@@ -3,7 +3,6 @@ module Data.Schematic.Validation where
33import Control.Monad
44import Control.Monad.Validation
55import Data.Aeson
6−import Data.Aeson.Internal
76import Data.Aeson.Types
87import Data.Foldable
98import Data.Functor.Identity
@@ -50,11 +49,11 @@ isValidationError (ValidationError _) = True
5049isValidationError _ = False
5150
5251validateTextConstraint
53− :: JSONPathText
52+ :: JSONPath
5453 -> Text
5554 -> Sing (tcs :: TextConstraint)
5655 -> Validation ()
57−validateTextConstraint (JSONPathText path) t = \case
56+validateTextConstraint (JSONPath path) t = \case
5857 STEq n -> do
5958 let
6059 nlen = withKnownNat n $ natVal n
@@ -107,11 +106,11 @@ validateTextConstraint (JSONPathText path) t = \case
107106 unless (matching ss) warn
108107
109108validateNumberConstraint
110− :: JSONPathText
109+ :: JSONPath
111110 -> Scientific
112111 -> Sing (tcs :: NumberConstraint)
113112 -> Validation ()
114−validateNumberConstraint (JSONPathText path) num = \case
113+validateNumberConstraint (JSONPath path) num = \case
115114 SNEq n -> do
116115 let
117116 nlen = withKnownNat n $ natVal n
@@ -149,11 +148,11 @@ validateNumberConstraint (JSONPathText path) num = \case
149148 unless predicate warn
150149
151150validateArrayConstraint
152− :: JSONPathText
151+ :: JSONPath
153152 -> V.Vector a
154153 -> Sing (tcs :: ArrayConstraint)
155154 -> Validation ()
156−validateArrayConstraint (JSONPathText path) v = \case
155+validateArrayConstraint (JSONPath path) v = \case
157156 SAEq n -> do
158157 let
159158 nlen = withKnownNat n $ natVal n
@@ -161,38 +160,10 @@ validateArrayConstraint (JSONPathText path) v = \case
161160 errMsg = "length should be == " <> T.pack (show nlen)
162161 warn = vWarning $ mmSingleton path (pure errMsg)
163162 unless predicate warn
164− SAGt n -> do
165− let
166− nlen = withKnownNat n $ natVal n
167− predicate = fromIntegral (V.length v) > nlen
168− errMsg = "length should be > " <> T.pack (show nlen)
169− warn = vWarning $ mmSingleton path (pure errMsg)
170− unless predicate warn
171− SAGe n -> do
172− let
173− nlen = withKnownNat n $ natVal n
174− predicate = fromIntegral (V.length v) >= nlen
175− errMsg = "length should be >= " <> T.pack (show nlen)
176− warn = vWarning $ mmSingleton path (pure errMsg)
177− unless predicate warn
178− SALt n -> do
179− let
180− nlen = withKnownNat n $ natVal n
181− predicate = fromIntegral (V.length v) < nlen
182− errMsg = "length should be < " <> T.pack (show nlen)
183− warn = vWarning $ mmSingleton path (pure errMsg)
184− unless predicate warn
185− SALe n -> do
186− let
187− nlen = withKnownNat n $ natVal n
188− predicate = fromIntegral (V.length v) <= nlen
189− errMsg = "length should be <= " <> T.pack (show nlen)
190− warn = vWarning $ mmSingleton path (pure errMsg)
191− unless predicate warn
192163
193164validateJsonRepr
194165 :: Sing schema
195− -> JSONPath
166+ -> [DemotedPathSegment]
196167 -> JsonRepr schema
197168 -> Validation ()
198169validateJsonRepr sschema dpath jr = case jr of
@@ -226,7 +197,7 @@ validateJsonRepr sschema dpath jr = case jr of
226197 process cs
227198 process acs
228199 for_ (V.indexed v) $ \(ix, jr') -> do
229− let newPath = dpath <> pure (Index $ fromIntegral ix)
200+ let newPath = dpath <> pure (DIx $ fromIntegral ix)
230201 validateJsonRepr s newPath jr'
231202 ReprOptional d -> case sschema of
232203 SSchemaOptional ss -> case d of
@@ -238,7 +209,7 @@ validateJsonRepr sschema dpath jr = case jr of
238209 go :: Rec FieldRepr (ts :: [(Symbol, Schema)] ) -> Validation ()
239210 go RNil = pure ()
240211 go (f@(FieldRepr d) :& ftl) = do
241− let newPath = dpath <> [Key (knownFieldName f)]
212+ let newPath = dpath <> [DKey (knownFieldName f)]
242213 validateJsonRepr (knownFieldSchema f) newPath d
243214 go ftl
244215 ReprUnion _ -> pure () -- FIXME
@@ -250,7 +221,7 @@ validateJsonRepr sschema dpath jr = case jr of
250221 -- fail "impossible to produce subUnion, please report this as a bug"
251222 -- Just x -> do
252223 -- let
253− -- JSONPathText path = demotedPathToText dpath
224+ -- JSONPath path = demotedPathToText dpath
254225 -- case stl of
255226 -- SNil -> void $ vWarning $ mmSingleton path
256227 -- $ pure "union handling error, please report this as bug"