Class JsonSchemaFactory

    • Method Detail

      • getInstance

        public static JsonSchemaFactory getInstance​(SpecVersion.VersionFlag versionFlag)
        Creates a factory with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.
        Parameters:
        versionFlag - the default dialect
        Returns:
        the factory
      • getInstance

        public static JsonSchemaFactory getInstance​(SpecVersion.VersionFlag versionFlag,
                                                    Consumer<JsonSchemaFactory.Builder> customizer)
        Creates a factory with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.
        Parameters:
        versionFlag - the default dialect
        customizer - to customize the factory
        Returns:
        the factory
      • newJsonSchema

        protected JsonSchema newJsonSchema​(SchemaLocation schemaUri,
                                           com.fasterxml.jackson.databind.JsonNode schemaNode,
                                           SchemaValidatorsConfig config)
        Creates a json schema from initial input.
        Parameters:
        schemaUri - the schema location
        schemaNode - the schema data node
        config - the config to use
        Returns:
        the schema
      • getSchemaLocation

        protected SchemaLocation getSchemaLocation​(SchemaLocation schemaLocation)
        Gets the base IRI from the schema retrieval IRI if present otherwise return one with a null base IRI.

        Note that the resolving of the $id or id in the schema node will take place in the JsonSchema constructor.

        Parameters:
        schemaLocation - the schema retrieval uri
        Returns:
        the schema location
      • getMetaSchema

        public JsonMetaSchema getMetaSchema​(String iri,
                                            SchemaValidatorsConfig config)
        Gets the meta-schema that is available to the factory.
        Parameters:
        iri - the IRI of the meta-schema
        config - the schema validators config
        Returns:
        the meta-schema
      • loadMetaSchema

        protected JsonMetaSchema loadMetaSchema​(String iri,
                                                SchemaValidatorsConfig config)
        Loads the meta-schema from the configured meta-schema factory.
        Parameters:
        iri - the IRI of the meta-schema
        config - the schema validators config
        Returns:
        the meta-schema
      • getSchema

        public JsonSchema getSchema​(String schema,
                                    SchemaValidatorsConfig config)
        Gets the schema.

        Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.

        Parameters:
        schema - the schema data as a string
        config - the config
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(String schema)
        Gets the schema.

        Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.

        Parameters:
        schema - the schema data as a string
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(InputStream schemaStream,
                                    SchemaValidatorsConfig config)
        Gets the schema.

        Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.

        Parameters:
        schemaStream - the input stream with the schema data
        config - the config
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(InputStream schemaStream)
        Gets the schema.

        Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.

        Parameters:
        schemaStream - the input stream with the schema data
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(SchemaLocation schemaUri,
                                    SchemaValidatorsConfig config)
        Gets the schema.
        Parameters:
        schemaUri - the absolute IRI of the schema which can map to the retrieval IRI.
        config - the config
        Returns:
        the schema
      • getYamlMapper

        protected com.fasterxml.jackson.databind.ObjectMapper getYamlMapper()
      • getJsonMapper

        protected com.fasterxml.jackson.databind.ObjectMapper getJsonMapper()
      • createSchemaValidatorsConfig

        protected SchemaValidatorsConfig createSchemaValidatorsConfig()
        Creates a schema validators config.
        Returns:
        the schema validators config
      • getSchema

        public JsonSchema getSchema​(URI schemaUri)
        Gets the schema.
        Parameters:
        schemaUri - the absolute IRI of the schema which can map to the retrieval IRI.
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(URI schemaUri,
                                    com.fasterxml.jackson.databind.JsonNode jsonNode,
                                    SchemaValidatorsConfig config)
        Gets the schema.
        Parameters:
        schemaUri - the absolute IRI of the schema which can map to the retrieval IRI.
        jsonNode - the node
        config - the config
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(URI schemaUri,
                                    com.fasterxml.jackson.databind.JsonNode jsonNode)
        Gets the schema.
        Parameters:
        schemaUri - the absolute IRI of the schema which can map to the retrieval IRI.
        jsonNode - the node
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(SchemaLocation schemaUri)
        Gets the schema.
        Parameters:
        schemaUri - the absolute IRI of the schema which can map to the retrieval IRI.
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(SchemaLocation schemaUri,
                                    com.fasterxml.jackson.databind.JsonNode jsonNode,
                                    SchemaValidatorsConfig config)
        Gets the schema.
        Parameters:
        schemaUri - the base absolute IRI
        jsonNode - the node
        config - the config
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(SchemaLocation schemaUri,
                                    com.fasterxml.jackson.databind.JsonNode jsonNode)
        Gets the schema.
        Parameters:
        schemaUri - the base absolute IRI
        jsonNode - the node
        Returns:
        the schema
      • getSchema

        public JsonSchema getSchema​(com.fasterxml.jackson.databind.JsonNode jsonNode)
        Gets the schema.

        Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.

        Prefer getSchema(SchemaLocation, JsonNode) instead to ensure the base IRI if no id is present.

        Parameters:
        jsonNode - the node
        Returns:
        the schema
      • normalizeMetaSchemaUri

        protected static String normalizeMetaSchemaUri​(String id)
        Normalizes the standard JSON schema dialects.

        This should not normalize any other unrecognized dialects.

        Parameters:
        id - the $schema identifier
        Returns:
        the normalized uri