- changed status to new
Discriminator validation fails with NullPointer
Issue #286
resolved
ProductId:
required:
- productId
type: object
properties:
productId:
type: string
enum:
- test
- test2
- test3
Product:
type: string
allOf:
- $ref: "#/components/schemas/ProductId"
discriminator:
propertyName: productId
mapping:
test: "#/components/schemas/test"
When validating this will result in a
com.google.common.util.concurrent.UncheckedExecutionException:
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2051) ~[guava-28.1-jre.jar:?]
at com.google.common.cache.LocalCache.get(LocalCache.java:3953) ~[guava-28.1-jre.jar:?]
..
Caused by: java.lang.NullPointerExceptionat com.atlassian.oai.validator.schema.keyword.Discriminator$DiscriminatorSyntaxChecker.checkValue(Discriminator.java:92) ~[classes/:?]
It expects when using allOf
and a discriminator that you also should have a property in the object.
…….
if (tree.getNode().get("oneOf") != null) {
return; // no need to check for 'properties', 'required' etc.
}
final JsonNode properties = tree.getNode().get("properties");
final List<String> propertyNames = stream(properties.fieldNames()).collect(toList());
if (!properties.has(discriminatorFieldName)) {
report.error(msg(tree, bundle, "err.swaggerv2.discriminator.noProperty").putArgument("fieldName", discriminatorFieldName).putArgument("properties", propertyNames));
return;
}
Should the code not be
if (tree.getNode().get("oneOf") != null || tree.getNode().get("allOf") != nul) {
return; // no need to check for 'properties', 'required' etc.
}
Comments (3)
-
reporter -
- edited description
-
- changed status to resolved
Available in v2.12.0
- Log in to comment
Should not result in nullpointer exception. Discriminator should work with allOf