OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] Unexpected behavior when using annotationlibrary swagger2
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I have model class with a date-time property which is defined as:
creationdate:
format: date-time
description: the creation date
type: string
example: '2022-10-07T01:00:00.000+02:00'
the maven config looks like:
<configuration>
<output>${project.build.directory}/generated-sources/</output>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<library>native</library>
<sourceFolder>/src/main/java</sourceFolder>
<serializableModel>true</serializableModel>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<allowUnicodeIdentifiers>true</allowUnicodeIdentifiers>
<useJakartaEe>true</useJakartaEe>
<supportUrlQuery>false</supportUrlQuery>
<annotationLibrary>swagger2</annotationLibrary>
<sortModelPropertiesByRequiredFlag>false</sortModelPropertiesByRequiredFlag>
<skipDefaultInterface>true</skipDefaultInterface>
</configOptions>
<modelPackage>com.github.saskiabikle.openapi.test.model</modelPackage>
<generateApis>false</generateApis>
<generateSupportingFiles>false</generateSupportingFiles>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<skipValidateSpec>false</skipValidateSpec>
</configuration>
the generated annotation looks like:
@Schema(example = "2022-10-07T01:00+02:00", requiredMode = Schema.RequiredMode.NOT_REQUIRED, description = "the creation date")
As you can see the seconds are missing.
If I check the definition of the default date-time (https://spec.openapis.org/registry/format/date-time) it refers to https://www.rfc-editor.org/rfc/rfc3339#section-5.6. There are seconds required.
openapi-generator version
I used 7.14.0 and the current master branch. The result is the same
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Blank API
version: 1.0.0
description: This is a simple API descriptor.
paths:
/:
get:
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/MyModel'
description: getAll
summary: getAll
components:
schemas:
MyModel:
title: Root Type for MyModel
description: My Testmodel
type: object
properties:
creationdate:
format: date-time
description: the creation date
type: string
example: '2022-10-07T01:00:00.000+02:00'
Steps to reproduce
If you use the example as mention the seconds are missing.
If you change the seconds from '00' to '01' the seconds the output is valid, because seconds are present.
Suggest a fix
I you can point me to code/unit test I would be able to create a PR.
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 by reproducing the generated annotation from the provided openapi.yaml and Maven configuration, then trace the Java generator's date-time example formatting and annotation generation. Done means examples with zero seconds retain the seconds required by the declared date-time format, with coverage for both the '00' and '01' cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100