OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] [Spring] Redundant "import java.time.OffsetDateTime" when using typeMappings
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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