Skip to content

fix(jaxrs-spec): generate @Deprecated annotations (fixes #18941)#23651

Open
anna-megalou wants to merge 2 commits intoOpenAPITools:masterfrom
anna-megalou:fix/jaxrs-spec-deprecated-annotation
Open

fix(jaxrs-spec): generate @Deprecated annotations (fixes #18941)#23651
anna-megalou wants to merge 2 commits intoOpenAPITools:masterfrom
anna-megalou:fix/jaxrs-spec-deprecated-annotation

Conversation

@anna-megalou
Copy link
Copy Markdown
Contributor

@anna-megalou anna-megalou commented Apr 28, 2026

Summary

Adds support for OpenAPI deprecated: true in the jaxrs-spec Java generator.

This PR adds generated Java deprecation annotations where applicable, including:

  • @Deprecated
  • /** @deprecated */
  • deprecated = true in API documentation annotations

It also adds a test for deprecated operations and parameters.

Why

Fixes #18941.

The generated Java code should reflect deprecated operations and parameters from the OpenAPI specification.

How to test

./mvnw -pl modules/openapi-generator test -Dtest=JavaJAXRSSpecServerCodegenTest

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Generate `@Deprecated` and `deprecated = true` in `jaxrs-spec` when the spec marks operations, parameters, models, or fields as deprecated. Aligns generated Java/Javadoc with the spec and adds tests.

- **Bug Fixes**
  - Add `@Deprecated` and Javadoc `@deprecated` to operations, interface methods, and all parameter types (body, cookie, header, path, query, form), including Quarkus templates.
  - Set `deprecated = true` in Swagger v3 `@Operation` and MicroProfile `@Operation`/`@Schema` (not in Swagger v2 `@ApiOperation`).
  - Mark enums, model classes, fields, getters/setters, collection helpers, and builder methods as deprecated.
  - Add tests verifying deprecations in `Pet` and `PetApi` generation.

<sup>Written for commit 008adfecbb5fbe60613c812692eaa1a79bf90c46. Summary will update on new commits. <a href="https://cubic.dev/pr/OpenAPITools/openapi-generator/pull/23651?utm_source=github">Review in cubic</a></sup>

<!-- End of auto-generated description by cubic. -->

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 13 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/JavaJaxRS/spec/apiMethod.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/JavaJaxRS/spec/apiMethod.mustache:8">
P1: `@ApiOperation` in Swagger 1.x does not support a `deprecated` attribute, so this newly generated argument can cause compile errors with supported/sample swagger-annotations versions.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread modules/openapi-generator/src/main/resources/JavaJaxRS/spec/apiMethod.mustache Outdated
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 5 files (changes from recent commits).

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/jaxrs/JavaJAXRSSpecServerCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java:1341">
P2: The test no longer verifies the generated API annotation still includes `deprecated = true`, so a regression in the actual `@Operation` output would pass unnoticed.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


Path petApi = output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java");
JavaFileAssert.assertThat(petApi).assertMethod("findPetsByTags", "List<String>").hasAnnotation("Deprecated");
JavaFileAssert.assertThat(petApi).fileContains("* @deprecated", "findPetsByTags");
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: The test no longer verifies the generated API annotation still includes deprecated = true, so a regression in the actual @Operation output would pass unnoticed.

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/jaxrs/JavaJAXRSSpecServerCodegenTest.java, line 1341:

<comment>The test no longer verifies the generated API annotation still includes `deprecated = true`, so a regression in the actual `@Operation` output would pass unnoticed.</comment>

<file context>
@@ -1338,7 +1338,7 @@ public void generatesDeprecatedAnnotationsForModelsOperationsAndParameters_issue
         Path petApi = output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java");
         JavaFileAssert.assertThat(petApi).assertMethod("findPetsByTags", "List<String>").hasAnnotation("Deprecated");
-        JavaFileAssert.assertThat(petApi).fileContains("@ApiOperation", "deprecated = true", "findPetsByTags");
+        JavaFileAssert.assertThat(petApi).fileContains("* @deprecated", "findPetsByTags");
         JavaFileAssert.assertThat(petApi).fileContains("findPetsByStatus", "@Deprecated", "@QueryParam(\"status\")");
     }
</file context>
Suggested change
JavaFileAssert.assertThat(petApi).fileContains("* @deprecated", "findPetsByTags");
JavaFileAssert.assertThat(petApi).fileContains("@Operation", "deprecated = true", "findPetsByTags");

@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 29, 2026

thanks for the pr

please follow step 3 to update the samples

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] [jaxrs-spec] Not generating @Deprecated annotations

2 participants