OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] [Spring] Redundant "import java.time.OffsetDateTime" when using typeMappings

Open
#14,164 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Specifying typeMapping for "string+date-time" doesn't remove the import of OffsetDateTime.

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <executions>
        <execution>
            <configuration>
                <typeMappings>
                    <typeMapping>string+date-time=LocalDateTime</typeMapping>
                </typeMappings>
                <importMappings>
                    <importMapping>LocalDateTime=java.time.LocalDateTime</importMapping>
                </importMappings>
            </configuration>
        </execution>
    </executions>
    <-- Other configs -->
</plugin>
openapi-generator version

openapi-generator-maven-plugin version 6.0.1

OpenAPI declaration file content or url
components:
  schemas:
    Foo:
      type: object
      properties:
        createdAt:
          type: string
          format: date-time
Steps to reproduce

Use the Open API with the typeMapping and importMapping above

Suggest a fix

Remove the fixed OffsetDateTime import at https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaSpring/model.mustache#L13

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/JavaSpring/model.mustache, especially the fixed import mentioned in the issue. Reproduce generation with the shown typeMapping and importMapping, then verify the generated Spring model no longer includes the redundant OffsetDateTime import while retaining the LocalDateTime mapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend, tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.