@@ -158,12 +158,18 @@ valid = pure ()
158158
159159-- | Validate schema's property given a lens into that property
160160-- and property checker.
161−check :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
162−check l g = withSchema $ \sch ->
161+checkMissing :: Validation s () -> Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
162+checkMissing missing l g = withSchema $ \sch ->
163163 case sch ^. l of
164− Nothing -> valid
164+ Nothing -> missing
165165 Just x -> g x
166166
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
172+
167173-- | Validate same value with different schema.
168174sub :: t -> Validation t a -> Validation s a
169175sub = lmap . const
@@ -292,9 +298,13 @@ validateObject o = withSchema $ \sch ->
292298 Null | not (k `elem` (sch ^. required)) -> valid -- null is fine for non-required property
293299 _ ->
294300 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
296302 Just s -> validateWithSchemaRef s v
297303
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"
307+
298308validateEnum :: Value -> Validation (ParamSchema t) ()
299309validateEnum value = do
300310 check enum_ $ \xs ->