OpenAPITools / OpenAPITools/openapi-generator
[BUG] Missing value/name mapping for shared enum definition
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
If a type is defined as a shared enum in the open api specification and the values are not upper case only, the generated code will not deserialize/serialize the enum value properly.
If the type is defined as an inline enum type, the generated code is correct and serialization/deserialization works.
openapi-generator version
5.3.0, jaxrs-resteasy
OpenAPI declaration file content or url
Example snippet from .yaml definition:
...
TermOfPaymentEnum:
type: string
enum:
- zero
- ten
- fifteen
...
Steps to reproduce
- Define a enum type with lower case values in components/schemas
- Generate the code with jaxrs-resteasy generator
The generated code is:
public enum TermOfPaymentEnum {
ZERO, TEN, FIFTEEN
}
Notice that the generated enum has no value attribute and no fromValue and toString() implementations.
I would expect the following code:
public enum TermOfPaymentEnum {
ZERO("zero"),
TEN("ten"),
FIFTEEN("fifteen"),
private String value;
TermOfPaymentEnum(final String value) {
this.value = value;
}
@Override
@JsonValue
public String toString() {
return String.valueOf(value);
}
}
Related issues/PRs
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
Start with the jaxrs-resteasy generator and compare generated code for the shared enum and inline enum cases described in the issue. Verify that lower-case OpenAPI values are preserved during serialization and deserialization, then add or run a regression test covering TermOfPaymentEnum-like values and confirm the generated enum includes the expected mapping behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100