swagger2-2.1.4.1: Swagger 2.0 data model

Copyright | (c) 2015 GetShopTV
License | BSD3
Maintainer | Nickolay Kudasov <nickolay@getshoptv.com>
Stability | experimental
Safe Haskell | None
Language | Haskell2010

Data.Swagger.Internal.Schema.Validation

Description

Validate JSON values with Swagger Schema.

Synopsis

- validateToJSON :: forall a. (ToJSON a, ToSchema a) => a -> [ValidationError]
- validateToJSONWithPatternChecker :: forall a. (ToJSON a, ToSchema a) => (Pattern -> Text -> Bool) -> a -> [ValidationError]
- type ValidationError = String
- data Result a
  - = Failed [ValidationError]
  - | Passed a
- data Config = Config {
  - configPatternChecker :: Pattern -> Text -> Bool
  - configDefinitions :: Definitions Schema
  }
- defaultConfig :: Config
- newtype Validation s a = Validation {
  - runValidation :: Config -> s -> Result a
  }
- withConfig :: (Config -> Validation s a) -> Validation s a
- withSchema :: (s -> Validation s a) -> Validation s a
- invalid :: String -> Validation schema a
- valid :: Validation schema ()
- check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
- sub :: t -> Validation t a -> Validation s a
- sub_ :: Getting a s a -> Validation a r -> Validation s r
- withRef :: Reference -> (Schema -> Validation s a) -> Validation s a
- validateWithSchemaRef :: Referenced Schema -> Value -> Validation s ()
- validateWithSchema :: Value -> Validation Schema ()
- validateWithParamSchema :: Value -> Validation (ParamSchema t) ()
- validateInteger :: Scientific -> Validation (ParamSchema t) ()
- validateNumber :: Scientific -> Validation (ParamSchema t) ()
- validateString :: Text -> Validation (ParamSchema t) ()
- validateArray :: Vector Value -> Validation (ParamSchema t) ()
- validateObject :: HashMap Text Value -> Validation Schema ()
- validateEnum :: Value -> Validation (ParamSchema t) ()
- validateSchemaType :: Value -> Validation Schema ()
- validateParamSchemaType :: Value -> Validation (ParamSchema t) ()

# Documentation

validateToJSON :: forall a. (ToJSON a, ToSchema a) => a -> [ValidationError] #

Validate ``ToJSON`` instance matches ``ToSchema`` for a given value. This can be used with QuickCheck to ensure those instances are coherent:

    validateToJSON (x :: Int) == []

NOTE: ``validateToJSON`` does not perform string pattern validation. See ``validateToJSONWithPatternChecker``.

validateToJSONWithPatternChecker :: forall a. (ToJSON a, ToSchema a) => (Pattern -> Text -> Bool) -> a -> [ValidationError] #

Validate ``ToJSON`` instance matches ``ToSchema`` for a given value and pattern checker. This can be used with QuickCheck to ensure those instances are coherent.

For validation without patterns see ``validateToJSON``.

type ValidationError = String #

Validation error message.

data Result a #

Validation result type.

Constructors

Failed [ValidationError] | Validation failed with a list of error messages.
Passed a | Validation passed.

Instances

Monad Result # |
Methods (>>=) :: Result a -> (a -> Result b) -> Result b # (>>) :: Result a -> Result b -> Result b # return :: a -> Result a # fail :: String -> Result a #
Functor Result # |
Methods fmap :: (a -> b) -> Result a -> Result b # (<$) :: a -> Result b -> Result a #
Applicative Result # |
Methods pure :: a -> Result a # (<*>) :: Result (a -> b) -> Result a -> Result b # (*>) :: Result a -> Result b -> Result b # (<*) :: Result a -> Result b -> Result a #
Alternative Result # |
Methods empty :: Result a # (<|>) :: Result a -> Result a -> Result a # some :: Result a -> Result [a] # many :: Result a -> Result [a] #
Eq a => Eq (Result a) # |
Methods (==) :: Result a -> Result a -> Bool # (/=) :: Result a -> Result a -> Bool #
Show a => Show (Result a) # |
Methods showsPrec :: Int -> Result a -> ShowS # show :: Result a -> String # showList :: [Result a] -> ShowS #

data Config #

Validation configuration.

Constructors

Config |
Fields configPatternChecker :: Pattern -> Text -> Bool Pattern checker for ``_paramSchemaPattern`` validation. configDefinitions :: Definitions Schema Schema definitions in scope to resolve references.

defaultConfig :: Config #

Default ``Config``:

    defaultConfig = Config
      { configPatternChecker = \_pattern _str -> True
      , configDefinitions    = mempty
      }

newtype Validation s a #

Value validation.

Constructors

Validation |
Fields runValidation :: Config -> s -> Result a

Instances

Profunctor Validation # |
Methods dimap :: (a -> b) -> (c -> d) -> Validation b c -> Validation a d # lmap :: (a -> b) -> Validation b c -> Validation a c # rmap :: (b -> c) -> Validation a b -> Validation a c # (#.) :: Coercible * c b => (b -> c) -> Validation a b -> Validation a c # (.#) :: Coercible * b a => Validation b c -> (a -> b) -> Validation a c #
Choice Validation # |
Methods left' :: Validation a b -> Validation (Either a c) (Either b c) # right' :: Validation a b -> Validation (Either c a) (Either c b) #
Monad (Validation s) # |
Methods (>>=) :: Validation s a -> (a -> Validation s b) -> Validation s b # (>>) :: Validation s a -> Validation s b -> Validation s b # return :: a -> Validation s a # fail :: String -> Validation s a #
Functor (Validation s) # |
Methods fmap :: (a -> b) -> Validation s a -> Validation s b # (<$) :: a -> Validation s b -> Validation s a #
Applicative (Validation schema) # |
Methods pure :: a -> Validation schema a # (<*>) :: Validation schema (a -> b) -> Validation schema a -> Validation schema b # (*>) :: Validation schema a -> Validation schema b -> Validation schema b # (<*) :: Validation schema a -> Validation schema b -> Validation schema a #
Alternative (Validation schema) # |
Methods empty :: Validation schema a # (<|>) :: Validation schema a -> Validation schema a -> Validation schema a # some :: Validation schema a -> Validation schema [a] # many :: Validation schema a -> Validation schema [a] #

withConfig :: (Config -> Validation s a) -> Validation s a #

withSchema :: (s -> Validation s a) -> Validation s a #

invalid :: String -> Validation schema a #

Issue an error message.

valid :: Validation schema () #

Validation passed.

check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s () #

Validate schema's property given a lens into that property and property checker.

sub :: t -> Validation t a -> Validation s a #

Validate same value with different schema.

sub_ :: Getting a s a -> Validation a r -> Validation s r #

Validate same value with a part of the original schema.

withRef :: Reference -> (Schema -> Validation s a) -> Validation s a #

Validate value against a schema given schema reference and validation function.

validateWithSchemaRef :: Referenced Schema -> Value -> Validation s () #

validateWithSchema :: Value -> Validation Schema () #

Validate JSON ``Value`` with Swagger ``Schema``.

validateWithParamSchema :: Value -> Validation (ParamSchema t) () #

Validate JSON ``Value`` with Swagger ``ParamSchema``.

validateInteger :: Scientific -> Validation (ParamSchema t) () #

validateNumber :: Scientific -> Validation (ParamSchema t) () #

validateString :: Text -> Validation (ParamSchema t) () #

validateArray :: Vector Value -> Validation (ParamSchema t) () #

validateObject :: HashMap Text Value -> Validation Schema () #

validateEnum :: Value -> Validation (ParamSchema t) () #

validateSchemaType :: Value -> Validation Schema () #

validateParamSchemaType :: Value -> Validation (ParamSchema t) () #