OpenAPITools / OpenAPITools/openapi-generator

[Java] Option to generate Enum values as public static final constants

Open
#6,828 1 comment 0 reactions 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

There are some cases, when you want to generate enums as simple constants, to get move flexibility on future releases.
Let assume response body contains list of next object:

Field {
  FieldType type;
  String value;
}

Your customer takes current version of client, parses that list, extracts interested fields into his/her system.
If you update server to return list with new object types, it will break de-serialization of that customer, even if he not interested in those new object types. That cause, that addition of new enum value breaks backward compatibility.

It definitely make sense, in cases where enums are big dictionaries(100+ values) and constantly updating to generate that as raw constants.

also, there is opposite case.
When you create custom package for customer with addition FieldType, but don't want to add it to client. All you want is just send them mail with "read with type value XXXX" message.

also#2, some android folks still recommends to use simple constants over enums.

Additional context

@see https://github.com/swagger-api/swagger-codegen/issues/6286

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

Review the related discussion in issue 6286, then inspect the current Java enum generation path and its configuration options. Done should mean a configurable mode emits enum values as public static final constants, while the existing enum behavior remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
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.