@@ -63,6 +63,9 @@ import Data.Swagger.SchemaOptions
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.
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
91-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
94-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
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 ?~ ["_"]
168-- | A configurable generic @'ParamSchema'@ creator.
174-- | A configurable generic @'ParamSchema'@ creator.
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