@@ -158,12 +158,18 @@ valid = pure ()
159-- | Validate schema's property given a lens into that property
159-- | Validate schema's property given a lens into that property
160-- and property checker.
160-- and property checker.
161−check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
161+checkMissing :: Validation s () -> Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
162−check l g = withSchema $ \sch ->
162+checkMissing missing l g = withSchema $ \sch ->
163 case sch ^. l of
163 case sch ^. l of
164− Nothing -> valid
164+ Nothing -> missing
165 Just x -> g x
165 Just x -> g x
167+-- | Validate schema's property given a lens into that property
168+-- and property checker.
169+-- If property is missing in schema, consider it valid.
170+check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
171+check = checkMissing valid
167-- | Validate same value with different schema.
173-- | Validate same value with different schema.
168sub :: t -> Validation t a -> Validation s a
174sub :: t -> Validation t a -> Validation s a
169sub = lmap . const
175sub = lmap . const
@@ -292,9 +298,13 @@ validateObject o = withSchema $ \sch ->
292 Null | not (k `elem` (sch ^. required)) -> valid -- null is fine for non-required property
298 Null | not (k `elem` (sch ^. required)) -> valid -- null is fine for non-required property
294 case InsOrdHashMap.lookup k (sch ^. properties) of
300 case InsOrdHashMap.lookup k (sch ^. properties) of
295− Nothing -> check additionalProperties $ \s -> validateWithSchemaRef s v
301+ Nothing -> checkMissing (unknownProperty k) additionalProperties $ \s -> validateWithSchemaRef s v
296 Just s -> validateWithSchemaRef s v
302 Just s -> validateWithSchemaRef s v
304+ unknownProperty :: Text -> Validation s a
305+ unknownProperty name = invalid $
306+ "property " <> show name <> " is found in JSON value, but it is not mentioned in Swagger schema"
298validateEnum :: Value -> Validation (ParamSchema t) ()
308validateEnum :: Value -> Validation (ParamSchema t) ()
299validateEnum value = do
309validateEnum value = do
300 check enum_ $ \xs ->
310 check enum_ $ \xs ->