1-- | Two differences from @examples/Simple.hs@:
3-- * This shows how to write the starting schema in Haskell instead
4-- of parsing it from JSON.
6-- * Validation is done in two steps using 'D4.referencesViaFilesystem' and
7-- 'D4.checkSchema' instead of 'D4.fetchFilesystemAndValidate'. This means
8-- that the actual validation involves no IO.
12import Data.Aeson (Value (..), toJSON)
14import qualified Data.JsonSchema.Draft4 as D4
17schema = D4.emptySchema { D4._schemaRef = Just "./unique.json" }
19schemaContext :: D4.SchemaWithURI D4.Schema
20schemaContext = D4.SchemaWithURI
21 { D4._swSchema = schema
22 , D4._swURI = Just "./examples/json/start.json"
26badData = toJSON (["foo", "foo"] :: [String])
30 res <- D4.referencesViaFilesystem schemaContext
31 let references = case res of
32 Left _ -> error "Couldn't fetch referenced schemas."
34 validate = case D4.checkSchema references schemaContext of
35 Left _ -> error "Not a valid schema."
37 case validate badData of
38 [] -> error "We validated bad data."
39 [D4.Failure (D4.Ref D4.UniqueItems) _ _ _] -> return () -- Success
40 _ -> error "We got a different failure than expected."
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list