git.iko.soy/typeable/swagger2
on master help sign in
Add some more doctest examples
commit36ec100ad3a764aa3f5396bb303522cb9124e701 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSat 19 Dec 2015, 17:32 (11 years ago) parenta6ac15f
2 files changed+13
src/Data/Swagger/Internal/ParamSchema.hs+10 src/Data/Swagger/Internal/Schema.hs+3
src/Data/Swagger/Internal/ParamSchema.hs+10
@@ -63,6 +63,9 @@ import Data.Swagger.SchemaOptions
6363-- @
6464class ToParamSchema a where
6565 -- | Convert a type into a plain parameter schema.
66+ --
67+ -- >>> encode $ toParamSchema (Proxy :: Proxy Integer)
68+ -- "{\"type\":\"integer\"}"
6669 toParamSchema :: proxy a -> ParamSchema t
6770 default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t
6871 toParamSchema = genericToParamSchema defaultSchemaOptions
@@ -89,6 +92,9 @@ instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
8992instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
9093
9194-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
95+--
96+-- >>> encode $ toParamSchemaBoundedIntegral (Proxy :: Proxy Int8)
97+-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
9298toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t
9399toParamSchemaBoundedIntegral _ = mempty
94100 & schemaType .~ SwaggerInteger
@@ -166,6 +172,10 @@ instance ToParamSchema () where
166172 & schemaEnum ?~ ["_"]
167173
168174-- | A configurable generic @'ParamSchema'@ creator.
175+--
176+-- >>> data Color = Red | Blue deriving Generic
177+-- >>> encode $ genericToParamSchema defaultSchemaOptions (Proxy :: Proxy Color)
178+-- "{\"type\":\"string\",\"enum\":[\"Red\",\"Blue\"]}"
169179genericToParamSchema :: forall proxy a t. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t
170180genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
171181
src/Data/Swagger/Internal/Schema.hs+3
@@ -373,6 +373,9 @@ instance ToSchema a => ToSchema (Last a) where declareNamedSchema _ = unname
373373instance ToSchema a => ToSchema (Dual a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
374374
375375-- | Default schema for @'Bounded'@, @'Integral'@ types.
376+--
377+-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
378+-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
376379toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
377380toSchemaBoundedIntegral _ = mempty
378381 & schemaType .~ SwaggerInteger