@@ -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"