Add support for JSpecify annotations in SpringCodegen#23233
Add support for JSpecify annotations in SpringCodegen#23233felldo wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
- Introduced `useJSpecify` flag to enable the use of JSpecify's `@Nullable` annotations. - Modified POJO templates to correctly place JSpecify annotations for `TYPE_USE` compatibility. - Updated importMappings to handle hardcoded JSpecify annotations when enabled. - Added a test case for verifying correct annotation placement and behavior (`issue_23206.yaml` and corresponding Java test).
There was a problem hiding this comment.
1 issue found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/generators/spring.md">
<violation number="1" location="docs/generators/spring.md:105">
P2: `useJSpecify` is documented and generates JSpecify annotation usage, but Spring build templates do not appear to add the required `org.jspecify:jspecify` dependency, risking uncompilable generated projects.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| |useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false| | ||
| |useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true| | ||
| |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| | ||
| |useJSpecify|Use JSpecify's @Nullable (org.jspecify.annotations.Nullable) instead of Spring's @Nullable. Overrides any user-supplied importMapping for 'Nullable'.| |false| |
There was a problem hiding this comment.
P2: useJSpecify is documented and generates JSpecify annotation usage, but Spring build templates do not appear to add the required org.jspecify:jspecify dependency, risking uncompilable generated projects.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/generators/spring.md, line 105:
<comment>`useJSpecify` is documented and generates JSpecify annotation usage, but Spring build templates do not appear to add the required `org.jspecify:jspecify` dependency, risking uncompilable generated projects.</comment>
<file context>
@@ -102,6 +102,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
+|useJSpecify|Use JSpecify's @Nullable (org.jspecify.annotations.Nullable) instead of Spring's @Nullable. Overrides any user-supplied importMapping for 'Nullable'.| |false|
|useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
</file context>
modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
Outdated
Show resolved
Hide resolved
Co-authored-by: Christopher Molin <28791817+Chrimle@users.noreply.github.com>
Chrimle
left a comment
There was a problem hiding this comment.
Agree that the generated pom.xml will need a jspecify dependency... unless it's a transitive dependency already? 🤔
Spring Boot 4 should already include JSpecify because they just switched to it from their own Null annotations. But earlier versions shouldn't provide it. So I guess we still need to add it? |
|
Hmm... there is a configOption Edit: It's useSpringBoot4.
So these files:
|
- Integrated the `useJSpecify` flag to conditionally include the JSpecify dependency in multiple `pom.mustache` templates.
useJSpecifyflag to enable the use of JSpecify's@Nullableannotations.TYPE_USEcompatibility.issue_23206.yamland corresponding Java test).PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds an optional
useJSpecifyflag inSpringCodegento generate JSpecify@Nullableas a TYPE_USE annotation in POJOs and include theorg.jspecify:jspecifydependency when enabled. Fixes incorrect@Nullableplacement and enables JSpecify-compatible builds (fixes #23206).New Features
useJSpecify: when true, mapsNullabletoorg.jspecify.annotations.Nullable(overrides any userimportMapping).@Nullableon the type for fields, getters, and setters (e.g.,a.b.c.@Nullable TypeName).pojo.mustacheto insert type-use annotations viax-jspecify-annotated-type.org.jspecify:jspecify:1.0.0to Springpom.mustachetemplates (spring-boot,spring-cloud,spring-http-interface).Migration
--additional-properties useJSpecify=true.Written for commit a48a5ae. Summary will update on new commits.
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg