git.iko.soy/typeable/openapi3
on master help sign in
Add genericToNamedSchemaBoundedIntegral helper
70a35c5Nickolay Kudasov
src/Data/Swagger/Schema.hs+1
@@ -11,6 +11,7 @@ module Data.Swagger.Schema (
11 genericToSchema,
11 genericToSchema,
12 genericToNamedSchema,
12 genericToNamedSchema,
13 genericToNamedSchemaBoundedEnum,
13 genericToNamedSchemaBoundedEnum,
14+ genericToNamedSchemaBoundedIntegral,
14
15
15 toSchemaBoundedIntegral,
16 toSchemaBoundedIntegral,
16 toSchemaBoundedEnum,
17 toSchemaBoundedEnum,
src/Data/Swagger/Schema/Internal.hs+9−1
@@ -159,11 +159,19 @@ toSchemaBoundedEnum _ = mempty
159 & schemaType .~ SchemaString
159 & schemaType .~ SchemaString
160 & schemaEnum ?~ map toJSON [minBound..maxBound :: a]
160 & schemaEnum ?~ map toJSON [minBound..maxBound :: a]
161
161
162+genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
163+ ( Bounded a, Integral a
164+ , Generic a, Rep a ~ D1 d f, Datatype d)
165+ => SchemaOptions -> proxy a -> NamedSchema
166+genericToNamedSchemaBoundedIntegral opts proxy
167+ = (gdatatypeSchemaName opts (Proxy :: Proxy d), toSchemaBoundedIntegral proxy)
168+
162genericToNamedSchemaBoundedEnum :: forall a d f proxy.
169genericToNamedSchemaBoundedEnum :: forall a d f proxy.
163 ( ToJSON a, Bounded a, Enum a
170 ( ToJSON a, Bounded a, Enum a
164 , Generic a, Rep a ~ D1 d f, Datatype d)
171 , Generic a, Rep a ~ D1 d f, Datatype d)
165 => SchemaOptions -> proxy a -> NamedSchema
172 => SchemaOptions -> proxy a -> NamedSchema
173+genericToNamedSchemaBoundedEnum opts proxy
166−genericToNamedSchemaBoundedEnum opts proxy = (gdatatypeSchemaName opts (Proxy :: Proxy d), toSchemaBoundedEnum proxy)
174+ = (gdatatypeSchemaName opts (Proxy :: Proxy d), toSchemaBoundedEnum proxy)
167
175
168genericToSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Schema
176genericToSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Schema
169genericToSchema opts = snd . genericToNamedSchema opts
177genericToSchema opts = snd . genericToNamedSchema opts