Skip to content

[Java][Spring] Annotate deprecated fluent model setters with @Deprecated - #24705

Open
kalayciburak wants to merge 1 commit into
OpenAPITools:masterfrom
kalayciburak:fix/24704-spring-deprecated-fluent-setters
Open

[Java][Spring] Annotate deprecated fluent model setters with @Deprecated#24705
kalayciburak wants to merge 1 commit into
OpenAPITools:masterfrom
kalayciburak:fix/24704-spring-deprecated-fluent-setters

Conversation

@kalayciburak

@kalayciburak kalayciburak commented Aug 14, 2026

Copy link
Copy Markdown

The Java Spring generator already annotates fields, getters, regular setters, and nested builder methods for properties marked deprecated: true. Fluent model setters and collection helpers (addXItem / putXItem) were missing @Deprecated.

This updates JavaSpring/pojo.mustache so those methods emit @Deprecated as well, including inherited fluent helpers.

Fixes #24704

PR checklist

  • Read the contribution guidelines.
  • Ran the following to build the project and update samples:
    ./mvnw -pl modules/openapi-generator-cli -am package -DskipTests=true -Dmaven.javadoc.skip=true -Djacoco.skip=true
    ./bin/generate-samples.sh ./bin/configs/spring*.yaml
    
    Regenerated Spring samples only. The sample delta is @Deprecated on fluent setters and collection helpers for already-deprecated properties (for example Pet.status).
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Java Spring @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08) @KannaKim (2026/07)

Tests

Executed:

  • ./mvnw -pl modules/openapi-generator -am test -Dtest=SpringCodegenTest#contractWithDeprecatedPropertiesAnnotatesFluentSettersAndCollectionHelpers RED then GREEN
  • ./mvnw -pl modules/openapi-generator -am test -Dtest=SpringCodegenTest#contractWithDeprecatedEnumGeneratesDeprecatedAnnotation,SpringCodegenTest#contractWithDeprecatedPropertiesAnnotatesFluentSettersAndCollectionHelpers,SpringCodegenTest#shouldGenerateSingleDeprecatedAnnotation 3/3 GREEN

Summary by cubic

Annotates generated Java Spring model fluent setters and collection helpers for deprecated properties with @deprecated to align with existing annotations on fields/getters/setters/builder methods. Previously, these fluent methods were not annotated; now they are, including inherited helpers, to surface consistent deprecation warnings.

  • Template change: modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache now emits @Deprecated on fluent setters (prop(value)), addXItem(...), putXItem(...), and their inherited equivalents when the schema property has deprecated: true.
  • Tests and samples: Adds a contract and a test asserting the annotations; regenerates Spring samples to reflect the new annotations.
  • Impact: No runtime or source behavior change. Calls to these fluent methods may now produce deprecation warnings. No migration required; prefer non-deprecated properties or suppress warnings as needed.

Written for commit bf615f6. Summary will update on new commits.

Review in cubic



Fluent setters and collection helpers generated from deprecated schema
properties now emit @deprecated, matching getters, setters, and nested
builder methods.

Fixes OpenAPITools#24704

@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 50 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/main/resources/JavaSpring/pojo.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache:158">
P3: The fluent setters and collection helpers get the `@Deprecated` annotation but, unlike the getter and regular setter for the same deprecated property, they emit no `/** @deprecated */` Javadoc block. Add a matching Javadoc deprecation tag for consistency so `@deprecated` HTML docs stay uniform across generated code.</violation>
</file>

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

Re-trigger cubic


{{! begin feature: fluent setter methods }}
{{#deprecated}}
@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.

P3: The fluent setters and collection helpers get the @Deprecated annotation but, unlike the getter and regular setter for the same deprecated property, they emit no /** @deprecated */ Javadoc block. Add a matching Javadoc deprecation tag for consistency so @deprecated HTML docs stay uniform across generated code.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache, line 158:

<comment>The fluent setters and collection helpers get the `@Deprecated` annotation but, unlike the getter and regular setter for the same deprecated property, they emit no `/** @deprecated */` Javadoc block. Add a matching Javadoc deprecation tag for consistency so `@deprecated` HTML docs stay uniform across generated code.</comment>

<file context>
@@ -154,6 +154,9 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
 
   {{! begin feature: fluent setter methods }}
+  {{#deprecated}}
+  @Deprecated
+  {{/deprecated}}
   public {{classname}} {{name}}({{#useJspecify}}{{#lambda.jSpecifyNullable}}{{^required}}{{^useOptional}}@Nullable {{/useOptional}}{{#useOptional}}{{#optionalAcceptNullable}}@Nullable {{/optionalAcceptNullable}}{{/useOptional}}{{/required}}{{/lambda.jSpecifyNullable}}{{#lambda.jSpecifyDatatype}}{{{datatypeWithEnum}}}{{/lambda.jSpecifyDatatype}}{{/useJspecify}}{{^useJspecify}}{{>nullableAnnotation_default}}{{{datatypeWithEnum}}}{{/useJspecify}} {{name}}) {
</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

1 participant