Closed fitz-97 closed 1 month ago
Examples can be found at https://github.com/networknt/json-schema-validator/blob/master/doc/schema-retrieval.md.
Examples can be found at https://github.com/networknt/json-schema-validator/blob/master/doc/schema-retrieval.md.
thank u for ur attention, But I couldn't solve it, it still verifies my $schema or $id. Will you consider using a simpler way to support this requirement? Because of performance issues, I still want to use this project
You at least need to post what you have tried and what isn't working.
The following is an example since you didn't post what are the contents of the schema or the meta-schema. Typically you will map the schema data from a classpath resource so that you don't have it all as an inline string.
String metaSchemaData = "{}";
String schemaData = "{}";
Map<String, String> schemas = new HashMap<>();
schemas.put("https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1", metaSchemaData);
schemas.put("https://schemas.amazon.com/selling-partners/definitions/product-types/schema/v1/HAIR_BRUSH", schemaData);
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V201909,
builder -> builder.schemaLoaders(schemaLoaders -> schemaLoaders.schemas(schemas)));
JsonSchema schema = factory.getSchema(SchemaLocation
.of("https://schemas.amazon.com/selling-partners/definitions/product-types/schema/v1/HAIR_BRUSH"));
String inputData = "{}";
System.out.println(schema.validate(inputData, InputFormat.JSON, OutputFormat.HIERARCHICAL));
It looks like there is a custom meta-schema https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1
with a custom vocabulary and custom keywords. If you need those keywords to do anything you will have to implement them yourself as they are non-standard.
The following is an example since you didn't post what are the contents of the schema or the meta-schema. Typically you will map the schema data from a classpath resource so that you don't have it all as an inline string.
String metaSchemaData = "{}"; String schemaData = "{}"; Map<String, String> schemas = new HashMap<>(); schemas.put("https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1", metaSchemaData); schemas.put("https://schemas.amazon.com/selling-partners/definitions/product-types/schema/v1/HAIR_BRUSH", schemaData); JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V201909, builder -> builder.schemaLoaders(schemaLoaders -> schemaLoaders.schemas(schemas))); JsonSchema schema = factory.getSchema(SchemaLocation .of("https://schemas.amazon.com/selling-partners/definitions/product-types/schema/v1/HAIR_BRUSH")); String inputData = "{}"; System.out.println(schema.validate(inputData, InputFormat.JSON, OutputFormat.HIERARCHICAL));
It looks like there is a custom meta-schema
https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1
with a custom vocabulary and custom keywords. If you need those keywords to do anything you will have to implement them yourself as they are non-standard.
I seem to have found a solution, thank you for your answer
I try to use this project to do some verification as shown in the picture. This schema is provided by Amazon, but its $id and $schema are not reachable URLs, but more like an identifier, nothing more. But when I try to build JsonSchema, it seems that I will actively go to this URL to get the corresponding structure. This is not what I expected. I hope to get the Schema directly from the file or String instead of through the network protocol. I tried looking for "examples" but couldn't find any. If there is a solution, please help me, thank you