Skip to content

fix(java-spring): add @Deprecated annotation to fluent setters for deprecated properties - #24762

Open
ANUSH2510 wants to merge 1 commit into
OpenAPITools:masterfrom
ANUSH2510:master
Open

fix(java-spring): add @Deprecated annotation to fluent setters for deprecated properties#24762
ANUSH2510 wants to merge 1 commit into
OpenAPITools:masterfrom
ANUSH2510:master

Conversation

@ANUSH2510

@ANUSH2510 ANUSH2510 commented Aug 24, 2026

Copy link
Copy Markdown

Description

Fixes #24704

The @Deprecated annotation was correctly generated on getters and standard setters for properties marked deprecated: true, but was missing on the corresponding fluent setter methods — for both a class's own properties and properties inherited from a parent schema (including the array/map item-adder variants: addXxxItem, putXxxItem).

Changes

  • Updated pojo.mustache to wrap all fluent setter variants (single, array-item, map-item; both own and inherited) with the same {{#deprecated}}@Deprecated{{/deprecated}} block already used for the standard setter.
  • Added a regression test shouldGenerateDeprecatedAnnotationOnFluentSetter in SpringCodegenTest.
  • Regenerated the affected sample (spring-cloud-deprecated) to reflect the fix.

Testing

  • New test passes.
  • Full SpringCodegenTest suite passes (328/328).
  • Verified manually against a custom spec with allOf inheritance + deprecated: true.

Summary by cubic

Annotates all fluent setters for deprecated properties with @deprecated in the Java Spring generator, matching the existing getters and standard setters. Previously, fluent setters (including inherited and array/map item adders) lacked the annotation; now compilers/IDEs will warn when they are used.

  • Updated JavaSpring/pojo.mustache to apply @deprecated to fluent setters for own and inherited properties, including addXxxItem and putXxxItem, when the property has deprecated: true.
  • Added regression test shouldGenerateDeprecatedAnnotationOnFluentSetter and regenerated the spring-cloud-deprecated sample.
  • Impact: Generated models may now emit deprecation warnings when calling fluent setters for deprecated fields. No runtime changes or configuration updates required.

Written for commit 12e4ce1. Summary will update on new commits.

Review in cubic

…precated properties

Fixes OpenAPITools#24704 - fluent setter methods (both for own properties and
inherited properties, including array/map item adders) were missing
the @deprecated annotation that the getter and standard setter
already carried for properties marked deprecated: true.
@wing328

wing328 commented Aug 24, 2026

Copy link
Copy Markdown
Member

thanks for the PR

is this the same as #24705 ?

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 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="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java:5852">
P2: This regression test only covers the single fluent setter of the own enum property `status`. The fix claims to cover inherited-property fluent setters and the `addXxxItem`/`putXxxItem` variants, none of which this test exercises (Pet is not a child schema and `status` is not a container). Extend the test to cover those variants so a regression in the rest of the fix is detected.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

new DefaultGenerator().opts(configurator.toClientOptInput()).generate();

JavaFileAssert.assertThat(tempDir.resolve("src/main/java/org/openapitools/model/Pet.java"))
.assertMethod("status", "StatusEnum").hasAnnotation("Deprecated");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This regression test only covers the single fluent setter of the own enum property status. The fix claims to cover inherited-property fluent setters and the addXxxItem/putXxxItem variants, none of which this test exercises (Pet is not a child schema and status is not a container). Extend the test to cover those variants so a regression in the rest of the fix is detected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 5852:

<comment>This regression test only covers the single fluent setter of the own enum property `status`. The fix claims to cover inherited-property fluent setters and the `addXxxItem`/`putXxxItem` variants, none of which this test exercises (Pet is not a child schema and `status` is not a container). Extend the test to cover those variants so a regression in the rest of the fix is detected.</comment>

<file context>
@@ -5833,6 +5833,24 @@ public void shouldGenerateSingleDeprecatedAnnotation() {
+        new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
+
+        JavaFileAssert.assertThat(tempDir.resolve("src/main/java/org/openapitools/model/Pet.java"))
+                .assertMethod("status", "StatusEnum").hasAnnotation("Deprecated");
+    }
 
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][JAVA][SPRING] Fluent model setters for deprecated properties are not annotated with @Deprecated

2 participants