Closed aznan2 closed 7 months ago
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 unevaluatedProperties
keyword exists in the meta-schema. In this case the schema at https://geojson.org/schema/Point.json
is a Draft 7 schema so it doesn't collect the annotations. It sounds like I may need to remove that check.
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
: