xref: /aosp_15_r20/external/json-schema-validator/doc/metaschema-validation.md (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1*78c4dd6aSAndroid Build Coastguard WorkerIf you have an use case to validate custom schemas against the one of the JSON schema draft version, here is the code that you can do it.
2*78c4dd6aSAndroid Build Coastguard Worker
3*78c4dd6aSAndroid Build Coastguard Worker```
4*78c4dd6aSAndroid Build Coastguard Worker  public static final Function<ObjectNode, Set<SchemaValidationMessage>> validateAgainstMetaSchema =
5*78c4dd6aSAndroid Build Coastguard Worker      schema -> {
6*78c4dd6aSAndroid Build Coastguard Worker        JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909);
7*78c4dd6aSAndroid Build Coastguard Worker         JsonSchema metaSchema = factory.getSchema(getSchemaUri());
8*78c4dd6aSAndroid Build Coastguard Worker        return metaSchema.validate(schema).stream()
9*78c4dd6aSAndroid Build Coastguard Worker            .map((validation) -> new SchemaValidationMessage(validation.getMessage()))
10*78c4dd6aSAndroid Build Coastguard Worker            .collect(Collectors.toSet());
11*78c4dd6aSAndroid Build Coastguard Worker      };
12*78c4dd6aSAndroid Build Coastguard Worker
13*78c4dd6aSAndroid Build Coastguard Worker```
14*78c4dd6aSAndroid Build Coastguard Worker
15*78c4dd6aSAndroid Build Coastguard WorkerThis should now work but does not support all the keywords because the JsonMetaSchema of SpecVersion.VersionFlag.V201909 is lacking these features.
16*78c4dd6aSAndroid Build Coastguard Worker
17*78c4dd6aSAndroid Build Coastguard WorkerYou can fix the issue by resolving the vocabularies to a local resource file and re-do the JsonMetaSchema for 2019 based on that.
18*78c4dd6aSAndroid Build Coastguard Worker
19*78c4dd6aSAndroid Build Coastguard Worker
20*78c4dd6aSAndroid Build Coastguard Worker
21