Description
Describe the bug
Using Polymorphism and additional some kind of union (union or Alias) with all or a subset of these models leads to a missing discriminator mapping. The first Element is always missing in the discriminator of the parent Class.
In Detail:
If you need a some kind of union, which is only a subset of models, which are inherited from a base model and use this subset at least once somewhere else (e.g. another Model or as Response) the union itself is correctly created. But the Parent Model of the models looses the first model which is referenced in an alias or an union.
The linked playground show the example from the docs with an additional alias (MyPet). If MyPet is used somewhere Pet looses the first Element from the MyPet Alias (Cat). This leads to the following discriminator mapping (without Cat):
Pet:
type: object
required:
- kind
- name
properties:
kind:
$ref: '#/components/schemas/PetKind'
name:
type: string
weight:
type: number
format: float
discriminator:
propertyName: kind
mapping:
dog: '#/components/schemas/Dog'
If MyPet would be defined reversed ( Dog | Cat ) only Cat would be rendered in mapping.
The same problem occurs if using union instead:
union MyPet {
cat: Cat,
dog: Dog,
}
Reproduction
Can be reproduced in Playground:
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.