Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Bug]: Cannot target java LocalDateTime via type mappings

Abierto
#12,650 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
java, openapi
Área
tooling

Línea de trabajo

Reproduce el problema con la especificación OpenAPI 3.1 proporcionada y los typeMappings e importMappings mostrados mediante el plugin de Maven. Empieza rastreando el manejo de palabras reservadas del generador de Java para los tipos asignados; se considera terminado cuando el código generado usa java.time.LocalDateTime en lugar de ModelLocalDateTime y compila.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Bug

Description

Using typeMappings I cannot specify a class with in-built support due to reserved word checking.

The OpenAPI specification defined "date-time" as a format value for strings, but that allows anything in ISO-8601. I want to declare in my spec whether it should be local date-time (no suffix), Zulu (Z suffix), or offer (+-nnnn suffix)

I am trying to do this with the following type mappings

typeMappings:
  string+date-time-local: LocalDateTime
  string+date: LocalDate
  string+time: LocalTime
  string+date-time-duration: Duration
  string+date-period: Period
  string+date-time-zoned: ZonedDateTime
  string+date-time-offset: OffsetDateTime
  string+timestamp: Instant

importMappings:
  LocalDateTime: 'java.time.LocalDateTime'
  LocalDate: 'java.time.LocalDate'
  LocalTime: 'java.time.LocalTime'
  ZonedDateTime: 'java.time.ZonedDateTime'
  OffsetDateTime: 'java.time.OffsetDateTime'
  Instant: 'java.time.Instant'
  Duration: 'java.time.Duration'
  Period: 'java.time.Period'

"LocalDate" is treated as a reserved word to avoid conflict between a spec declaring a model of that name and the java.time classes. I do not want to declare anything new but instead actually use the standard java.time classes.

When doing this, I receive this warning [WARNING] LocalDate (reserved word) cannot be used as model name. Renamed to ModelLocalDate, and it generates code using ModelLocalDate. I cannot see any obvious way of achieving what I need to do,.

Swagger Codegen Version

7.13.0 (via maven plugin)

Language / Generator

Java

OpenAPI/Swagger Spec

openapi: 3.1.0
info:
  title: Example
  version: 1.0.0
paths:
  /example:
    post:
      summary: example
      operationId: example
      parameters:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Example"
components:
  schemas:
    Example:
      type: object
      properties:
        localDate:
          type: string
          format: date-time-local

Steps to Reproduce

Attempt to generate the above OpenAPI specification using the type mappings above.

Expected Behaviour

Code is generated which utilised java.time.LocalDateTime

Actual Behavior

Code is generated using ModelLocalDateTime, which does not compile

Related

This would appear to be related to the changes in https://github.com/OpenAPITools/openapi-generator/pull/16276

Checklist

  • I have searched the existing issues to make sure this is not a duplicate.
  • I have included a minimal and reproducible spec example.
  • I have explained how to reproduce the issue.
  • I have specified which generator/language is affected.
Lenguaje dominante
Mustache
Estrellas
17.8k
Forks
6k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de swagger-api/swagger-codegen

Todos los issues de swagger-api/swagger-codegen

Issues similares

Más issues de DevTools

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.