OpenAPITools / OpenAPITools/openapi-generator
[BUG] Spring generator: inheritance now always requires discriminator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
According to the latest OAS3.0 specification the following is a perfect fine example of inheritance:
Animal:
type: object
properties:
name:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- type: object
properties:
breed:
type: string
Till version 4.3.0 it works fine, the pojo is generated as:
public class Cat extends Animal{
String breed;
}
From version 5.0.0 I instead get:
public class Cat {
String name;
String breed;
}
In order to make this work in version 5.0.x I have to edit the specification like this:
Animal:
type: object
discriminator:
propertyName: className
properties:
name:
type: string
Is this intentional? I find it much more confusing now
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 Spring generator's handling of OpenAPI 3 inheritance and discriminator settings, using the specification examples in this issue as the reproduction. Compare generation behavior between versions 4.3.0 and 5.0.x; done means the discriminator-free Cat schema generates a class extending Animal without duplicating inherited properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100