hjsonschema 0.5.1.2 → 0.5.1.3
raw patch · 4 files changed
+9/−43 lines, 4 filesdep ~aesondep ~basedep ~hjsonpointerPVP: minor bump suggested
API additions: PVP suggests at least a minor 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
Files
- Main.hs +0/−27
- hjsonschema.cabal +2/−14
- src/Data/JsonSchema/Helpers.hs +4/−0
- src/Data/JsonSchema/Validators.hs +3/−2
− Main.hs
@@ -1,27 +0,0 @@-{-# 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 =- 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."--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"])
hjsonschema.cabal view
@@ -1,5 +1,5 @@ name: hjsonschema-version: 0.5.1.2+version: 0.5.1.3 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.1 && < 0.2+ , hjsonpointer >= 0.2 && < 0.3 , http-conduit >= 2.1.5 && < 2.2 , http-types >= 0.8 && < 0.9 , regexpr >= 0.5 && < 0.6@@ -81,18 +81,6 @@ , 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- , vector- , unordered-containers source-repository head type: git
src/Data/JsonSchema/Helpers.hs view
@@ -124,6 +124,10 @@ -- * 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,8 +426,9 @@ ref spec g s (String val) = do (reference, pointer) <- refAndPointer (_rsURI s `combineIdAndRef` val) r <- RawSchema reference <$> H.lookup reference g- let p = decodeUtf8 . urlDecode True . encodeUtf8 $ pointer- case jsonPointer p >>= resolvePointer (Object $ _rsObject r) of+ let urlDecoded = decodeUtf8 . urlDecode True . encodeUtf8 $ pointer+ p <- eitherToMaybe $ jsonPointer urlDecoded+ case resolvePointer p (Object $ _rsObject r) of Right (Object o) -> Just $ validate $ compile spec g $ RawSchema (_rsURI r) o _ -> Nothing