Skip to content

Commit

Permalink
feat(src/Schema): validate HasNot property
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-baptiste.gourlet committed Jun 20, 2024
1 parent 00aca83 commit 1be8f45
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Data/OpenApi/Internal/Schema/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,15 @@ validateSchemaType val = withSchema $ \sch ->
-- variant does not match.
forM_ variants $ \var ->
validateWithSchemaRef var val

(view not_ -> Just notVariant) -> do
-- Attempt to validate against `notVariant`, expecting it to fail.
-- `False <$ ...` ensures that a successful validation maps to `False`.
-- If the validation fails, `return True` ensures we catch this as the desired outcome.
validationResult <- (False <$ validateWithSchemaRef notVariant val) <|> return True
if validationResult
then valid -- If the result is `True`, it means `validateWithSchemaRef` failed, which is correct.
else invalid $ "Value matches 'not' schema, which it shouldn't: " ++ show val

_ ->
case (sch ^. type_, val) of
-- Type must be set for nullable to have effect
Expand Down

0 comments on commit 1be8f45

Please sign in to comment.