-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminated schema with shared ancestor shows invalid mapping options #2678
Comments
I assume this is the same issue, but will document it here anyway. Using {
"openapi": "3.0.1",
"info": {
"title": "My API",
"version": "v1"
},
"paths": {
"/animals": {
"post": {
"summary": "Create an animal",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateAnimalReqDto"
}
}
}
}
}
}
},
"components": {
"schemas": {
"CreateAnimalReqDto": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"animal": {
"$ref": "#/components/schemas/AnimalDto"
}
}
},
"AnimalDto": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
},
"discriminator": {
"propertyName": "type",
"mapping": {
"cat": "#/components/schemas/CatDto",
"dog": "#/components/schemas/DogDto",
"lizard": "#/components/schemas/LizardDto"
}
}
},
"MammalDto": {
"allOf": [
{
"$ref": "#/components/schemas/AnimalDto"
},
{
"type": "object"
}
]
},
"ReptileDto": {
"allOf": [
{
"$ref": "#/components/schemas/AnimalDto"
},
{
"type": "object"
}
]
},
"CatDto": {
"allOf": [
{
"$ref": "#/components/schemas/MammalDto"
},
{
"type": "object"
}
]
},
"DogDto": {
"allOf": [
{
"$ref": "#/components/schemas/MammalDto"
},
{
"type": "object"
}
]
},
"LizardDto": {
"allOf": [
{
"$ref": "#/components/schemas/ReptileDto"
},
{
"type": "object"
}
]
}
}
}
} Produces the following UI: |
Perhaps this is my misunderstanding of how to structure a polymorphic schema:
Using this example, I removed the inclusion of // ... snip ...
"AnimalDto": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
},
"discriminator": {
"propertyName": "type",
"mapping": {
"cat": "#/components/schemas/CatDto",
"dog": "#/components/schemas/DogDto",
"lizard": "#/components/schemas/LizardDto"
}
}
},
"MammalDto": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"ReptileDto": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
// ... snip ... This produced the correct result: Albeit at the expense of redefining common properties in each mapped schema. |
Describe the bug
If a discriminated schema shares a common ancestor (schema) with another discriminated schema, extra schemas are shown in the UI (namely the two discriminated schemas).
Expected behavior
I would expect only the types listed in the mapping section to be shown.
Minimal reproducible OpenAPI snippet(if possible)
Screenshots
(highlighted discriminator values are invalid)
Additional context
N/A
The text was updated successfully, but these errors were encountered: