git.iko.soy/typeable/swagger2
on master help sign in
Validate non-required null fields
commit6f311cbe215f88b427c1e9de2f00d96aaecb4e0d authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateThu 28 Jan 2016, 18:06 (11 years ago) parentee3ddd5
1 file changed+6−3
src/Data/Swagger/Schema/Validation.hs+6−3
src/Data/Swagger/Schema/Validation.hs+6−3
@@ -241,9 +241,12 @@ validateObject o = withSchema $ \schema ->
241241
242242 validateProps = withSchema $ \schema -> do
243243 for_ (HashMap.toList o) $ \(k, v) ->
244− case HashMap.lookup k (schema ^. properties) of
245− Nothing -> check additionalProperties $ \s -> sub s $ validateWithSchema v
246− Just s -> validateWithSchemaRef s v
244+ case v of
245+ Null | not (k `elem` (schema ^. required)) -> valid -- null is fine for non-required property
246+ _ ->
247+ case HashMap.lookup k (schema ^. properties) of
248+ Nothing -> check additionalProperties $ \s -> sub s $ validateWithSchema v
249+ Just s -> validateWithSchemaRef s v
247250
248251validateEnum :: Value -> Validation (ParamSchema t) ()
249252validateEnum value = do