Skip to content

Commit

Permalink
Fix doctests for #138
Browse files Browse the repository at this point in the history
`Just _` and `Nothing` cases wrapped properly
  • Loading branch information
Andrey Prokopenko committed Aug 22, 2018
1 parent 6f10ca0 commit 61e004f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Data/Swagger/Internal/Schema/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ validateSchemaType value = withSchema $ \sch ->
(Nothing, String s) -> sub_ paramSchema (validateString s)
(Nothing, Array xs) -> sub_ paramSchema (validateArray xs)
(Nothing, Object o) -> validateObject o
(t, _) -> invalid $ "expected JSON value of type " ++ show t
param@(t, _) -> invalid $ "expected JSON value of type " ++ showType param

validateParamSchemaType :: Value -> Validation (ParamSchema t) ()
validateParamSchemaType value = withSchema $ \sch ->
Expand All @@ -356,11 +356,18 @@ validateParamSchemaType value = withSchema $ \sch ->
(Just SwaggerNumber, Number n) -> validateNumber n
(Just SwaggerString, String s) -> validateString s
(Just SwaggerArray, Array xs) -> validateArray xs
(Nothing, Null) -> valid
(Nothing, Bool _) -> valid
-- Number by default
(Nothing, Number n) -> validateNumber n
(Nothing, String s) -> validateString s
(Nothing, Array xs) -> validateArray xs
(t, _) -> invalid $ "expected JSON value of type " ++ show t

param@(t, _) -> invalid $ "expected JSON value of type " ++ showType param

showType :: (Maybe (SwaggerType t), Value) -> String
showType (Just type_, _) = show type_
showType (Nothing, Null) = "SwaggerNull"
showType (Nothing, Bool _) = "SwaggerBoolean"
showType (Nothing, Number _) = "SwaggerNumber"
showType (Nothing, String _) = "SwaggerString"
showType (Nothing, Array _) = "SwaggerArray"
showType (Nothing, Object _) = "SwaggerObject"

0 comments on commit 61e004f

Please sign in to comment.