OpenAPITools / OpenAPITools/openapi-generator
[REQ][JAVA] Configurable Option to Toggle @javax.annotation Annotations
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Our problem
When generating our OpenAPI specification using the SpringDoc generator, we encounter an issue. The generated DTOs in the code lack the @NotNull annotations by default. As a result, these properties are not appropriately marked as required within the OpenAPI specification. However, when converting this specification into models using the openapi-generator-maven-plugin in another application, the generated getters have the @javax.annotation.Nullable annotation, which mandates adding null checks throughout our codebase.
example of minumum specification.
{
"openapi": "3.0.1",
"info": {
"title": "my-app",
"version": "1.0"
},
"paths": {
},
"components": {
"schemas": {
"MyObject": {
"title": "MyObject",
"required": [],
"type": "object",
"properties": {
"key": {
"type": "string",
"format": "uuid"
},
"other": {
"$ref": "#/components/schemas/MyOtherObject"
}
}
},
"MyOtherObject": {
"title": "MyOtherObject",
"required": [],
"type": "object",
"properties": {
"aString": {
"type": "string"
},
"myDate": {
"type": "string",
"format": "date"
}
}
}
}
}
}
Now if I want myObject.getOther().getMyDate() we have to do a null check first on getOther because of the@javax.annotation.Nullable
Solution that we like
I propose adding a configurable setting within the OpenAPI Generator that would allow us to control the presence of @javax.annotation.Nonnull and @javax.annotation.Nullable annotations during code generation
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
No repository file or test is named in the report. Start by tracing the Java generator's handling of javax.annotation.Nonnull and javax.annotation.Nullable, then identify how generator settings are exposed. Done means a configurable option controls whether these annotations appear in generated Java code, with coverage for both enabled and disabled behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100