Closed ghost closed 4 years ago
Discriminators aren't currently being added to the parent class properties section of the schema.
properties
This code:
@dataclass class Pet(JsonSchemaMixin, discriminator=True) name: str @dataclass class Cat(Pet): hunting_skill: Literal["clueless", "lazy", "adventurous", "aggressive"] = "lazy"
Generates this schema:
"Pet": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "name": { "type": "string" } }, "required": [ "name", "petType" ] }, "Cat": { "allOf": [ { "$ref": "#/components/schemas/Pet" }, { "type": "object", "properties": { "hunting_skill": { "type": "string", "default": "lazy", "enum": [ "clueless", "lazy", "adventurous", "aggressive" ] } }, "required": [ "huntingSkill" ] } ] }
The correct schema would be:
"Pet": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "name": { "type": "string" }, "petType": { "type": "string" } }, "required": [ "name", "petType" ] }, "Cat": { "allOf": [ { "$ref": "#/components/schemas/Pet" }, { "type": "object", "properties": { "hunting_skill": { "type": "string", "default": "lazy", "enum": [ "clueless", "lazy", "adventurous", "aggressive" ] } }, "required": [ "huntingSkill" ] } ] }
Discriminators aren't currently being added to the parent class
properties
section of the schema.This code:
Generates this schema:
The correct schema would be: