@@ -60,6 +60,10 @@ draft4 = Spec $ H.fromList
6060--
6161-- This is just a convenience function built by preloading 'validate'
6262-- with the spec schema that describes valid Draft 4 schemas.
63+--
64+-- NOTE: It's not actually required to run 'isValidSchema' on
65+-- prospective draft 4 schemas at all. However, it's a good way to
66+-- catch unintentional mistakes in schema documents.
6367isValidSchema :: RawSchema -> Vector ValErr
6468isValidSchema r =
6569 case decode . fromStrict $ $(embedFile "draft4.json") of
@@ -70,6 +74,18 @@ isValidSchema r =
7074 (compile draft4 H.empty draft4Schema)
7175 (Object . _rsObject $ r)
7276
77+-- | Check that a 'RawSchema' conforms to the JSON Schema Draft 4
78+-- master schema document. Compile it if it does.
79+--
80+-- This is just a convenience function built by combining
81+-- 'isValidSchema' and 'compile'.
82+compileDraft4 :: Graph -> RawSchema -> Either (Vector ValErr) Schema
83+compileDraft4 g r =
84+ let es = isValidSchema r
85+ in case V.length es of
86+ 0 -> Right $ compile draft4 g r
87+ _ -> Left es
88+
7389--------------------------------------------------
7490-- * Graph Builder
7591--------------------------------------------------