OpenAPITools / OpenAPITools/openapi-generator
[Question] Superclass importmapping
Nobody has claimed this yet.
- 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 use importmapping for the superclasses of generated models. In this case the superclasses are the original classes the openapi schema was made from.
Describe the solution you'd like
Have a non-overriden method in the superclass( a getter with a fixed value rather than variable return). Currently readonly creates a constructor which the superclass does not support.
Avoid @Override annotations on all properties not on parent(s). Or avoid the setter returning object entirely.
Describe alternatives you've considered
I'v tried using the normalizer with the REF_AS_PARENT_IN_ALLOF to true.
Leaving the properties in the childclass workarounds the whole @Override setters, but would basically be shadowing superclass fields.
Additional context
The problem im trying to solve somehow:
We have a multilayer extends, like Pet -> Lizard -> Snake.
Our original Pet and Lizard classes are annotated with lombok.experimental.Superbuilder. So they dont have public Lizard setPetType(String petType) and other overriden property setters.
If i try to use importmapping for the parentclasses to use the shared originals, the compile breaks on the @Override (imported superclass not having self returning setters).
Also i havent found a way for a fixed field. Our Pet equivalent has an abstract get method which has a fixed value impl in our Cat and Lizard equivalent. Lets say
getPetType() {
return "Cat"
}
When i set readOnly in the spec it seems to assume constructor injection for the property. And it would require that constructor for the intermediate superclass.
Is there any normal way around this other than changing the template? I'd rather not have to maintain custom template changes.
I feel it's a shame you can't import the actual original class of the allOf this way, but there might be a valid reason.
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 by reproducing the multilayer Pet → Lizard → Snake case described in the issue, including importmapping and REF_AS_PARENT_IN_ALLOF. Review the generated Java model behavior around readonly properties, constructors, @Override setters, and imported Lombok SuperBuilder classes. Done means a supported approach exists without custom template changes, or the requested behavior is clearly scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- backend-api-design, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100