Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data SchemaWithURI schema = SchemaWithURI {}
- data Schema = Schema {
- _schemaVersion :: Maybe Text
- _schemaId :: Maybe Text
- _schemaRef :: Maybe Text
- _schemaDefinitions :: Maybe (HashMap Text Schema)
- _schemaOther :: HashMap Text Value
- _schemaMultipleOf :: Maybe Scientific
- _schemaMaximum :: Maybe Scientific
- _schemaExclusiveMaximum :: Maybe Bool
- _schemaMinimum :: Maybe Scientific
- _schemaExclusiveMinimum :: Maybe Bool
- _schemaMaxLength :: Maybe Int
- _schemaMinLength :: Maybe Int
- _schemaPattern :: Maybe Text
- _schemaMaxItems :: Maybe Int
- _schemaMinItems :: Maybe Int
- _schemaUniqueItems :: Maybe Bool
- _schemaItems :: Maybe (Items Schema)
- _schemaAdditionalItems :: Maybe (AdditionalItems Schema)
- _schemaMaxProperties :: Maybe Int
- _schemaMinProperties :: Maybe Int
- _schemaRequired :: Maybe Required
- _schemaDependencies :: Maybe (HashMap Text (Dependency Schema))
- _schemaProperties :: Maybe (HashMap Text Schema)
- _schemaPatternProperties :: Maybe (HashMap Text Schema)
- _schemaAdditionalProperties :: Maybe (AdditionalProperties Schema)
- _schemaEnum :: Maybe EnumVal
- _schemaType :: Maybe TypeVal
- _schemaAllOf :: Maybe (NonEmpty Schema)
- _schemaAnyOf :: Maybe (NonEmpty Schema)
- _schemaOneOf :: Maybe (NonEmpty Schema)
- _schemaNot :: Maybe Schema
- emptySchema :: Schema
- fetchHTTPAndValidate :: SchemaWithURI Schema -> Value -> IO (Either HTTPValidationFailure ())
- data HTTPValidationFailure
- data HTTPFailure
- type InvalidSchema = NonEmpty (Maybe Text, Failure)
- fetchFilesystemAndValidate :: SchemaWithURI Schema -> Value -> IO (Either FilesystemValidationFailure ())
- data FilesystemValidationFailure
- data FilesystemFailure
- type Invalid = NonEmpty Failure
- type Failure = Fail ValidatorChain
- data Fail err = Failure {}
- data ValidatorChain
- = MultipleOf
- | Maximum
- | ExclusiveMaximum
- | Minimum
- | ExclusiveMinimum
- | MaxLength
- | MinLength
- | PatternValidator
- | MaxItems
- | MinItems
- | UniqueItems
- | Items ValidatorChain
- | AdditionalItemsBool
- | AdditionalItemsObject ValidatorChain
- | MaxProperties
- | MinProperties
- | Required
- | SchemaDependency ValidatorChain
- | PropertyDependency
- | Properties ValidatorChain
- | PatternProperties ValidatorChain
- | AdditionalPropertiesBool
- | AdditionalPropertiesObject ValidatorChain
- | RefResolution
- | RefLoop
- | Ref ValidatorChain
- | Enum
- | TypeValidator
- | AllOf ValidatorChain
- | AnyOf ValidatorChain
- | OneOfTooManySuccesses
- | OneOfNoSuccesses ValidatorChain
- | NotValidator
- data ReferencedSchemas schema = ReferencedSchemas {
- _rsStarting :: !schema
- _rsSchemaMap :: !(URISchemaMap schema)
- referencesViaHTTP :: SchemaWithURI Schema -> IO (Either HTTPFailure (URISchemaMap Schema))
- referencesViaFilesystem :: SchemaWithURI Schema -> IO (Either FilesystemFailure (URISchemaMap Schema))
- metaSchema :: Schema
- metaSchemaBytes :: ByteString
- schemaValidity :: Schema -> [Failure]
- referencesValidity :: URISchemaMap Schema -> [(Text, Failure)]
- checkSchema :: URISchemaMap Schema -> SchemaWithURI Schema -> Either InvalidSchema (Value -> [Failure])
- draft4FetchInfo :: FetchInfo Schema
Draft 4 Schema
data SchemaWithURI schema Source #
Eq schema => Eq (SchemaWithURI schema) Source # | |
Show schema => Show (SchemaWithURI schema) Source # | |
emptySchema :: Schema Source #
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, and then validate data.
data HTTPValidationFailure Source #
data HTTPFailure Source #
type InvalidSchema = NonEmpty (Maybe Text, Failure) 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, and then validate data.
data FilesystemFailure Source #
Validation failure
type Failure = Fail ValidatorChain Source #
Validators shouldn't know more about the schema they're going to be used with than necessary. If a validator throws errors using the error sum type of a particular schema, then it can't be used with other schemas later that have different error sum types (at least not without writing partial functions).
Because of this we make Fail
a higher order type, so each validator
can return a sum type describing only the failures that can occur in that
validator (or '()' if that validator can only fail in one way).
It's the job of a schema's validate function to unify the errors produced
by the validators it uses into a single error sum type for that schema.
The schema's validate function will return a Fail
with
that sum type as its type argument.
The slightly weird naming (Fail
and Failure
) is so that we can define
a 'type Failure = Fail SchemaErrorType' for each of our schemas, and
export it along with 'Fail(..)'. This way the users of the library only
use Failure
, not Fail
.
Failure | |
|
data ValidatorChain Source #
Distinguish all the different possible causes of failure for Draft 4 validation.
MultipleOf | |
Maximum | |
ExclusiveMaximum | |
Minimum | |
ExclusiveMinimum | |
MaxLength | |
MinLength | |
PatternValidator | |
MaxItems | |
MinItems | |
UniqueItems | |
Items ValidatorChain | |
AdditionalItemsBool | |
AdditionalItemsObject ValidatorChain | |
MaxProperties | |
MinProperties | |
Required | |
SchemaDependency ValidatorChain | |
PropertyDependency | |
Properties ValidatorChain | |
PatternProperties ValidatorChain | |
AdditionalPropertiesBool | |
AdditionalPropertiesObject ValidatorChain | |
RefResolution | Indicates a reference that failed to resolve. NOTE: The language agnostic test suite doesn't specify if this should cause a validation error or should allow data to pass. We choose to return a validation error. Also note that ideally we would enforce in the type system that any failing references be dealt with before valididation. Then this could be removed entirely. |
RefLoop | |
Ref ValidatorChain | |
Enum | |
TypeValidator | |
AllOf ValidatorChain | |
AnyOf ValidatorChain | |
OneOfTooManySuccesses | |
OneOfNoSuccesses ValidatorChain | |
NotValidator |
Fetching tools
data ReferencedSchemas schema Source #
ReferencedSchemas | |
|
Eq schema => Eq (ReferencedSchemas schema) Source # | |
Show schema => Show (ReferencedSchemas schema) Source # | |
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
metaSchema :: Schema Source #
schemaValidity :: Schema -> [Failure] Source #
Check that a schema itself is valid (if so the returned list will be empty).
:: URISchemaMap Schema | |
-> [(Text, Failure)] | The first value in the tuple is the URI of a referenced schema. |
Check that a set of referenced schemas are valid (if so the returned list will be empty).
checkSchema :: URISchemaMap Schema -> SchemaWithURI Schema -> Either InvalidSchema (Value -> [Failure]) Source #
A helper function.
Checks if a schema and a set of referenced schemas are valid.
Return a function to validate data.