Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validate allOf #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Data/OpenApi/Internal/Schema/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Prelude.Compat

import Control.Applicative
import Control.Lens hiding (allOf)
import Control.Monad (forM, forM_, when)
import Control.Monad (forM, when)

import Data.Aeson hiding (Result)
#if MIN_VERSION_aeson(2,0,0)
Expand All @@ -49,6 +49,7 @@ import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import Data.Traversable (for)
import Data.Vector (Vector)
import qualified Data.Vector as Vector

Expand Down Expand Up @@ -488,10 +489,11 @@ validateSchemaType val = withSchema $ \sch ->
1 -> valid
_ -> invalid $ "Value matches more than one of 'oneOf' schemas: " ++ show val
(view allOf -> Just variants) -> do
-- Default semantics for Validation Monad will abort when at least one
-- variant does not match.
forM_ variants $ \var ->
validateWithSchemaRef var val
schemas <- for variants $ \case
Ref ref -> withRef ref pure
Inline s -> pure s

sub (mconcat schemas) $ validateWithSchema val

_ ->
case (sch ^. type_, val) of
Expand Down