swagger-api / swagger-api/swagger-codegen-generators
modelNamePrefix Doesn't Work With 'oneof' Inheritance in Java
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
When there is a oneOf relationship in the openapi specification, say:
Pet:
oneOf:
- $ref: '#/components/schemas/Cat
- $ref: '#/components/schemas/Dog'
And a modelNamePrefix is specified (say Model), the Cat and Dog model classes will have the following class signatures
public class ModelCat implements Pet
...
public class ModelDog implements Pet
This causes a compilation error without any ancillary code because the Pet model class is generated as ModelPet.
I believe the fix is pretty simple and the source of the issue is the population of the interfaceModels list for the CodegenModel in the DefaultCodegenConfig.postProcessAllModels method
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 in DefaultCodegenConfig.postProcessAllModels and inspect how the interfaceModels list is populated for oneOf inheritance when modelNamePrefix is set. Trace the generated references for ModelPet, ModelCat, and ModelDog, then verify that the generated Java classes compile without the interface-name mismatch.
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
- Mostly clear
- Newbie friendliness
- 40/100