git.iko.soy/typeable/hjsonschema
on c0ef770 help sign in
.travis.yml+5−5
since splitsnapshots
unifiedsplit
@@ -26,15 +26,15 @@ before_cache:
26
26
27matrix:
27matrix:
28 include:
28 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]}}
29 - compiler: "ghc-8.0.2"
32 - compiler: "ghc-8.0.2"
30 # env: TEST=--disable-tests BENCH=--disable-benchmarks
33 # env: TEST=--disable-tests BENCH=--disable-benchmarks
31 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
34 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
32− - compiler: "ghc-8.2.2"
35+ - compiler: "ghc-8.2.1"
33− # env: TEST=--disable-tests BENCH=--disable-benchmarks
34− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}
35− - compiler: "ghc-8.4.1"
36 # env: TEST=--disable-tests BENCH=--disable-benchmarks
36 # env: TEST=--disable-tests BENCH=--disable-benchmarks
37− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.4.1], sources: [hvr-ghc]}}
37+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.1], sources: [hvr-ghc]}}
38
38
39before_install:
39before_install:
40 - HC=${CC}
40 - HC=${CC}
README.md+20−8
@@ -1,12 +1,6 @@
1−# DEPRECATION NOTICE
1+# Summary
2
2
3−`hjsonschema` was an attempt to build a very modular JSON Schema library. Validators have [a concrete type](src/JSONSchema/Validator/Types.hs) and can be mixed and matched into new [Specs](src/JSONSchema/Types.hs).
3+A Haskell implementation of [JSON Schema](http://json-schema.org/) ([Draft 4](http://json-schema.org/specification-links.html)).
4−
5−However this flexibility came at the price of complicating the code. I don't think it was the right tradeoff, especially since situations where you'd want to change what validators make up a `Spec` at runtime seem rare.
6−
7−Also, there are many parts of JSON Schema that `hjsonschema` doesn't implement properly (as you can see from the issue tracker). I'm hoping that a new JSON Schema library will come along that handles these correctly. In the meantime I'm happy to merge working fixes into here.
8−
9−# Links
10
4
11[Hackage](https://hackage.haskell.org/package/hjsonschema) / [GitHub](https://github.com/seagreen/hjsonschema) / [Travis CI](https://travis-ci.org/seagreen/hjsonschema)
5[Hackage](https://hackage.haskell.org/package/hjsonschema) / [GitHub](https://github.com/seagreen/hjsonschema) / [Travis CI](https://travis-ci.org/seagreen/hjsonschema)
12
6
@@ -14,12 +8,30 @@ Also, there are many parts of JSON Schema that `hjsonschema` doesn't implement p
14
8
15See [here](https://github.com/seagreen/hjsonschema/blob/master/examples/Simple.hs).
9See [here](https://github.com/seagreen/hjsonschema/blob/master/examples/Simple.hs).
16
10
11+# Design
12+
13+`hjsonschema` was an attempt to build a very modular JSON Schema library. Validators have [a concrete type](src/JSONSchema/Validator/Types.hs) and can be mixed and matched into new [Specs](src/JSONSchema/Types.hs).
14+
15+However this flexibility comes at the price of complicating the code. I'm no longer sure it was the right tradeoff, especially since situations where you'd want to change what validators make up a `Spec` at runtime seem rare.
16+
17+Also, there are edge cases of JSON Schema that `hjsonschema` doesn't implement properly (as you can see from the issue tracker). My motivation to fix them myself has ended. However, I'll still maintain the library, give feedback on issues, and merge PRs. I'd also be happy to advise any Haskellers who are interested in writing their own JSON Schema libraries.
18+
17# System dependencies
19# System dependencies
18
20
19+ Requires [pcre](http://www.pcre.org/) (`pkgs.pcre` in Nixpkgs).
21+ Requires [pcre](http://www.pcre.org/) (`pkgs.pcre` in Nixpkgs).
20
22
23+# Tests
24+
25+Run all: `stack test`
26+
27+Run only local tests: `stack test hjsonschema:local`
28+
29+Run only remote tests (temporarily starts an HTTP server on port 1234 and makes GETs to json-schema.org): `stack test hjsonschema:remote`
30+
21## Vendoring
31## Vendoring
22
32
23+ `JSON-Schema-Test-Suite` is vendored from commit # c1b12bf699f29a04b4286711c6e3bbfba66f21e5 [here](https://github.com/json-schema-org/JSON-Schema-Test-Suite).
33+ `JSON-Schema-Test-Suite` is vendored from commit # c1b12bf699f29a04b4286711c6e3bbfba66f21e5 [here](https://github.com/json-schema-org/JSON-Schema-Test-Suite).
24
34
25+ `src/draft4.json` is from commit # c1b12bf699f29a04b4286711c6e3bbfba66f21e5 [here](https://github.com/json-schema/json-schema). The [root ref in remote ref](./JSON-Schema-Test-Suite/tests/draft4/refRemote.json) test has been modified to fix [#175](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/175).
35+ `src/draft4.json` is from commit # c1b12bf699f29a04b4286711c6e3bbfba66f21e5 [here](https://github.com/json-schema/json-schema). The [root ref in remote ref](./JSON-Schema-Test-Suite/tests/draft4/refRemote.json) test has been modified to fix [#175](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/175).
36+
37++ `.travis.yml` was created with `make_travis_yml_2.hs` commit # ea6c7d177a97bfbfb2fdc4deba943d60d2aff199.
changelog.md−6
@@ -1,11 +1,5 @@
1# 1.8.0
1# 1.8.0
2
2
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−
9+ Allow HTTPS references (thanks @creichert!).
3+ Allow HTTPS references (thanks @creichert!).
10+ Use `safe-exceptions` to eliminate the risk of catching asynchronous exceptions.
4+ Use `safe-exceptions` to eliminate the risk of catching asynchronous exceptions.
11
5
hjsonschema.cabal+5−2
@@ -1,5 +1,5 @@
1name: hjsonschema
1name: hjsonschema
2−version: 1.9.0
2+version: 1.8.0
3synopsis: JSON Schema library
3synopsis: JSON Schema library
4homepage: https://github.com/seagreen/hjsonschema
4homepage: https://github.com/seagreen/hjsonschema
5license: MIT
5license: MIT
@@ -10,7 +10,7 @@ category: Data
10build-type: Simple
10build-type: Simple
11cabal-version: >=1.10
11cabal-version: >=1.10
12-- Rerun multi-ghc-travis (executable make-travis-yml-2) after changing:
12-- 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.1
14extra-source-files:
14extra-source-files:
15 changelog.md
15 changelog.md
16 JSON-Schema-Test-Suite/remotes/*.json
16 JSON-Schema-Test-Suite/remotes/*.json
@@ -77,6 +77,7 @@ library
77 , QuickCheck >= 2.8
77 , QuickCheck >= 2.8
78 , safe-exceptions >= 0.1.6
78 , safe-exceptions >= 0.1.6
79 , scientific >= 0.3
79 , scientific >= 0.3
80+ , semigroups >= 0.18
80 , unordered-containers >= 0.2
81 , unordered-containers >= 0.2
81 , text >= 1.1
82 , text >= 1.1
82 , vector >= 0.10
83 , vector >= 0.10
@@ -114,6 +115,7 @@ test-suite local
114 , hjsonschema
115 , hjsonschema
115 , profunctors
116 , profunctors
116 , protolude
117 , protolude
118+ , semigroups
117 , text
119 , text
118 , QuickCheck
120 , QuickCheck
119 , unordered-containers
121 , unordered-containers
@@ -152,6 +154,7 @@ test-suite remote
152 , hjsonschema
154 , hjsonschema
153 , profunctors
155 , profunctors
154 , protolude
156 , protolude
157+ , semigroups
155 , text
158 , text
156 , unordered-containers
159 , unordered-containers
157 , vector
160 , vector
src/JSONSchema/Fetch.hs+1−2
@@ -7,7 +7,6 @@ import Control.Monad (foldM)
7import qualified Data.ByteString as BS
7import qualified Data.ByteString as BS
8import qualified Data.ByteString.Lazy as LBS
8import qualified Data.ByteString.Lazy as LBS
9import qualified Data.HashMap.Strict as HM
9import qualified Data.HashMap.Strict as HM
10−import qualified Data.Semigroup as S
11import qualified Data.Text as T
10import qualified Data.Text as T
12import qualified Network.HTTP.Client as NC
11import qualified Network.HTTP.Client as NC
13import qualified Network.HTTP.Client.TLS as NCTLS
12import qualified Network.HTTP.Client.TLS as NCTLS
@@ -30,7 +29,7 @@ data FetchInfo schema = FetchInfo
30-- | Keys are URIs (without URI fragments).
29-- | Keys are URIs (without URI fragments).
31newtype URISchemaMap schema
30newtype URISchemaMap schema
32 = URISchemaMap { _unURISchemaMap :: HashMap Text schema }
31 = URISchemaMap { _unURISchemaMap :: HashMap Text schema }
33− deriving (Eq, Show, S.Semigroup, Monoid)
32+ deriving (Eq, Show, Monoid)
34
33
35-- | A top-level schema along with its location.
34-- | A top-level schema along with its location.
36data SchemaWithURI schema = SchemaWithURI
35data SchemaWithURI schema = SchemaWithURI
src/JSONSchema/Validator/Draft4/Any.hs+8−32
@@ -4,7 +4,6 @@ import Import hiding ((<>))
4
4
5import Data.Aeson.TH (constructorTagModifier)
5import Data.Aeson.TH (constructorTagModifier)
6import Data.Char (toLower)
6import Data.Char (toLower)
7−import qualified Data.HashMap.Strict as HM
8import Data.List.NonEmpty (NonEmpty((:|)))
7import Data.List.NonEmpty (NonEmpty((:|)))
9import qualified Data.List.NonEmpty as NE
8import qualified Data.List.NonEmpty as NE
10import qualified Data.Scientific as SCI
9import qualified Data.Scientific as SCI
@@ -134,7 +133,7 @@ data JSONPointerError
134 deriving (Eq, Show)
133 deriving (Eq, Show)
135
134
136resolveFragment
135resolveFragment
137− :: (FromJSON schema, ToJSON schema)
136+ :: forall schema. (FromJSON schema, ToJSON schema)
138 => (BaseURI -> schema -> BaseURI)
137 => (BaseURI -> schema -> BaseURI)
139 -> Scope schema
138 -> Scope schema
140 -> Text
139 -> Text
@@ -159,40 +158,17 @@ resolveFragment updateScope scope fragment = do
159 -- as property keys that aren't meant to change scope?
158 -- as property keys that aren't meant to change scope?
160 -- Perhaps this should be added to the language agnostic
159 -- Perhaps this should be added to the language agnostic
161 -- test suite as well.
160 -- 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.
167 go :: (Value, BaseURI)
161 go :: (Value, BaseURI)
168 -> JP.Token
162 -> JP.Token
169 -> Either JSONPointerError (Value, BaseURI)
163 -> Either JSONPointerError (Value, BaseURI)
170− go (lastVal, baseURI) tok = do
164+ go (lastVal, uri) tok = do
171 v <- first ResolutionError (JP.resolveToken tok lastVal)
165 v <- first ResolutionError (JP.resolveToken tok lastVal)
172− newBase <- newBaseURIFromFragment updateScope baseURI v
166+ case v of
173− Right (v, newBase)
167+ Array _ -> pure (v, uri)
174−
168+ _ -> do
175−-- | Update the 'BaseURI' (the store of the current "id" value)
169+ -- PERFORMANCE: Avoid deserializing subschemas.
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))
170+ schema <- first SubschemaDecodingError (fromJSONEither v)
191− Right (updateScope baseURI schema)
171+ pure (v, updateScope uri schema)
192− _ -> Right baseURI
193− where
194− idKey :: Text
195− idKey = "id"
196
172
197--------------------------------------------------
173--------------------------------------------------
198-- * enum
174-- * enum