@@ -70,29 +70,16 @@ embedded schema = concat
70 checkDependency (OB.PropertyDependency _) = Nothing
70 checkDependency (OB.PropertyDependency _) = Nothing
71 checkDependency (OB.SchemaDependency s) = Just s
71 checkDependency (OB.SchemaDependency s) = Just s
73−--------------------------------------------------
74−-- * Validation (Exported from 'Data.JsonSchema.Draft4')
75−--------------------------------------------------
77−-- | In normal situations just use 'checkSchema', which is a combination of
78−-- 'schemaValidity' and 'runValidate'.
80− :: ReferencedSchemas Schema
81− -> SchemaWithURI Schema
84−runValidate = (fmap.fmap.fmap.fmap) specializeForDraft4 validateAny
86--------------------------------------------------
73--------------------------------------------------
87-- * Validation (Main internal functions)
74-- * Validation (Main internal functions)
88--------------------------------------------------
75--------------------------------------------------
90−validateAny
77+runValidate
91 :: ReferencedSchemas Schema
78 :: ReferencedSchemas Schema
92 -> SchemaWithURI Schema
79 -> SchemaWithURI Schema
94− -> [FR.Failure ValidatorChain]
81+ -> [Invalid]
95−validateAny referenced sw x = concat
82+runValidate referenced sw x = concat
96 [ f _schemaEnum (setFailure Enum) (fmap maybeToList . AN.enumVal)
83 [ f _schemaEnum (setFailure Enum) (fmap maybeToList . AN.enumVal)
97 , f _schemaType (setFailure TypeValidator) (fmap maybeToList . AN.typeVal)
84 , f _schemaType (setFailure TypeValidator) (fmap maybeToList . AN.typeVal)
98 , f _schemaAllOf (modFailure AllOf) (AN.allOf recurse)
85 , f _schemaAllOf (modFailure AllOf) (AN.allOf recurse)
@@ -102,7 +89,7 @@ validateAny referenced sw x = concat
102 , refFailures
89 , refFailures
103 ] <> specificValidators
90 ] <> specificValidators
105− specificValidators :: [FR.Failure ValidatorChain]
92+ specificValidators :: [Invalid]
106 specificValidators =
93 specificValidators =
107 case x of
94 case x of
108 Number y -> validateNumber (_swSchema sw) y
95 Number y -> validateNumber (_swSchema sw) y
@@ -120,16 +107,16 @@ validateAny referenced sw x = concat
121 -- [1] A list of errors wrapped in a 'Maybe' where 'Nothing' represents
108 -- [1] A list of errors wrapped in a 'Maybe' where 'Nothing' represents
122 -- if resolving the reference itself failed.
109 -- if resolving the reference itself failed.
123− refFailures :: [FR.Failure ValidatorChain]
110+ refFailures :: [Invalid]
124 refFailures =
111 refFailures =
125 case _schemaRef (_swSchema sw) of
112 case _schemaRef (_swSchema sw) of
126 Nothing -> mempty
113 Nothing -> mempty
127 Just reference ->
114 Just reference ->
128− maybe [FR.Failure RefResolution (toJSON reference) mempty]
115+ maybe [FR.Invalid RefResolution (toJSON reference) mempty]
129 (fmap (modFailure Ref))
116 (fmap (modFailure Ref))
130 $ AN.ref scope
117 $ AN.ref scope
131 getReference
118 getReference
132− (\a b -> validateAny referenced (SchemaWithURI b a))
119+ (\a b -> runValidate referenced (SchemaWithURI b a))
133 reference
120 reference
@@ -143,7 +130,7 @@ validateAny referenced sw x = concat
143validateString
130validateString
144 :: Schema
131 :: Schema
146− -> [FR.Failure ValidatorChain]
133+ -> [Invalid]
147validateString schema x = concat
134validateString schema x = concat
148 [ f _schemaMaxLength (setFailure MaxLength) (fmap maybeToList . ST.maxLength)
135 [ f _schemaMaxLength (setFailure MaxLength) (fmap maybeToList . ST.maxLength)
149 , f _schemaMinLength (setFailure MinLength) (fmap maybeToList . ST.minLength)
136 , f _schemaMinLength (setFailure MinLength) (fmap maybeToList . ST.minLength)
@@ -155,7 +142,7 @@ validateString schema x = concat
155validateNumber
142validateNumber
156 :: Schema
143 :: Schema
157 -> Scientific
144 -> Scientific
158− -> [FR.Failure ValidatorChain]
145+ -> [Invalid]
159validateNumber schema x = concat
146validateNumber schema x = concat
160 [ f _schemaMultipleOf (setFailure MultipleOf) (fmap maybeToList . NU.multipleOf)
147 [ f _schemaMultipleOf (setFailure MultipleOf) (fmap maybeToList . NU.multipleOf)
161 , f _schemaMaximum
148 , f _schemaMaximum
@@ -182,7 +169,7 @@ validateArray
182 :: ReferencedSchemas Schema
169 :: ReferencedSchemas Schema
183 -> SchemaWithURI Schema
170 -> SchemaWithURI Schema
184 -> Vector Value
171 -> Vector Value
185− -> [FR.Failure ValidatorChain]
172+ -> [Invalid]
186validateArray referenced (SchemaWithURI schema mUri) x = concat
173validateArray referenced (SchemaWithURI schema mUri) x = concat
187 [ f _schemaMaxItems (setFailure MaxItems) (fmap maybeToList . AR.maxItems)
174 [ f _schemaMaxItems (setFailure MaxItems) (fmap maybeToList . AR.maxItems)
188 , f _schemaMinItems (setFailure MinItems) (fmap maybeToList . AR.minItems)
175 , f _schemaMinItems (setFailure MinItems) (fmap maybeToList . AR.minItems)
@@ -204,7 +191,7 @@ validateObject
204 :: ReferencedSchemas Schema
191 :: ReferencedSchemas Schema
205 -> SchemaWithURI Schema
192 -> SchemaWithURI Schema
206 -> HashMap Text Value
193 -> HashMap Text Value
207− -> [FR.Failure ValidatorChain]
194+ -> [Invalid]
208validateObject referenced (SchemaWithURI schema mUri) x = concat
195validateObject referenced (SchemaWithURI schema mUri) x = concat
209 [ f _schemaMaxProperties (setFailure MaxProperties) (fmap maybeToList . OB.maxProperties)
196 [ f _schemaMaxProperties (setFailure MaxProperties) (fmap maybeToList . OB.maxProperties)
210 , f _schemaMinProperties (setFailure MinProperties) (fmap maybeToList . OB.minProperties)
197 , f _schemaMinProperties (setFailure MinProperties) (fmap maybeToList . OB.minProperties)
@@ -262,9 +249,9 @@ descendNextLevel
262 -> SchemaWithURI Schema
249 -> SchemaWithURI Schema
263 -> Schema
250 -> Schema
265− -> [FR.Failure ValidatorChain]
252+ -> [Invalid]
266descendNextLevel referenced (SchemaWithURI schema mUri) =
253descendNextLevel referenced (SchemaWithURI schema mUri) =
267− validateAny referenced . flip SchemaWithURI scope
254+ runValidate referenced . flip SchemaWithURI scope
269 scope :: Maybe Text
256 scope :: Maybe Text
270 scope = updateResolutionScope mUri (_schemaId schema)
257 scope = updateResolutionScope mUri (_schemaId schema)
@@ -273,8 +260,8 @@ runSingle
273 :: Schema
260 :: Schema
275 -> (Schema -> Maybe val)
262 -> (Schema -> Maybe val)
276− -> (err -> FR.Failure ValidatorChain)
263+ -> (err -> Invalid)
277 -> (val -> dta -> [err])
264 -> (val -> dta -> [err])
278− -> [FR.Failure ValidatorChain]
265+ -> [Invalid]
279runSingle schema dta field modifyError validate =
266runSingle schema dta field modifyError validate =
280 maybe mempty (\val -> modifyError <$> validate val dta) (field schema)
267 maybe mempty (\val -> modifyError <$> validate val dta) (field schema)