Skip to content

Conversation

@Chrimle
Copy link
Contributor

@Chrimle Chrimle commented Nov 9, 2025

Adds support for generated enum-classes to be annotated @Deprecated when deprecated: true is set in the OpenAPI-schema, similarly to how it is done when generating classes. Note: this annotation is not applied to inner enum-classes.

Fixes #22311.

OpenAPI Schema:

DeprecatedExampleEnum:
  type: string
  deprecated: true
  enum:
    - ENUM1
    - ENUM2
    - ENUM3

Results in:

/**
 * Gets or Sets DeprecatedExampleEnum
 */
@Deprecated
public enum DeprecatedExampleEnum {
  
  ENUM1("ENUM1"),
  
  ENUM2("ENUM2"),
  
  ENUM3("ENUM3");
  
  // ... unchanged ...
}

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@Chrimle Chrimle changed the title [Java] Annotate Deprecated enum-classes with @Deprecated [Java] Support Deprecation of Generated enum-classes Nov 9, 2025
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
*/
{{#gson}}
{{#isDeprecated}}@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

suggestion:

{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}

Copy link
Contributor Author

@Chrimle Chrimle Nov 10, 2025

Choose a reason for hiding this comment

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

This will result in an empty line, like:

/*
 * javadoc here...
 */
 
 @Deprecated

Also, making a newline between {{/isDeprecated}} and {{#gson}} will always generate another empty line after the deprecated-annotation, or result to 2 empty lines after the javadocs.

Is this OK? (from a Style-Guide perspective)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @wing328, the suggested change has been done, and the updated samples have been committed too. 👍

@Chrimle
Copy link
Contributor Author

Chrimle commented Nov 10, 2025

Hello @wing328 !
I have ran /.mvnw clean install and then ./bin/generate-samples.sh ./bin/configs/java*. The updated sample files have been committed to show the diffs.

Personally, with reference to the google-java-format, the new line added to these classes is not conforming to the format.

Is this OK, or should I address this at the same time as your suggestion?

Cheers

@Chrimle
Copy link
Contributor Author

Chrimle commented Nov 11, 2025

Will update the other Java templates too.

@Chrimle
Copy link
Contributor Author

Chrimle commented Nov 11, 2025

No other files have been updated. Ready for review!

@Chrimle Chrimle marked this pull request as ready for review November 11, 2025 19:05
@Chrimle
Copy link
Contributor Author

Chrimle commented Nov 11, 2025

Pinging the Java Tech Committee 🔔
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg

Hopefully this is how it is intended 🙏

@wing328
Copy link
Member

wing328 commented Nov 12, 2025

looks good to me. let's give it a try

i'll add a test in another PR

done via #22335

@wing328 wing328 merged commit ec8ca20 into OpenAPITools:master Nov 12, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][JAVA] Generated Enum Classes are not Annotated @Deprecated

2 participants