Giter VIP home page Giter VIP logo

Comments (5)

justin-tay avatar justin-tay commented on May 28, 2024

Examples can be found at https://github.com/networknt/json-schema-validator/blob/master/doc/schema-retrieval.md.

from json-schema-validator.

fitz-97 avatar fitz-97 commented on May 28, 2024

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

from json-schema-validator.

justin-tay avatar justin-tay commented on May 28, 2024

You at least need to post what you have tried and what isn't working.

from json-schema-validator.

justin-tay avatar justin-tay commented on May 28, 2024

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.

from json-schema-validator.

fitz-97 avatar fitz-97 commented on May 28, 2024

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

from json-schema-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.