- edited description
Discriminator validation does not follow $ref resulting in false positives
The code from swagger-request-validator / swagger-request-validator-core / src / main / java / com / atlassian / oai / validator / schema / SwaggerV20Library.java tries to validate discriminator fields have type=string.
final JsonNode property = properties.get(discriminatorFieldName);
if (!property.has("type") ||
!property.get("type").textValue().equalsIgnoreCase("string")) {
report.error(msg(tree, bundle, "err.swaggerv2.discriminator.wrongType")
.putArgument("fieldName", discriminatorFieldName)
);
return;
}
However, if the schema looks like this, where the discriminator is actually a $ref to a field defined elsewhere, it doesn't work because the code doesn't dereference the $ref first.
“Animal”: {
"discriminator": “animalType",
"type": "object",
"required": [
"animalType",
],
"properties": {
…
"animalType": {
"$ref": "/model/DataDictionary.json#/animalType"
}
}
}
}
Conceptually it's an easy fix, just add 2 lines like this before doing the check.
while ( property is a $ref node )
property = property. dereference
Is there a utility function in your library somewhere for doing this?
Comments (4)
-
reporter -
reporter - edited description
-
reporter - edited description
-
Thanks for raising this.
I think this is the same, or related, to Issue
#44.The JSON schema validation in SRV is using the
com.github.java-json-tools:json-schema-validator
library. Taking a quick look there appears to be methods on theSchemaTree
interface for resolving refs that might work in this scenario, but Id have to spend some time playing with it. - Log in to comment