Replies: 1 comment
-
Is there a specific reason why you want to specify your custom meta schema using a json file? In the first place to do this you would need to define a custom vocabulary for which you would associate your custom keyword implementations but your custom meta schema doesn't have any custom vocabulary. You then need to map the meta schema If you want to specify it by code you just have to create the meta schema with the keyword. JsonMetaSchema metaSchema = JsonMetaSchema
.builder("https://domain/meta-schema/myschema/v1/schema", JsonMetaSchema.getV202012())
.keyword(new MinDateKeyword()).build(); Then use this when you create your factory. JsonSchemaFactory.getInstance(VersionFlag.V202012, builder -> builder.metaSchema(metaSchema)); If you have resources on the classpath you should generally not load the schema in that way. You should be mapping the You would typically map using a prefix and then place the resource in the correct folder structure JsonSchemaFactory.getInstance(VersionFlag.V202012, builder -> builder.metaSchema(metaSchema)
.schemaMappers(schemaMappers -> schemaMappers.mapPrefix("https://domain", "classpath:"))); Or if you really want JsonSchemaFactory.getInstance(VersionFlag.V202012,
builder -> builder.metaSchema(metaSchema).schemaMappers(schemaMappers -> schemaMappers.mappings(
Collections.singletonMap("https://domain/retail/product.schema", "classpath:my_schema.json")))); You can then load using JsonMetaSchema metaSchema = JsonMetaSchema
.builder("https://domain/meta-schema/myschema/v1/schema", JsonMetaSchema.getV202012())
.keyword(new MinDateKeyword()).build();
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012,
builder -> builder.metaSchema(metaSchema).schemaMappers(schemaMappers -> schemaMappers.mappings(
Collections.singletonMap("https://domain/retail/product.schema", "classpath:my_schema.json"))));
JsonSchema schema = factory.getSchema(SchemaLocation.of("https://domain/retail/product.schema")); |
Beta Was this translation helpful? Give feedback.
-
Iam creating a custom meta-schema json file by extending the existing json-schema version 202012. How can i make json-schema-validator to use this custom meta-schema instead of default schema dialect from 202012?
Problem details:
I have created a JSON file in my local called "my_custom_meta_schema.json" which has following content:
Now, I will be creating a schema which uses the above meta-schema , It will start with something like :
I am using networknt's json-schema-validator
implementation ("com.networknt:json-schema-validator:1.4.0")
How can I make
JsonSchemaFactory
to use the custom meta schema instead of default one?My current function uses default 202012 draft . but I want to use my custom meta schema (extended from 202012 version) for validation
My current function (It doesn't use custom meta schema currently ):
Beta Was this translation helpful? Give feedback.
All reactions