git.iko.soy/typeable/openapi3
on master help sign in
Add some more doctest examples
36ec100Nickolay Kudasov
src/Data/Swagger/Internal/ParamSchema.hs+10
@@ -63,6 +63,9 @@ import Data.Swagger.SchemaOptions
63-- @
63-- @
64class ToParamSchema a where
64class ToParamSchema a where
65 -- | Convert a type into a plain parameter schema.
65 -- | Convert a type into a plain parameter schema.
66+ --
67+ -- >>> encode $ toParamSchema (Proxy :: Proxy Integer)
68+ -- "{\"type\":\"integer\"}"
66 toParamSchema :: proxy a -> ParamSchema t
69 toParamSchema :: proxy a -> ParamSchema t
67 default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t
70 default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t
68 toParamSchema = genericToParamSchema defaultSchemaOptions
71 toParamSchema = genericToParamSchema defaultSchemaOptions
@@ -89,6 +92,9 @@ instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
89instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
92instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
90
93
91-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
94-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
95+--
96+-- >>> encode $ toParamSchemaBoundedIntegral (Proxy :: Proxy Int8)
97+-- "{\"maximum\":127,\"minimum\":-128,\"type\":\"integer\"}"
92toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t
98toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t
93toParamSchemaBoundedIntegral _ = mempty
99toParamSchemaBoundedIntegral _ = mempty
94 & schemaType .~ SwaggerInteger
100 & schemaType .~ SwaggerInteger
@@ -166,6 +172,10 @@ instance ToParamSchema () where
166 & schemaEnum ?~ ["_"]
172 & schemaEnum ?~ ["_"]
167
173
168-- | A configurable generic @'ParamSchema'@ creator.
174-- | 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\"]}"
169genericToParamSchema :: forall proxy a t. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t
179genericToParamSchema :: forall proxy a t. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t
170genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
180genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
171
181
src/Data/Swagger/Internal/Schema.hs+3
@@ -373,6 +373,9 @@ instance ToSchema a => ToSchema (Last a) where declareNamedSchema _ = unname
373instance ToSchema a => ToSchema (Dual a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
373instance ToSchema a => ToSchema (Dual a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
374
374
375-- | Default schema for @'Bounded'@, @'Integral'@ types.
375-- | Default schema for @'Bounded'@, @'Integral'@ types.
376+--
377+-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
378+-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
376toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
379toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
377toSchemaBoundedIntegral _ = mempty
380toSchemaBoundedIntegral _ = mempty
378 & schemaType .~ SwaggerInteger
381 & schemaType .~ SwaggerInteger