git.iko.soy/typeable/schematic
on master help sign in
7 files changed+51−42
since splitsnapshots
unifiedsplit
ChangeLog.md+4 schematic.cabal+7−3 src/Data/Schematic/Path.hs+17−20 src/Data/Schematic/Validation.hs+11−10 stack-13.21.yaml+7 stack-13.7.yaml−5 stack.yaml+5−4
ChangeLog.md+4
@@ -1,5 +1,9 @@
11# Revision history for schematic
22
3+## 0.6.0.0 -- 2021-01-15
4+
5+Added compatability with aeson-1.4.3.0. Since version 1.4.3 the module `Data.Aeson` started exporting `JSONPath`, which was conflicting with our own `JSONPath`. Furthermore, started using `JSONPathElement` from `aeson` instead of `DemotedPathSegment`.
6+
37## 0.5.1.0 -- 2021-01-15
48
59Fix the generation of json schema for numbers.
schematic.cabal+7−3
@@ -1,5 +1,5 @@
11name: schematic
2−version: 0.5.1.0
2+version: 0.6.0.0
33synopsis: JSON-biased spec and validation tool
44description: JSON-biased spec and validation tool. Makes possible to have a schema as a haskell type and derive json instances, validation actions, JSON generation for property-test generically. Built-in lens support.
55license: BSD3
@@ -10,7 +10,7 @@ homepage: http://github.com/typeable/schematic
1010Bug-reports: http://github.com/typeable/schematic/issues/
1111category: Data
1212build-type: Simple
13−extra-source-files: ChangeLog.md
13+extra-source-files: ChangeLog.md, README.md
1414cabal-version: >=1.10
1515
1616library
@@ -67,7 +67,7 @@ library
6767 , UndecidableInstances
6868 build-depends: base >=4.11 && <5
6969 , bytestring
70− , aeson >= 1 && < 1.4.3.0
70+ , aeson >= 1.4.3.0 && < 1.6
7171 , containers
7272 , hjsonschema
7373 , mtl
@@ -118,3 +118,7 @@ test-suite spec
118118 , HelpersSpec
119119 , LensSpec
120120 , JsonSchemaSpec
121+
122+source-repository head
123+ type: git
124+ location: https://github.com/typeable/schematic
src/Data/Schematic/Path.hs+17−20
@@ -4,36 +4,33 @@ import Data.Foldable as F
44import Data.Singletons.Prelude
55import Data.Singletons.TypeLits
66import Data.Text as T
7+import Data.Aeson.Internal
78
89
9−data PathSegment = Key Symbol | Ix Nat
10−
11−data instance Sing (jp :: PathSegment) where
12− SKey :: (SingI k) => Sing (k :: Symbol) -> Sing ('Key k)
13− SIx :: (SingI n) => Sing (n :: Nat) -> Sing ('Ix n)
14−
15−data DemotedPathSegment = DKey Text | DIx Integer
10+newtype JSONPathText = JSONPathText Text
1611 deriving (Show)
1712
18−-- | Textual representation of json path.
19−newtype JSONPath = JSONPath Text
20− deriving (Show)
13+data PathSegment = PathKey Symbol | PathIx Nat
14+
15+data instance Sing (jp :: PathSegment) where
16+ SKey :: (SingI k) => Sing (k :: Symbol) -> Sing ('PathKey k)
17+ SIx :: (SingI n) => Sing (n :: Nat) -> Sing ('PathIx n)
2118
22−demotePath :: Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
19+demotePath :: Sing (ps :: [PathSegment]) -> JSONPath
2320demotePath = go []
2421 where
25− go :: [DemotedPathSegment] -> Sing (ps :: [PathSegment]) -> [DemotedPathSegment]
22+ go :: JSONPath -> Sing (ps :: [PathSegment]) -> JSONPath
2623 go acc SNil = acc
2724 go acc (SCons p ps) = go (acc ++ [demotePathSeg p]) ps
28− demotePathSeg :: Sing (ps :: PathSegment) -> DemotedPathSegment
29− demotePathSeg (SKey s) = DKey $ T.pack $ withKnownSymbol s $ symbolVal s
30− demotePathSeg (SIx n) = DIx $ withKnownNat n $ fromIntegral $ natVal n
25+ demotePathSeg :: Sing (ps :: PathSegment) -> JSONPathElement
26+ demotePathSeg (SKey s) = Key $ T.pack $ withKnownSymbol s $ symbolVal s
27+ demotePathSeg (SIx n) = Index $ withKnownNat n $ fromIntegral $ natVal n
3128
32−demotedPathToText :: [DemotedPathSegment] -> JSONPath
33−demotedPathToText = JSONPath . F.foldl' renderPathSegment ""
29+demotedPathToText :: JSONPath -> JSONPathText
30+demotedPathToText = JSONPathText . F.foldl' renderPathSegment ""
3431 where
35− renderPathSegment acc (DKey t) = acc <> "." <> t
36− renderPathSegment acc (DIx n) = acc <> "[" <> T.pack (show n) <> "]"
32+ renderPathSegment acc (Key t) = acc <> "." <> t
33+ renderPathSegment acc (Index n) = acc <> "[" <> T.pack (show n) <> "]"
3734
38−pathToText :: Sing (ps :: [PathSegment]) -> JSONPath
35+pathToText :: Sing (ps :: [PathSegment]) -> JSONPathText
3936pathToText = demotedPathToText . demotePath
src/Data/Schematic/Validation.hs+11−10
@@ -3,6 +3,7 @@ module Data.Schematic.Validation where
33import Control.Monad
44import Control.Monad.Validation
55import Data.Aeson
6+import Data.Aeson.Internal
67import Data.Aeson.Types
78import Data.Foldable
89import Data.Functor.Identity
@@ -49,11 +50,11 @@ isValidationError (ValidationError _) = True
4950isValidationError _ = False
5051
5152validateTextConstraint
52− :: JSONPath
53+ :: JSONPathText
5354 -> Text
5455 -> Sing (tcs :: TextConstraint)
5556 -> Validation ()
56−validateTextConstraint (JSONPath path) t = \case
57+validateTextConstraint (JSONPathText path) t = \case
5758 STEq n -> do
5859 let
5960 nlen = withKnownNat n $ natVal n
@@ -106,11 +107,11 @@ validateTextConstraint (JSONPath path) t = \case
106107 unless (matching ss) warn
107108
108109validateNumberConstraint
109− :: JSONPath
110+ :: JSONPathText
110111 -> Scientific
111112 -> Sing (tcs :: NumberConstraint)
112113 -> Validation ()
113−validateNumberConstraint (JSONPath path) num = \case
114+validateNumberConstraint (JSONPathText path) num = \case
114115 SNEq n -> do
115116 let
116117 nlen = withKnownNat n $ natVal n
@@ -148,11 +149,11 @@ validateNumberConstraint (JSONPath path) num = \case
148149 unless predicate warn
149150
150151validateArrayConstraint
151− :: JSONPath
152+ :: JSONPathText
152153 -> V.Vector a
153154 -> Sing (tcs :: ArrayConstraint)
154155 -> Validation ()
155−validateArrayConstraint (JSONPath path) v = \case
156+validateArrayConstraint (JSONPathText path) v = \case
156157 SAEq n -> do
157158 let
158159 nlen = withKnownNat n $ natVal n
@@ -191,7 +192,7 @@ validateArrayConstraint (JSONPath path) v = \case
191192
192193validateJsonRepr
193194 :: Sing schema
194− -> [DemotedPathSegment]
195+ -> JSONPath
195196 -> JsonRepr schema
196197 -> Validation ()
197198validateJsonRepr sschema dpath jr = case jr of
@@ -225,7 +226,7 @@ validateJsonRepr sschema dpath jr = case jr of
225226 process cs
226227 process acs
227228 for_ (V.indexed v) $ \(ix, jr') -> do
228− let newPath = dpath <> pure (DIx $ fromIntegral ix)
229+ let newPath = dpath <> pure (Index $ fromIntegral ix)
229230 validateJsonRepr s newPath jr'
230231 ReprOptional d -> case sschema of
231232 SSchemaOptional ss -> case d of
@@ -237,7 +238,7 @@ validateJsonRepr sschema dpath jr = case jr of
237238 go :: Rec FieldRepr (ts :: [(Symbol, Schema)] ) -> Validation ()
238239 go RNil = pure ()
239240 go (f@(FieldRepr d) :& ftl) = do
240− let newPath = dpath <> [DKey (knownFieldName f)]
241+ let newPath = dpath <> [Key (knownFieldName f)]
241242 validateJsonRepr (knownFieldSchema f) newPath d
242243 go ftl
243244 ReprUnion _ -> pure () -- FIXME
@@ -249,7 +250,7 @@ validateJsonRepr sschema dpath jr = case jr of
249250 -- fail "impossible to produce subUnion, please report this as a bug"
250251 -- Just x -> do
251252 -- let
252− -- JSONPath path = demotedPathToText dpath
253+ -- JSONPathText path = demotedPathToText dpath
253254 -- case stl of
254255 -- SNil -> void $ vWarning $ mmSingleton path
255256 -- $ pure "union handling error, please report this as bug"
stack-13.21.yamlnew file+7
@@ -0,0 +1,7 @@
1+resolver: lts-13.21
2+extra-deps:
3+ - hjsonpointer-1.4.0@rev:0
4+ - hjsonschema-1.9.0@rev:0
5+ - validationt-0.3.0
6+nix:
7+ packages: [pcre, pkg-config, zlib]
stack-13.7.yamldeleted−5
@@ -1,5 +0,0 @@
1−resolver: lts-13.7
2−extra-deps:
3− - hjsonpointer-1.4.0@rev:0
4− - hjsonschema-1.9.0@rev:0
5− - validationt-0.2.1.0
stack.yaml+5−4
@@ -1,5 +1,6 @@
1−resolver: lts-12.0
1+resolver: lts-14.22
22extra-deps:
3− - hjsonpointer-1.4.0@rev:0
4− - hjsonschema-1.9.0@rev:0
5− - validationt-0.2.1.0
3+- hjsonpointer-1.4.0@rev:0
4+- hjsonschema-1.9.0@rev:0
5+- git: https://github.com/typeable/validationt.git
6+ commit: 97fea97c4015ab5e99f3efb2c73e1fef4b8857d8