OpenAPITools / OpenAPITools/openapi-generator

[REQ][Java][Spring] Add "@Deprecated" annotation to enum value in java code if enum value is deprecated in contract

Open
#19,615 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

I would like to propose an improvement for the generated java sources based on the API contract.

I think it would be very interesting to give the possibility to add the @Deprecated annotation to an enum value.

Describe the solution you'd like

For this, you could add a new extension, e.g. x-deprecated and add the value to deprecated.

    SaleBasePeriodType:
      type: string
      enum:
        - ACCUMULATED_CAMPAIGN
        - YESTERDAY
        - FISCAL_YEAR
        - LAST_FISCAL_YEAR
      x-deprecated: # new custom extension
        - ACCUMULATED_CAMPAIGN

Desired code:

public enum SaleBasePeriodTypeDTO {

  @Deprecated // <- annotation added
  ACCUMULATED_CAMPAIGN("ACCUMULATED_CAMPAIGN"),

  YESTERDAY("YESTERDAY"),

  FISCAL_YEAR("FISCAL_YEAR"),

  LAST_FISCAL_YEAR("LAST_FISCAL_YEAR");

  private String value;

  SaleBasePeriodTypeDTO(String value) {
    this.value = value;
  }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Java/Spring enum-generation entry point and how API contract extensions are read for enum values. Confirm the generated enum output for the proposed x-deprecated values, then identify or add the relevant generator tests; done means deprecated contract values receive @Deprecated while other values remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.