git.iko.soy/typeable/hjsonschema
on 2baee34 help sign in
4 files changed+18−40
since splitsnapshots
unifiedsplit
.travis.yml+3 changelog.md−6 hjsonschema.cabal+7−2 src/JSONSchema/Validator/Draft4/Any.hs+8−32
.travis.yml+3
@@ -26,6 +26,9 @@ before_cache:
2626
2727matrix:
2828 include:
29+ - compiler: "ghc-7.10.3"
30+ # env: TEST=--disable-tests BENCH=--disable-benchmarks
31+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
2932 - compiler: "ghc-8.0.2"
3033 # env: TEST=--disable-tests BENCH=--disable-benchmarks
3134 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
changelog.md−6
@@ -1,11 +1,5 @@
11# 1.8.0
22
3−+ Add GHC 8.4 support (thanks @4e6 !).
4−+ Drop GHC 7.10 support.
5−+ Fix JSON Pointer resolution error.
6−
7−# 1.8.0
8−
93+ Allow HTTPS references (thanks @creichert!).
104+ Use `safe-exceptions` to eliminate the risk of catching asynchronous exceptions.
115
hjsonschema.cabal+7−2
@@ -1,5 +1,5 @@
11name: hjsonschema
2−version: 1.9.0
2+version: 1.8.0
33synopsis: JSON Schema library
44homepage: https://github.com/seagreen/hjsonschema
55license: MIT
@@ -10,7 +10,7 @@ category: Data
1010build-type: Simple
1111cabal-version: >=1.10
1212-- Rerun multi-ghc-travis (executable make-travis-yml-2) after changing:
13−Tested-With: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1
13+Tested-With: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1
1414extra-source-files:
1515 changelog.md
1616 JSON-Schema-Test-Suite/remotes/*.json
@@ -77,9 +77,12 @@ library
7777 , QuickCheck >= 2.8
7878 , safe-exceptions >= 0.1.6
7979 , scientific >= 0.3
80+ , semigroups >= 0.18
8081 , unordered-containers >= 0.2
8182 , text >= 1.1
8283 , vector >= 0.10
84+ if impl(ghc < 8.0)
85+ build-depends: semigroups == 0.18.*
8386
8487test-suite local
8588 hs-source-dirs:
@@ -114,6 +117,7 @@ test-suite local
114117 , hjsonschema
115118 , profunctors
116119 , protolude
120+ , semigroups
117121 , text
118122 , QuickCheck
119123 , unordered-containers
@@ -152,6 +156,7 @@ test-suite remote
152156 , hjsonschema
153157 , profunctors
154158 , protolude
159+ , semigroups
155160 , text
156161 , unordered-containers
157162 , vector
src/JSONSchema/Validator/Draft4/Any.hs+8−32
@@ -4,7 +4,6 @@ import Import hiding ((<>))
44
55import Data.Aeson.TH (constructorTagModifier)
66import Data.Char (toLower)
7−import qualified Data.HashMap.Strict as HM
87import Data.List.NonEmpty (NonEmpty((:|)))
98import qualified Data.List.NonEmpty as NE
109import qualified Data.Scientific as SCI
@@ -134,7 +133,7 @@ data JSONPointerError
134133 deriving (Eq, Show)
135134
136135resolveFragment
137− :: (FromJSON schema, ToJSON schema)
136+ :: forall schema. (FromJSON schema, ToJSON schema)
138137 => (BaseURI -> schema -> BaseURI)
139138 -> Scope schema
140139 -> Text
@@ -159,40 +158,17 @@ resolveFragment updateScope scope fragment = do
159158 -- as property keys that aren't meant to change scope?
160159 -- Perhaps this should be added to the language agnostic
161160 -- test suite as well.
162− --
163− -- In the meantime 'newBaseURIFromFragment' drops all keys
164− -- from JSON objects except "id", which at least prevents
165− -- SubschemaDecodingError in a situation where one of the
166− -- values we step through isn't a valid schema.
167161 go :: (Value, BaseURI)
168162 -> JP.Token
169163 -> Either JSONPointerError (Value, BaseURI)
170− go (lastVal, baseURI) tok = do
164+ go (lastVal, uri) tok = do
171165 v <- first ResolutionError (JP.resolveToken tok lastVal)
172− newBase <- newBaseURIFromFragment updateScope baseURI v
173− Right (v, newBase)
174−
175−-- | Update the 'BaseURI' (the store of the current "id" value)
176−-- after resolving one token of a JSON Pointer and stepping into
177−-- a new 'Value'.
178−newBaseURIFromFragment
179− :: FromJSON schema
180− => (BaseURI -> schema -> BaseURI)
181− -> BaseURI
182− -> Value
183− -> Either JSONPointerError BaseURI
184−newBaseURIFromFragment updateScope baseURI v =
185− case v of
186− Object hm -> do
187− let hmWithOnlyId = case HM.lookup idKey hm of
188− Nothing -> mempty
189− Just idVal -> HM.singleton idKey idVal
190− schema <- first SubschemaDecodingError (fromJSONEither (Object hmWithOnlyId))
191− Right (updateScope baseURI schema)
192− _ -> Right baseURI
193− where
194− idKey :: Text
195− idKey = "id"
166+ case v of
167+ Array _ -> pure (v, uri)
168+ _ -> do
169+ -- PERFORMANCE: Avoid deserializing subschemas.
170+ schema <- first SubschemaDecodingError (fromJSONEither v)
171+ pure (v, updateScope uri schema)
196172
197173--------------------------------------------------
198174-- * enum