Skip to content

feat: generate @Deprecated annotations for spec-level deprecation (Java/Spring/Docs) - #1283

Open
jjjasper wants to merge 4 commits into
mainfrom
feat/java-generate-deprecation-annotation-2
Open

feat: generate @Deprecated annotations for spec-level deprecation (Java/Spring/Docs)#1283
jjjasper wants to merge 4 commits into
mainfrom
feat/java-generate-deprecation-annotation-2

Conversation

@jjjasper

@jjjasper jjjasper commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Generate @Deprecated annotations (and a deprecation message) across the Java, Spring, and docs generators when an OpenAPI spec is marked deprecated via info.x-deprecated (optionally with info.x-sunset-date).

  • DeprecationExtensions (boat-scaffold/.../codegen/utils): reads x-deprecated/x-sunset-date off Info and builds a human-readable deprecation message (e.g. "This API is deprecated and will be removed on 2026-12-31.").
  • BoatJavaCodeGen / BoatSpringCodeGen: when the spec is marked deprecated, propagate isDeprecated/deprecated and the message (via a x-boat-deprecation-message vendor extension) onto every generated operation, model, and model property.
  • BoatDocsGenerator: same propagation for the generated HTML docs, surfaced in boat-docs/index.mustache and param.mustache.
  • Mustache templates updated so the deprecation message shows up in Javadoc @deprecated tags and @Schema/@ApiModel annotations, for both boat-java (root templates and the okhttp-gson library templates, which is the default library and has its own copies) and boat-spring.
  • Tests: unit tests for DeprecationExtensions, and end-to-end codegen tests (BoatCommonJavaCodeGenTests, BoatSpringCodeGenTests) against a new deprecated-spec.yaml fixture.

Fix included in this PR

While validating the feature, found postProcessAllModels in BoatJavaCodeGen/BoatSpringCodeGen never actually ran: it checked instanceof CodegenModel against the wrong map nesting level (openapi-generator 7.20.0 nests as Map<String, ModelsMap>List<ModelMap>CodegenModel), and as originally written was a compile error (generic-erasure name clash), meaning this branch had never been built or test-run. Also found BoatJavaCodeGen's default okhttp-gson library templates (which take precedence over the root boat-java templates that were edited) never got the message rendering, and one Javadoc-parsing test that was fragile to a pre-existing blank-line quirk in generated code. All fixed and covered by the passing test suite below.

Test plan

  • mvn -pl boat-scaffold -am test (JDK 17) — full boat-scaffold module test suite passes, including BoatCommonJavaCodeGenTests#shouldGenerateDeprecationAnnotationsFromSpecLevel, BoatSpringCodeGenTests#shouldGenerateDeprecationAnnotationsFromSpecLevel, and DeprecationExtensionsTests

🤖 Generated with Claude Code

jjjasper and others added 4 commits September 4, 2026 09:59
Wire x-deprecated and x-sunset-date vendor extensions from OpenAPI info block
into generated Java/Spring code, marking the entire API as deprecated with a
sunset date message in Javadoc when present.

- New DeprecationExtensions utility mirrors B015 lint rule parsing
- BoatJavaCodeGen and BoatSpringCodeGen propagate spec-level deprecation
  through preprocessOpenAPI, fromOperation, postProcessModelProperty, and
  postProcessAllModels hooks
- Message text appended to @deprecated Javadoc tags and @Schema descriptions
- Unit tests for DeprecationExtensions boolean/date parsing and message building
- Mustache templates updated to render deprecation message when x-boat-deprecation-message
  is present in vendorExtensions

Co-Authored-By: Claude <noreply@anthropic.com>
Add BoatSpringCodeGenTests.shouldGenerateDeprecationAnnotationsFromSpecLevel()
and BoatCommonJavaCodeGenTests.shouldGenerateDeprecationAnnotationsFromSpecLevel()
to verify @deprecated annotations and sunset-date messages are generated when
x-deprecated and x-sunset-date are present in the OpenAPI info block.

Add deprecated-spec.yaml test fixture with:
- Info-level x-deprecated and x-sunset-date
- Operation-level deprecated: true
- Property-level deprecated: true

Co-Authored-By: Claude <noreply@anthropic.com>
Add preprocessOpenAPI override to BoatDocsGenerator to compute spec-level
deprecation and sunset-date message, then propagate to fromOperation hook
similar to codegen classes.

Update boat-docs templates to render deprecation message:
- index.mustache: show message in the deprecated badge for operations
- param.mustache: show message in the deprecated badge for parameters

Co-Authored-By: Claude <noreply@anthropic.com>
…son templates

postProcessAllModels previously checked `instanceof CodegenModel` against
the top-level Map<String, Object>, whose entries are actually ModelsMap ->
List<ModelMap> -> CodegenModel on openapi-generator 7.20.0. As written it
was also a compile error (name clash on erasure with the real generic
override), so this code path never ran and was never exercised by CI.

Also fixes boat-java's default okhttp-gson library, which has its own
api.mustache/pojo.mustache overriding the ones under boat-java/ that were
edited for this feature, so the deprecation message never rendered for the
default boat-java output.

Co-Authored-By: Claude <noreply@anthropic.com>
@jjjasper jjjasper changed the title fix: correct spec-wide deprecation propagation to models and okhttp-gson templates feat: add @deprecated annotation generation for spec-level deprecation Sep 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
7.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@jjjasper jjjasper changed the title feat: add @deprecated annotation generation for spec-level deprecation feat: generate @Deprecated annotations for spec-level deprecation (Java/Spring/Docs) Sep 4, 2026
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.

1 participant