Discriminator with allOf return not allowed error validation parent properties
Issue #396
new
We are using discriminator to be able to set different different type of object in a property, we are using the following specification
{
"components": {
"schemas": {
"Party": {
"properties": {
"name": {
"type": "string"
},
"contactMediums": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ContactMedium"
}
}
}
},
"ContactMedium": {
"title": "ContactMedium",
"required": [
"@type"
],
"type": "object",
"properties": {
"@type": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
}
},
"discriminator": {
"propertyName": "@type",
"mapping": {
"EmailContact": "EmailContact"
}
}
},
"EmailContact": {
"title": "EmailContact",
"allOf": [
{
"$ref": "#/components/schemas/ContactMedium"
},
{
"type": "object",
"properties": {
"emailAddress": {
"type": "string"
}
}
}
]
}
}
}
}
Validating party like below
{
"name": "John",
"contactMediums": [
{
"@type": "EmailContact",
"name": "Primary Email",
"emailAddress": "test@example.com"
}
]
}
caused the following validation result:
[Path '/contactMediums/0'] Object instance has properties which are not allowed by the schema: ["@type","name"]
i created the validator using this code
final ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
parseOptions.setResolveCombinators(true);
final OpenApiInteractionValidator validator = OpenApiInteractionValidator
.createForInlineApiSpecification(this.specString)
.withParseOptions(parseOptions)
.build();
Comments (3)
-
-
Also present here with
2.35.1
and OAS3.1.0
.
I cannot make a use of discriminator andallOf
together -
I see lot of issues around Discriminator with this library. The issues have been raised since 2020, why is this not being fixed? @James Navin what is your take on lack of Discriminator support for oneOf and anyOf, and when is this TODO going to be addressed?
// TODO: `oneOf` and `anyOf` composition validation logic final JsonNode currentSchemaNode = data.getSchema().getNode(); if (currentSchemaNode.has("oneOf") || currentSchemaNode.has("anyOf")) { log.debug("Support for discriminators with oneOf/anyOf not implemented yet. Validation may be inaccurate."); return; }
- Log in to comment
I think I have the same problem.
is failing with:
Object instance has properties which are not allowed by the schema: ["name","type"]
Explicitly adding the fields to A works, but with the `allOf` it should not be required.