Safe Haskell | None |
---|---|
Language | Haskell2010 |
- compile :: forall err. Spec err -> SchemaGraph -> RawSchema -> Schema err
- validate :: Schema err -> Value -> [ValidationFailure err]
- newtype Spec err = Spec {}
- newtype Schema err = Schema {
- _unSchema :: [Value -> [ValidationFailure err]]
- data RawSchema = RawSchema {}
- type SchemaCache = HashMap Text (HashMap Text Value)
- data SchemaGraph = SchemaGraph {}
- data ValSpec err = ValSpec EmbeddedSchemas (ValidatorConstructor err [ValidationFailure err])
- type EmbeddedSchemas = Maybe Text -> Value -> [RawSchema]
- type ValidatorConstructor schemaErr valErr = Spec schemaErr -> SchemaGraph -> RawSchema -> Value -> Maybe (Value -> valErr)
- data ValidationFailure err = ValidationFailure {
- _failureName :: !err
- _failureInfo :: !FailureInfo
- data FailureInfo = FailureInfo {
- _validatingData :: !Value
- _offendingData :: !Value
- fetchReferencedSchemas :: Spec err -> SchemaCache -> RawSchema -> IO (Either Text SchemaGraph)
- fetchReferencedSchemas' :: forall m e t err. (MonadIO m, Functor m, MonadError t e, Traversable e, IsString t) => (Text -> m (e ByteString)) -> Spec err -> SchemaCache -> RawSchema -> m (e SchemaGraph)
- data Draft4Failure
- = MultipleOf
- | Maximum
- | ExclusiveMaximum
- | Minimum
- | ExclusiveMinimum
- | MaxLength
- | MinLength
- | Pattern
- | Items Draft4Failure
- | AdditionalItemsBool
- | AdditionalItemsObject Draft4Failure
- | MaxItems
- | MinItems
- | UniqueItems
- | MaxProperties
- | MinProperties
- | Required
- | Properties Draft4Failure
- | PatternProperties Draft4Failure
- | AdditionalPropertiesBool
- | AdditionalPropertiesObject Draft4Failure
- | SchemaDependency Draft4Failure
- | PropertyDependency
- | Enum
- | TypeValidator
- | AllOf Draft4Failure
- | AnyOf
- | OneOf
- | NotValidator
- | Ref Draft4Failure
- draft4 :: Spec Draft4Failure
- isValidSchema :: RawSchema -> [ValidationFailure Draft4Failure]
- compileDraft4 :: SchemaGraph -> RawSchema -> Either [ValidationFailure Draft4Failure] (Schema Draft4Failure)
Primary API
validate :: Schema err -> Value -> [ValidationFailure err] Source
Schemas
type SchemaCache = HashMap Text (HashMap Text Value) Source
A set of RawSchemas, split into a HashMap.
Keys correspond to Schema _rsURIs. Values correspond to Schema _rsDatas.
data SchemaGraph Source
SchemaGraph | |
|
Validators
ValSpec EmbeddedSchemas (ValidatorConstructor err [ValidationFailure err]) |
type EmbeddedSchemas = Maybe Text -> Value -> [RawSchema] Source
Return a schema's immediate subschemas.
This is used by fetchRefs
to find all the
subschemas in a document. This allows it to process only
"$ref"s and "id"s that are actual schema keywords.
type ValidatorConstructor schemaErr valErr = Spec schemaErr -> SchemaGraph -> RawSchema -> Value -> Maybe (Value -> valErr) Source
This is what's used to write most validators in practice.
Its important that particular validators don't know about the error sum type of the Spec they're going to be used in. That way they can be included in other Specs later without encouraging partial functions.
This means that a properly written ValidatorConstructor will need its error type modified for use in a Spec. Data.JsonSchema.Helpers provides giveName and modifyName for this purpose.
data ValidationFailure err Source
ValidationFailure | |
|
Show err => Show (ValidationFailure err) Source |
data FailureInfo Source
Schema feching tools
fetchReferencedSchemas :: Spec err -> SchemaCache -> RawSchema -> IO (Either Text SchemaGraph) Source
Take a schema. Retrieve every document either it or its
subschemas include via the "$ref" keyword. Load a SchemaGraph
out
with them.
fetchReferencedSchemas' :: forall m e t err. (MonadIO m, Functor m, MonadError t e, Traversable e, IsString t) => (Text -> m (e ByteString)) -> Spec err -> SchemaCache -> RawSchema -> m (e SchemaGraph) Source
A version of fetchReferencedSchemas where the function to make requests is provided by the user. This allows restrictions to be added, e.g. rejecting non-local URIs.
Draft 4 specific
data Draft4Failure Source
isValidSchema :: RawSchema -> [ValidationFailure Draft4Failure] Source
Check if a RawSchema
is valid Draft 4 schema.
This is just a convenience function built by preloading validate
with the spec schema that describes valid Draft 4 schemas.
NOTE: It's not actually required to run isValidSchema
on
prospective draft 4 schemas at all. However, it's a good way to
catch unintentional mistakes in schema documents.
compileDraft4 :: SchemaGraph -> RawSchema -> Either [ValidationFailure Draft4Failure] (Schema Draft4Failure) Source
Check that a RawSchema
conforms to the JSON Schema Draft 4
master schema document. Compile it if it does.
This is just a convenience function built by combining
isValidSchema
and compile
.
NOTE: It's not actually required to run isValidSchema
on
prospective draft 4 schemas at all.