Copyright | (c) 2015 GetShopTV |
---|---|
License | BSD3 |
Maintainer | Nickolay Kudasov <nickolay@getshoptv.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Validate JSON values with Swagger Schema.
- 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 {}
- 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] Source #
Validate
instance matches ToJSON
for a given value.
This can be used with QuickCheck to ensure those instances are coherent:ToSchema
validateToJSON (x :: Int) == []
NOTE:
does not perform string pattern validation.
See validateToJSON
.validateToJSONWithPatternChecker
validateToJSONWithPatternChecker :: forall a. (ToJSON a, ToSchema a) => (Pattern -> Text -> Bool) -> a -> [ValidationError] Source #
Validate
instance matches ToJSON
for a given value and pattern checker.
This can be used with QuickCheck to ensure those instances are coherent.ToSchema
For validation without patterns see
.validateToJSON
type ValidationError = String Source #
Validation error message.
Validation result type.
Failed [ValidationError] | Validation failed with a list of error messages. |
Passed a | Validation passed. |
Validation configuration.
Config | |
|
defaultConfig :: Config Source #
Default
:Config
defaultConfig =Config
{configPatternChecker
= \_pattern _str -> True ,configDefinitions
= mempty }
newtype Validation s a Source #
Value validation.
Validation | |
|
Profunctor Validation Source # | |
Choice Validation Source # | |
Monad (Validation s) Source # | |
Functor (Validation s) Source # | |
Applicative (Validation schema) Source # | |
Alternative (Validation schema) Source # | |
withConfig :: (Config -> Validation s a) -> Validation s a Source #
withSchema :: (s -> Validation s a) -> Validation s a Source #
invalid :: String -> Validation schema a Source #
Issue an error message.
valid :: Validation schema () Source #
Validation passed.
check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s () Source #
Validate schema's property given a lens into that property and property checker.
sub :: t -> Validation t a -> Validation s a Source #
Validate same value with different schema.
sub_ :: Getting a s a -> Validation a r -> Validation s r Source #
Validate same value with a part of the original schema.
withRef :: Reference -> (Schema -> Validation s a) -> Validation s a Source #
Validate value against a schema given schema reference and validation function.
validateWithSchemaRef :: Referenced Schema -> Value -> Validation s () Source #
validateWithSchema :: Value -> Validation Schema () Source #
validateWithParamSchema :: Value -> Validation (ParamSchema t) () Source #
Validate JSON
with Swagger Value
.ParamSchema
validateInteger :: Scientific -> Validation (ParamSchema t) () Source #
validateNumber :: Scientific -> Validation (ParamSchema t) () Source #
validateString :: Text -> Validation (ParamSchema t) () Source #
validateArray :: Vector Value -> Validation (ParamSchema t) () Source #
validateObject :: HashMap Text Value -> Validation Schema () Source #
validateEnum :: Value -> Validation (ParamSchema t) () Source #
validateSchemaType :: Value -> Validation Schema () Source #
validateParamSchemaType :: Value -> Validation (ParamSchema t) () Source #