packages feed

hjsonschema 0.5.1.3 → 0.5.2.0

raw patch · 6 files changed

+67/−17 lines, 6 filesdep ~aesondep ~basedep ~hjsonpointernew-component:exe:mainPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: aeson, base, hjsonpointer, unordered-containers, vector

API changes (from Hackage documentation)

- Data.JsonSchema.Helpers: eitherToMaybe :: Either a b -> Maybe b
+ Data.JsonSchema: compileDraft4 :: Graph -> RawSchema -> Either (Vector ValErr) Schema

Files

+ Main.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import Data.Aeson+import qualified Data.HashMap.Strict as H+import qualified Data.JsonSchema as JS+import qualified Data.Vector as V++main :: IO ()+main = do+  eitherGraph <- JS.fetchRefs JS.draft4 rawSchema H.empty+  case eitherGraph of+    Left e  -> print e+    Right g ->+      case JS.compileDraft4 g rawSchema of+        Left e2 -> print e2+        Right a -> print $ JS.validate a invalidData++rawSchema :: JS.RawSchema+rawSchema = JS.RawSchema+  { JS._rsURI = ""+  , JS._rsObject = H.singleton "uniqueItems" (Bool True) -- Schema JSON goes here.+  }++invalidData :: Value+invalidData = Array (V.fromList ["foo", "foo"])
README.md view
@@ -19,14 +19,14 @@ import qualified Data.Vector as V  main :: IO ()-main =-  case V.length (JS.isValidSchema rawSchema) of-    0 -> do-      eitherGraph <- JS.fetchRefs JS.draft4 rawSchema H.empty-      case eitherGraph of-        Left e  -> print e-        Right g -> print $ JS.validate (JS.compile JS.draft4 g $ rawSchema) invalidData-    _ -> putStrLn "The schema you tried to use doesn't follow the draft 4 layout."+main = do+  eitherGraph <- JS.fetchRefs JS.draft4 rawSchema H.empty+  case eitherGraph of+    Left e  -> print e+    Right g ->+      case JS.compileDraft4 g rawSchema of+        Left e2 -> print e2+        Right a -> print $ JS.validate a invalidData  rawSchema :: JS.RawSchema rawSchema = JS.RawSchema
hjsonschema.cabal view
@@ -1,5 +1,5 @@ name:                   hjsonschema-version:                0.5.1.3+version:                0.5.2.0 synopsis:               JSON Schema Draft 4 library homepage:               https://github.com/seagreen/hjsonschema license:                MIT@@ -31,7 +31,7 @@                       , bytestring           >= 0.10  && < 0.11                       , file-embed           >= 0.0.8 && < 0.0.9                       , hashable             >= 1.2   && < 1.3-                      , hjsonpointer         >= 0.2   && < 0.3+                      , hjsonpointer         >= 0.1   && < 0.2                       , http-conduit         >= 2.1.5 && < 2.2                       , http-types           >= 0.8   && < 0.9                       , regexpr              >= 0.5   && < 0.6@@ -81,6 +81,18 @@                       , HUnit                >= 1.2 && < 1.3                       , test-framework       >= 0.8 && < 0.9                       , test-framework-hunit >= 0.3 && < 0.4++executable main+  main-is:            Main.hs+  default-language:   Haskell2010+  ghc-options:        -Wall+  other-extensions:   OverloadedStrings++  build-depends:      aeson+                    , base+                    , hjsonschema+                    , unordered-containers+                    , vector  source-repository head   type:               git
src/Data/JsonSchema.hs view
@@ -60,6 +60,10 @@ -- -- This is just a convenience function built by preloading 'validate' -- with the spec schema that describes valid Draft 4 schemas.+--+-- NOTE: It's not actually required to run 'isValidSchema' on+-- prospective draft 4 schemas at all. However, it's a good way to+-- catch unintentional mistakes in schema documents. isValidSchema :: RawSchema -> Vector ValErr isValidSchema r =   case decode . fromStrict $ $(embedFile "draft4.json") of@@ -69,6 +73,18 @@       validate         (compile draft4 H.empty draft4Schema)         (Object . _rsObject $ r)++-- | Check that a 'RawSchema' conforms to the JSON Schema Draft 4+-- master schema document. Compile it if it does.+--+-- This is just a convenience function built by combining+-- 'isValidSchema' and 'compile'.+compileDraft4 :: Graph -> RawSchema -> Either (Vector ValErr) Schema+compileDraft4 g r =+  let es = isValidSchema r+  in case V.length es of+    0 -> Right $ compile draft4 g r+    _ -> Left es  -------------------------------------------------- -- * Graph Builder
src/Data/JsonSchema/Helpers.hs view
@@ -124,10 +124,6 @@ -- * Utils -------------------------------------------------- -eitherToMaybe :: Either a b -> Maybe b-eitherToMaybe (Left _)  = Nothing-eitherToMaybe (Right a) = Just a- vectorOfElems :: HashMap k a -> Vector a vectorOfElems = V.fromList . H.elems 
src/Data/JsonSchema/Validators.hs view
@@ -426,9 +426,8 @@ ref spec g s (String val) = do   (reference, pointer) <- refAndPointer (_rsURI s `combineIdAndRef` val)   r <- RawSchema reference <$> H.lookup reference g-  let urlDecoded = decodeUtf8 . urlDecode True . encodeUtf8 $ pointer-  p <- eitherToMaybe $ jsonPointer urlDecoded-  case resolvePointer p (Object $ _rsObject r) of+  let p = decodeUtf8 . urlDecode True . encodeUtf8 $ pointer+  case jsonPointer p >>= resolvePointer (Object $ _rsObject r) of     Right (Object o) ->       Just $ validate $ compile spec g $ RawSchema (_rsURI r) o     _                -> Nothing