mirror of
https://github.com/NorfairKing/autodocodec.git
synced 2024-12-02 09:52:01 +03:00
generate a value schema as well
This commit is contained in:
parent
cf7f92f50b
commit
de9fc92a9d
@ -55,9 +55,12 @@ data JSONSchema
|
||||
JSONSchema
|
||||
| CommentSchema !Text !JSONSchema
|
||||
| RefSchema !Text
|
||||
| WithDefSchema !(Map Text JSONSchema) JSONSchema
|
||||
| WithDefSchema !(Map Text JSONSchema) !JSONSchema
|
||||
deriving (Show, Eq, Generic)
|
||||
|
||||
-- NOTE, this is a recursive schema so we've had to manually write our generators for it.
|
||||
-- If you add any constructors here, make sure to go add the constructor to the GenValid instance as well.
|
||||
|
||||
validateAccordingTo :: JSON.Value -> JSONSchema -> Bool
|
||||
validateAccordingTo val schema = (`evalState` M.empty) $ go val schema
|
||||
where
|
||||
@ -219,7 +222,7 @@ instance FromJSON JSONSchema where
|
||||
case mAny of
|
||||
Just anies -> pure $ ChoiceSchema anies
|
||||
Nothing -> do
|
||||
mConst <- o JSON..:? "const"
|
||||
let mConst = HM.lookup "const" o
|
||||
case mConst of
|
||||
Just constant -> pure $ ValueSchema constant
|
||||
Nothing -> do
|
||||
|
@ -100,6 +100,7 @@ instance GenValid JSONSchema where
|
||||
oneof
|
||||
[ ArraySchema <$> resize (n -1) genValid,
|
||||
(ObjectSchema <$> resize (n -1) genValid) `suchThat` isValid,
|
||||
ValueSchema <$> genValid,
|
||||
do
|
||||
(a, b, c) <- genSplit3 (n -1)
|
||||
choice1 <- resize a genValid
|
||||
|
Loading…
Reference in New Issue
Block a user