hjsonschema-1.5.0.0: JSON Schema library

Safe HaskellNone
LanguageHaskell2010

JSONSchema.Draft4

Contents

Synopsis

Draft 4 Schema

data SchemaWithURI schema Source #

Constructors

SchemaWithURI 

Fields

  • _swSchema :: !schema
     
  • _swURI :: !(Maybe Text)

    This is the URI identifying the document containing the schema. It's different than the schema's "id" field, which controls scope when resolving references contained in the schema.

Instances

Eq schema => Eq (SchemaWithURI schema) Source # 

Methods

(==) :: SchemaWithURI schema -> SchemaWithURI schema -> Bool #

(/=) :: SchemaWithURI schema -> SchemaWithURI schema -> Bool #

Show schema => Show (SchemaWithURI schema) Source # 

Methods

showsPrec :: Int -> SchemaWithURI schema -> ShowS #

show :: SchemaWithURI schema -> String #

showList :: [SchemaWithURI schema] -> ShowS #

data Schema Source #

Constructors

Schema 

Fields

One-step validation (getting references over HTTP)

fetchHTTPAndValidate :: SchemaWithURI Schema -> Value -> IO (Either HTTPValidationFailure ()) Source #

Fetch recursively referenced schemas over HTTP, check that both the original and referenced schemas are valid, then validate then data.

newtype SchemaInvalid Source #

A description of why a schema (or one of its reference) is itself invalid.

Nothing indicates the starting schema. Just indicates a referenced schema. The contents of the Just is the schema's URI.

NOTE: 'HashMap (Maybe Text) Invalid' would be a nicer way of defining this, but then we lose the guarantee that there's at least one key.

One-step validation (getting references from the filesystem)

fetchFilesystemAndValidate :: SchemaWithURI Schema -> Value -> IO (Either FilesystemValidationFailure ()) Source #

Fetch recursively referenced schemas from the filesystem, check that both the original and referenced schemas are valid, then validate the data.

Validation failure

data Invalid Source #

Used to report an entire instance being invalidated, as opposed to the failure of a single validator.

Fetching tools

data ReferencedSchemas schema Source #

Constructors

ReferencedSchemas 

Fields

  • _rsStarting :: !schema

    Used to resolve relative references when we don't know what the scope of the current schema is. This only happens with starting schemas because if we're using a remote schema we had to know its URI in order to fetch it.

    Tracking the starting schema (instead of just resolving the reference to the current schema being used for validation) is necessary for cases where schemas are embedded inside one another. For instance in this case not distinguishing the starting and "foo" schemas sends the code into an infinite loop:

    { "additionalProperties": false, "properties": { "foo": { "$ref": "#" } } }

  • _rsSchemaMap :: !(HashMap Text schema)

    Map of URIs to schemas.

Instances

Eq schema => Eq (ReferencedSchemas schema) Source # 

Methods

(==) :: ReferencedSchemas schema -> ReferencedSchemas schema -> Bool #

(/=) :: ReferencedSchemas schema -> ReferencedSchemas schema -> Bool #

Show schema => Show (ReferencedSchemas schema) Source # 

newtype URISchemaMap schema Source #

Keys are URIs (without URI fragments).

Constructors

URISchemaMap 

Fields

Instances

Eq schema => Eq (URISchemaMap schema) Source # 

Methods

(==) :: URISchemaMap schema -> URISchemaMap schema -> Bool #

(/=) :: URISchemaMap schema -> URISchemaMap schema -> Bool #

Show schema => Show (URISchemaMap schema) Source # 

Methods

showsPrec :: Int -> URISchemaMap schema -> ShowS #

show :: URISchemaMap schema -> String #

showList :: [URISchemaMap schema] -> ShowS #

referencesViaHTTP :: SchemaWithURI Schema -> IO (Either HTTPFailure (URISchemaMap Schema)) Source #

Fetch the schemas recursively referenced by a starting schema over HTTP.

referencesViaFilesystem :: SchemaWithURI Schema -> IO (Either FilesystemFailure (URISchemaMap Schema)) Source #

Fetch the schemas recursively referenced by a starting schema from the filesystem.

Other Draft 4 things exported just in case

schemaValidity :: Schema -> [ValidatorFailure] Source #

Check that a schema itself is valid (if so the returned list will be empty).

referencesValidity Source #

Arguments

:: URISchemaMap Schema 
-> [(Text, NonEmpty ValidatorFailure)]

The first item of the tuple is the URI of a schema, the second is that schema's validation errors.

Check that a set of referenced schemas are valid (if so the returned list will be empty).

checkSchema :: URISchemaMap Schema -> SchemaWithURI Schema -> Either SchemaInvalid (Value -> [ValidatorFailure]) Source #

Checks if a schema and a set of referenced schemas are valid.

Return a function to validate data.

draft4FetchInfo :: FetchInfo Schema Source #

An instance of FetchInfo specialized for JSON Schema Draft 4.