OpenAPITools / OpenAPITools/openapi-generator
[BUG] discriminator property of supertype not marked as so in subtype
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?
Description
When I specify a type Pet containing a discriminator type and specify a subtype Dog using allOf, then the generated model value for Pet.type.isDiscriminator == true while Dog.type.isDiscriminator == false . I would expect Dog.type.isDiscriminator == true.
This behavior is unexpected to me, but I'm not 100% sure if it's intended or not. Can someone confirm? In case this is a bug I can invest some time to try to solve it.
openapi-generator version
5.3.0
OpenAPI declaration file content or url
Pet:
type: object
discriminator:
propertyName: type
required: [name, type]
properties:
name:
type: string
type:
type: string
Dog:
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
required: [name, type, age]
properties:
age:
type: string
Generation Details
Using the folowing data_class.mustache template:
{{#allVars}}//{{&baseName}} isDiscriminator == {{isDiscriminator}}}
{{/allVars}}
You will be able to see in the generated models that for Pet, type.isDiscriminator == true, while for Dog the same is false.
Steps to reproduce
$ openapi-generator-cli generate -g kotlin -i openapi.yaml -o gen -t templates
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 OpenAPI declaration and the data_class.mustache template, then run the documented Kotlin generation command to reproduce the Pet and Dog output. Trace how the generated model metadata represents the inherited discriminator. Done means Dog.type is marked isDiscriminator == true, with the behavior covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin, openapi
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100