Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- class Validation property on where
- data NotBlank = NotBlank
- newtype ValErrs = ValErrs [(Text, Text)]
- parseJsonBody :: forall a m. (MonadUnliftIO m, FromJSON a) => ActionT m a
- inErrMsgObj :: obj -> InObj obj
- (<?!<) :: Parser (Maybe (Assurance prop on)) -> prop -> Parser (Maybe on)
- (<!<) :: Parser (Assurance prop on) -> prop -> Parser on
Documentation
class Validation property on where Source #
A simple validation class using typeclass-metaprogramming (TMP) to help catch and generate Conduit-spec-abiding validation errors
Intended for use on Aeson Parsers (in manual FromJSON instances)
See also: NotBlank
(example), (<!<)
, and (<?!<)
data IsRed = IsRed instance Validation IsRed Text where validate = (== "red") errMsg = "must be red"
newtype Test = Test Text instance FromJSON Test where parseJSON = withObject "Test" $ \v -> Test <$> v .: "test" <!< IsRed <!< NotBlank -- assurances are evaluated R->L
>>>
eitherDecode @Test "{ \"test\": \"\" }"
Left "Error in $.test: can't be blank"
>>>
eitherDecode @Test "{ \"test\": \"abc\" }"
Left "Error in $.test: must be red"
Instances
A property ensuing that the given json field isn't blank (intended for String/Text-like objects).
Instances
parseJsonBody :: forall a m. (MonadUnliftIO m, FromJSON a) => ActionT m a Source #
Extracts and decodes an expected json body, intended for use with Validation
s.
Returns the appropriate unprocessable errors the Conduit spec expects.
newtype Test = Test Text deriving (Show) instance FromJSON Test where parseJSON = withObject "Test" $ \v -> Test <$> v .: "test" <!< NotBlank endpoint = post "/" $ do result <- parseJsonBody @Test print text
inErrMsgObj :: obj -> InObj obj Source #