OpenAPITools / OpenAPITools/openapi-generator
[Java] Option to generate Enum values as public static final constants
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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