git.iko.soy/typeable/hjsonschema
on master help sign in
35 lines 1.2 kB history raw
1module JSONSchema.Types where
3import Import
5import JSONSchema.Validator.Types (Validator(..))
7newtype Spec schema err
8 = Spec { _unSpec :: [Validator schema schema err] }
10-- | Return a schema's immediate subschemas.
11--
12-- The first list is subschemas validating the same level of the document,
13-- the second list is subschemas validating lower levels (see
14-- 'JSONSchema.Validator.Types.Fail' for a full explanation).
15embedded :: Spec schema a -> schema -> ([schema], [schema])
16embedded spec schema =
17 let embeds = (\val -> _embedded val schema) <$> _unSpec spec
18 in foldl' (\(a,b) (x,y) -> (x <> a, y <> b)) (mempty, mempty) embeds
20validate
21 :: Spec schema err
22 -> schema
23 -> Value
24 -> [err]
25validate spec schema v =
26 (\val -> _validate val schema v) =<< _unSpec spec
28-- | A basic schema type that doesn't impose much structure.
29--
30-- 'JSONSchema.Draft4' doesn't use this, but instead uses the record based
31-- one defined in 'JSONSchema.Draft4.Schema' to make it easier to write
32-- draft 4 schemas in Haskell.
33newtype Schema
34 = Schema { _unSchema :: HashMap Text Value }
35 deriving (Eq, Show, FromJSON, ToJSON)