-
Notifications
You must be signed in to change notification settings - Fork 328
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
Since 1.3.1: unevaluatedProperties doesn't work with external schemas #943
Comments
This is happening because I have some logic to determine if annotations need to be collected for evaluation and one of the checks is checking if the As a workaround you can switch on annotation collection. String schemaData = "{\r\n"
+ " \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\r\n"
+ " \"$ref\": \"https://geojson.org/schema/Point.json\",\r\n"
+ " \"unevaluatedProperties\": false\r\n"
+ "}";
String inputData = "{\r\n"
+ " \"type\": \"Point\",\r\n"
+ " \"coordinates\": [1, 1]\r\n"
+ "}";
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.setPathType(PathType.JSON_POINTER);
JsonSchema schema = factory.getSchema(schemaData, config);
System.out.println(schema.validate(inputData, InputFormat.JSON, OutputFormat.HIERARCHICAL, executionContext -> {
executionContext.getExecutionConfig().setAnnotationCollectionEnabled(true);
executionContext.getExecutionConfig().setAnnotationCollectionPredicate(keyword -> true);
})); The results if annotation collection is turned on. {
"valid" : true,
"evaluationPath" : "",
"schemaLocation" : "#",
"instanceLocation" : "",
"annotations" : {
"unevaluatedProperties" : [ ]
},
"details" : [ {
"valid" : true,
"evaluationPath" : "/$ref",
"schemaLocation" : "https://geojson.org/schema/Point.json#",
"instanceLocation" : "",
"annotations" : {
"properties" : [ "type", "coordinates" ],
"title" : "GeoJSON Point"
},
"details" : [ {
"valid" : true,
"evaluationPath" : "/$ref/properties/coordinates",
"schemaLocation" : "https://geojson.org/schema/Point.json#/properties/coordinates",
"instanceLocation" : "/coordinates",
"annotations" : {
"items" : true
}
} ]
} ]
} |
Thanks! I tried making a copy of the Point schema locally and change it to 2020-12, but I still get the same thing. As for the annotation collection, the setAnnotationCollectionEnabled() method is protected, so it can't be accessed. |
Must have used the wrong access modifier by mistake. Shall also fix that. |
If a schema contains all properties then unevaluatedProperties works as expected, but if some properties come from an external schema then they are ignored. So, given this instance:
The following schema will work:
But this will not, resulting in error messages relating to unevaluated properties
$.type
and$.coordinates
:The text was updated successfully, but these errors were encountered: