Description
If a schema uses a discriminator, clients read that property to select a subtype. Include the property in required so it is present in each object.
Potential impact
Without that value, clients and servers may choose different subtypes or reject the data.
Remediation
Add the field named by discriminator.propertyName (3.0) or discriminator (2.0) to required. Preserve other required fields, including inherited ones, and check actual requests and responses for the discriminator value.
Examples
These OpenAPI 3.0 excerpts omit info, paths, subtypes, and their composition.
Before
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"discriminator": {
"propertyName": "petType"
},
"properties": {
"petType": {
"type": "string"
}
},
"required": [
"name"
]
}
}
}
}
After
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"discriminator": {
"propertyName": "petType"
},
"properties": {
"petType": {
"type": "string"
}
},
"required": [
"petType"
]
}
}
}
}
The revised required list replaces name with petType. Include both if name is still mandatory.