-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A schema language for JSON. -- -- A reference implementation of a schema language, together with a -- conformance suite and a specification. @package medea @version 1.1.2 -- | This module contains the reference Haskell implementation of a Medea -- validator, providing both schema graph file loading and validation, -- with some convenience functions. -- -- A minimal example of use follows. This example first attempts to load -- a Medea schema graph file from /path/to/schema.medea, and, if -- successful, attempts to validate the JSON file at -- /path/to/my.json against the schemata so loaded. -- --
--   import Data.Medea (loadSchemaFromFile, validateFromFile)
--   import Control.Monad.Except (runExceptT)
--   
--   main :: IO ()
--   main = do
--     -- try to load the schema graph file
--     loaded <- runExceptT . loadSchemaFromFile $ "/path/to/schema.medea"
--     case loaded of
--        Left err -> print err -- or some other handling
--        Right scm -> do
--          -- try to validate
--          validated <- runExceptT . validateFromFile scm $ "/path/to/my.json"
--          case validated of
--            Left err -> print err -- or some other handling
--            Right validJson -> print validJson -- or some other useful thing
--   
-- -- For more details about how to create Medea schema graph files, see -- TUTORIAL.md and SPEC.md. module Data.Medea -- | A compiled Medea schema. data Schema -- | Possible errors from loading Medea schemata. data LoaderError -- | The data provided wasn't UTF-8. NotUtf8 :: LoaderError -- | Parsing failed. ParsingFailed :: !ParseErrorBundle Text ParseError -> LoaderError -- | No schema labelled $start was provided. StartSchemaMissing :: LoaderError -- | A schema was typed in terms of itself. SelfTypingSchema :: LoaderError -- | A schema was defined more than once. MultipleSchemaDefinition :: {-# UNPACK #-} !Text -> LoaderError -- | We expected a schema, but couldn't find it. MissingSchemaDefinition :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> LoaderError -- | A schema was named with a reserved identifier (other than -- start). SchemaNameReserved :: {-# UNPACK #-} !Text -> LoaderError -- | An isolated schema was found. IsolatedSchemata :: {-# UNPACK #-} !Text -> LoaderError -- | A property schema refers to a non-existent schema. MissingPropSchemaDefinition :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> LoaderError -- | A minimum length specification was more than its corresponding maximum -- length specification. MinimumLengthGreaterThanMaximum :: {-# UNPACK #-} !Text -> LoaderError -- | A property was specified more than once. MultiplePropSchemaDefinition :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> LoaderError -- | A list specification did not provide an element type. MissingListSchemaDefinition :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> LoaderError -- | A tuple specification does not provide a positional schema. MissingTupleSchemaDefinition :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> LoaderError -- | Schema had a property specification, but no $object type. PropertySpecWithoutObjectType :: {-# UNPACK #-} !Text -> LoaderError -- | Schema had a list specification, but no $array type. ListSpecWithoutArrayType :: {-# UNPACK #-} !Text -> LoaderError -- | Schema had a tuple specification, but no $array type. TupleSpecWithoutArrayType :: {-# UNPACK #-} !Text -> LoaderError -- | Schema had a string specification, but no $string type. StringSpecWithoutStringType :: {-# UNPACK #-} !Text -> LoaderError -- | All possible errors from the Medea parser. data ParseError -- | An identifier exceeded 32 bytes. IdentifierTooLong :: {-# UNPACK #-} !Text -> ParseError -- | We saw a non-reserved identifier where we wanted a reserved one. ExpectedReservedIdentifier :: {-# UNPACK #-} !Text -> ParseError -- | A Medea natural number had literal zeroes. LeadingZero :: {-# UNPACK #-} !Text -> ParseError -- | We were given incompatible requirements within a specification. ConflictingSpecRequirements :: ParseError -- | We were not given a length in an array specification. EmptyLengthArraySpec :: ParseError -- | We were not given an element specification in an array specification. EmptyArrayElements :: ParseError -- | We were given no string values in a string specification. EmptyStringValuesSpec :: ParseError -- | Attempt to produce a schema from UTF-8 data in memory. buildSchema :: MonadError LoaderError m => ByteString -> m Schema -- | Parse and process a Medea schema graph file. loadSchemaFromFile :: (MonadIO m, MonadError LoaderError m) => FilePath -> m Schema -- | Load data corresponding to a Medea schema graph file from a -- Handle. loadSchemaFromHandle :: (MonadIO m, MonadError LoaderError m) => Handle -> m Schema -- | The basic types of JSON value (as per ECMA-404). data JSONType JSONNull :: JSONType JSONBoolean :: JSONType JSONNumber :: JSONType JSONString :: JSONType JSONArray :: JSONType JSONObject :: JSONType -- | An annotation, describing which schema a given chunk of JSON was -- deemed to be valid against. data SchemaInformation -- | No requirements were placed on this chunk. AnySchema :: SchemaInformation -- | Validated as JSON null. NullSchema :: SchemaInformation -- | Validated as JSON boolean. BooleanSchema :: SchemaInformation -- | Validated as JSON number. NumberSchema :: SchemaInformation -- | Validated as JSON string. StringSchema :: SchemaInformation -- | Validated as JSON array. ArraySchema :: SchemaInformation -- | Validated as JSON object. ObjectSchema :: SchemaInformation -- | Validated against the start schema. StartSchema :: SchemaInformation -- | Validated against the schema with the given name. UserDefined :: {-# UNPACK #-} !Text -> SchemaInformation -- | All possible validation errors. data ValidationError EmptyError :: ValidationError -- | We could not parse JSON out of what we were provided. NotJSON :: ValidationError -- | We got a type different to what we expected. WrongType :: !Value -> !JSONType -> ValidationError -- | We expected one of several possibilities, but got something that fits -- none. NotOneOfOptions :: !Value -> ValidationError -- | We found a JSON object with a property that wasn't specified in its -- schema, and additional properties are forbidden. AdditionalPropFoundButBanned :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> ValidationError -- | We found a JSON object which is missing a property its schema -- requires. RequiredPropertyIsMissing :: {-# UNPACK #-} !Text -> {-# UNPACK #-} !Text -> ValidationError -- | We found a JSON array which falls outside of the minimum or maximum -- length constraints its corresponding schema demands. OutOfBoundsArrayLength :: {-# UNPACK #-} !Text -> !Value -> ValidationError -- | This is a bug - please report it to us! ImplementationError :: {-# UNPACK #-} !Text -> ValidationError -- | JSON, annotated with what schemata it was deemed valid against. data ValidatedJSON -- | Convert to an Aeson Value, throwing away all schema -- information. toValue :: ValidatedJSON -> Value -- | What schema did this validate against? validAgainst :: ValidatedJSON -> SchemaInformation -- | Attempt to construct validated JSON from a bytestring. This will -- attempt to decode using Aeson before validating. validate :: (MonadPlus m, MonadError ValidationError m) => Schema -> ByteString -> m ValidatedJSON -- | Helper for construction of validated JSON from a JSON file. This will -- attempt to decode using Aeson before validating. validateFromFile :: (MonadPlus m, MonadError ValidationError m, MonadIO m) => Schema -> FilePath -> m ValidatedJSON -- | Helper for construction of validated JSON from a Handle. This -- will set the argument Handle to binary mode, as this function -- won't work otherwise. This function will close the Handle once -- it finds EOF. This will attempt to decode using Aeson before -- validating. validateFromHandle :: (MonadPlus m, MonadError ValidationError m, MonadIO m) => Schema -> Handle -> m ValidatedJSON instance Control.DeepSeq.NFData Data.Medea.SchemaInformation instance Data.Hashable.Class.Hashable Data.Medea.SchemaInformation instance GHC.Generics.Generic Data.Medea.SchemaInformation instance GHC.Show.Show Data.Medea.SchemaInformation instance Data.Data.Data Data.Medea.SchemaInformation instance GHC.Classes.Eq Data.Medea.SchemaInformation instance GHC.Show.Show Data.Medea.ValidatedJSON instance GHC.Classes.Eq Data.Medea.ValidatedJSON instance Data.Data.Data Data.Medea.ValidatedJSON instance Data.Hashable.Class.Hashable Data.Medea.ValidationError instance GHC.Generics.Generic Data.Medea.ValidationError instance GHC.Show.Show Data.Medea.ValidationError instance GHC.Classes.Eq Data.Medea.ValidationError instance GHC.Base.Semigroup Data.Medea.ValidationError instance GHC.Base.Monoid Data.Medea.ValidationError instance Control.DeepSeq.NFData Data.Medea.ValidatedJSON instance Data.Hashable.Class.Hashable Data.Medea.ValidatedJSON