OpenAPITools / OpenAPITools/openapi-generator
[BUG] Incorrect java model classes generated for multi level hierarchy using discriminator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The models with JsonSubTypes annotations are not generated as expected.
Expected classes
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "object_type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = TessellSubObjDTO.class, name = "sub-obj"),
})
public class TessellBaseObjDTO {...}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "sub_obj_type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = TessellDailySubObjDTO.class, name = "daily")
})
public class TessellSubObjDTO extends TessellBaseObjDTO {...}
public class TessellDailySubObjDTO extends TessellSubObjDTO {...}
Actual
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "object_type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = TessellDailySubObjDTO.class, name = "DailySubObj"),
@JsonSubTypes.Type(value = TessellSubObjDTO.class, name = "SubObj"),
@JsonSubTypes.Type(value = TessellDailySubObjDTO.class, name = "daily"),
@JsonSubTypes.Type(value = TessellSubObjDTO.class, name = "sub-obj"),
})
public class TessellBaseObjDTO {...}
public class TessellSubObjDTO extends TessellBaseObjDTO {...}
public class TessellDailySubObjDTO extends TessellSubObjDTO {...}
openapi-generator version
5.2.1
OpenAPI declaration file content or url
Generation Details
Specific Config options:
- java8: true
- delegatePattern: true
- additionalModelTypeAnnotations: @lombok.experimental.SuperBuilder;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor
Steps to reproduce
Using openapi-generator-maven-plugin (version : 5.2.1) to generate the code.
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 linked OpenAPI declaration and reproduce generation through the openapi-generator-maven-plugin using version 5.2.1 and the listed Java options. Inspect how the generator builds JsonSubTypes annotations for the multi-level discriminator hierarchy. Done means the generated classes match the expected separate discriminator annotations and subtype names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100