OpenAPITools / OpenAPITools/openapi-generator
[BUG] 6.2.1 regression - JavaSpring `@NotNull` code annotation with no import
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [Yes] Have you provided a full/minimal spec to reproduce the issue?
- [No] Have you validated the input using an OpenAPI validator (example)?
- [No] Have you tested with the latest master to confirm the issue still exists?
- [Yes] Have you searched for related issues/PRs?
- [Yes] What's the actual output vs expected output?
Description
JavaSpring generator creates java files with @NotNull but there's no import for that symbol, resulting in javac error cannot find symbol.
openapi-generator version
6.2.1
This is a regression, was working on 6.2.0.
OpenAPI declaration file content or url
AuthzRequestStatus:
type: string
enum: ['APPROVED', 'REQUESTED', 'REJECTED']
Generation Details
Project uses the Gradle plugin to generate, full configuration is here:
https://github.com/au-research/raido-v2/blob/895de24f6dc9ec3a360ba04acf0f3ee1355b6d59/api-svc/idl-raid-v2/build.gradle#L136
I think the relevant configuration item might be: openApiNullable: "false" and useBeanValidation: "false"?
Generates code like:

Steps to reproduce
- run the standard Gradle
openApiGeneratetask - then compile the generated code
javacfails with errorcannot find symbol
Suggest a fix
If openApiNullable and useBeanValidation set to false - 6.2.1 should not generate the @NotNull annotation. 6.2.0 does not generate the annotation.
Workaround
Customise pojo.mustache template to effective revert the effect of commit 0060dfd1.
https://github.com/au-research/raido-v2/blob/main/api-svc/idl-raid-v2/src/main/resources/template/pojo.mustache#L3
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 the JavaSpring generator's pojo.mustache template and the behavior introduced by commit 0060dfd1. Run the standard Gradle openApiGenerate task with openApiNullable and useBeanValidation disabled, then compile the generated Java; done means the generated code has no unresolved @NotNull annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100