forked from seagreen/hjsonschema
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.hs
More file actions
35 lines (29 loc) · 1.14 KB
/
Types.hs
File metadata and controls
35 lines (29 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module JSONSchema.Types where
import Import
import JSONSchema.Validator.Types (Validator(..))
newtype Spec schema err
= Spec { _unSpec :: [Validator schema schema err] }
-- | Return a schema's immediate subschemas.
--
-- The first list is subschemas validating the same level of the document,
-- the second list is subschemas validating lower levels (see
-- 'JSONSchema.Validator.Types.Fail' for a full explanation).
embedded :: Spec schema a -> schema -> ([schema], [schema])
embedded spec schema =
let embeds = (\val -> _embedded val schema) <$> _unSpec spec
in foldl' (\(a,b) (x,y) -> (x <> a, y <> b)) (mempty, mempty) embeds
validate
:: Spec schema err
-> schema
-> Value
-> [err]
validate spec schema v =
(\val -> _validate val schema v) =<< _unSpec spec
-- | A basic schema type that doesn't impose much structure.
--
-- 'JSONSchema.Draft4' doesn't use this, but instead uses the record based
-- one defined in 'JSONSchema.Draft4.Schema' to make it easier to write
-- draft 4 schemas in Haskell.
newtype Schema
= Schema { _unSchema :: HashMap Text Value }
deriving (Eq, Show, FromJSON, ToJSON)