Safe Haskell | None |
---|---|
Language | Haskell2010 |
- 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
- data HTTPValidationFailure
- fetchHTTPAndValidate :: SchemaWithURI Schema -> Value -> IO (Either HTTPValidationFailure ())
- data FilesystemValidationFailure
- fetchFilesystemAndValidate :: SchemaWithURI Schema -> Value -> IO (Either FilesystemValidationFailure ())
- data SchemaWithURI schema = SchemaWithURI {}
- data ReferencedSchemas schema = ReferencedSchemas {
- _rsStarting :: !schema
- _rsSchemaMap :: !(URISchemaMap schema)
- data HTTPFailure
- referencesViaHTTP :: SchemaWithURI Schema -> IO (Either HTTPFailure (ReferencedSchemas Schema))
- data FilesystemFailure
- referencesViaFilesystem :: SchemaWithURI Schema -> IO (Either FilesystemFailure (ReferencedSchemas Schema))
- type Invalid = Failure ValidatorChain
- data Failure err = Invalid {}
- 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
- | Ref ValidatorChain
- | Enum
- | TypeValidator
- | AllOf ValidatorChain
- | AnyOf
- | OneOf
- | NotValidator
- checkSchema :: ReferencedSchemas Schema -> SchemaWithURI Schema -> Either (NonEmpty Invalid) (Value -> [Invalid])
- schemaValidity :: Schema -> [Invalid]
- runValidate :: ReferencedSchemas Schema -> SchemaWithURI Schema -> Value -> [Invalid]
- draft4Spec :: Spec Schema
Documentation
One-step validation
fetchHTTPAndValidate :: SchemaWithURI Schema -> Value -> IO (Either HTTPValidationFailure ()) Source
fetchFilesystemAndValidate :: SchemaWithURI Schema -> Value -> IO (Either FilesystemValidationFailure ()) Source
Fetching tools
data SchemaWithURI schema Source
SchemaWithURI | |
|
Eq schema => Eq (SchemaWithURI schema) Source | |
Show schema => Show (SchemaWithURI schema) Source |
data ReferencedSchemas schema Source
ReferencedSchemas | |
|
Eq schema => Eq (ReferencedSchemas schema) Source | |
Show schema => Show (ReferencedSchemas schema) Source |
data HTTPFailure Source
referencesViaHTTP :: SchemaWithURI Schema -> IO (Either HTTPFailure (ReferencedSchemas Schema)) Source
data FilesystemFailure Source
referencesViaFilesystem :: SchemaWithURI Schema -> IO (Either FilesystemFailure (ReferencedSchemas Schema)) Source
Failure
type Invalid = Failure 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).
Thus validators that can only fail in one way return FailureInfo
s.
Validators that can fail in multiple ways return ValidationFailure
s
along with an custom error sum type for that particular validator.
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 ValidationFailure
with
that sum type as its type argument.
data ValidatorChain Source
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. |
Ref ValidatorChain | |
Enum | |
TypeValidator | |
AllOf ValidatorChain | |
AnyOf | |
OneOf | |
NotValidator |
Other Draft 4 things exported just in case
checkSchema :: ReferencedSchemas Schema -> SchemaWithURI Schema -> Either (NonEmpty Invalid) (Value -> [Invalid]) Source
Check the that a schema itself is valid.
Return a function to validate data.
schemaValidity :: Schema -> [Invalid] Source
Check that a schema itself is valid.
runValidate :: ReferencedSchemas Schema -> SchemaWithURI Schema -> Value -> [Invalid] Source