hjsonschema-1.1.0.1: JSON Schema library

Safe HaskellNone
LanguageHaskell2010

Data.JsonSchema.Fetch

Contents

Synopsis

Types

data FetchInfo schema Source #

This is all the fetching functions need to know about a particular JSON Schema draft, e.g. JSON Schema Draft 4.

Constructors

FetchInfo 

Fields

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 :: !(URISchemaMap schema)
     

Instances

Eq schema => Eq (ReferencedSchemas schema) Source # 

Methods

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

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

Show schema => Show (ReferencedSchemas schema) Source # 

type URISchemaMap schema = HashMap Text schema Source #

Keys are URIs (without URI fragments).

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 #

Fetch via HTTP

referencesViaHTTP' :: forall schema. FromJSON schema => FetchInfo schema -> SchemaWithURI schema -> IO (Either HTTPFailure (URISchemaMap schema)) Source #

Take a schema. Retrieve every document either it or its subschemas include via the "$ref" keyword.

Fetch via Filesystem

referencesViaFilesystem' :: forall schema. FromJSON schema => FetchInfo schema -> SchemaWithURI schema -> IO (Either FilesystemFailure (URISchemaMap schema)) Source #

Method Agnostic Fetching Tools

referencesMethodAgnostic :: forall schema. FromJSON schema => (Text -> IO ByteString) -> FetchInfo schema -> SchemaWithURI schema -> IO (Either Text (URISchemaMap schema)) Source #

A version of fetchReferencedSchemas where the function to fetch schemas is provided by the user. This allows restrictions to be added, e.g. rejecting non-local URIs.

getRecursiveReferences :: forall schema. FromJSON schema => (Text -> IO ByteString) -> FetchInfo schema -> URISchemaMap schema -> SchemaWithURI schema -> IO (Either Text (URISchemaMap schema)) Source #

includeSubschemas :: forall schema. FetchInfo schema -> SchemaWithURI schema -> [SchemaWithURI schema] Source #

Return the schema passed in as an argument, as well as every subschema contained within it.