git.iko.soy/typeable/openapi3
on master help sign in
Add constructorTagModifier option
b4f1e60Nickolay Kudasov
src/Data/Swagger/Schema/Internal.hs+3−1
@@ -135,6 +135,7 @@ instance ToSchema a => ToSchema (Dual a) where toNamedSchema _ = unnamed $ to
135
135
136data SchemaOptions = SchemaOptions
136data SchemaOptions = SchemaOptions
137 { fieldLabelModifier :: String -> String
137 { fieldLabelModifier :: String -> String
138+ , constructorTagModifier :: String -> String
138 , datatypeNameModifier :: String -> String
139 , datatypeNameModifier :: String -> String
139 , useReferences :: Bool
140 , useReferences :: Bool
140 , unwrapUnaryRecords :: Bool
141 , unwrapUnaryRecords :: Bool
@@ -143,6 +144,7 @@ data SchemaOptions = SchemaOptions
143defaultSchemaOptions :: SchemaOptions
144defaultSchemaOptions :: SchemaOptions
144defaultSchemaOptions = SchemaOptions
145defaultSchemaOptions = SchemaOptions
145 { fieldLabelModifier = id
146 { fieldLabelModifier = id
147+ , constructorTagModifier = id
146 , datatypeNameModifier = id
148 , datatypeNameModifier = id
147 , useReferences = True
149 , useReferences = True
148 , unwrapUnaryRecords = False
150 , unwrapUnaryRecords = False
@@ -262,7 +264,7 @@ gsumConToSchema tagSchemaRef opts _ schema = schema
262 & schemaMaxProperties ?~ 1
264 & schemaMaxProperties ?~ 1
263 & schemaMinProperties ?~ 1
265 & schemaMinProperties ?~ 1
264 where
266 where
265− tag = T.pack (conName (Proxy3 :: Proxy3 c f p))
267+ tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
266
268
267instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
269instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
268 gsumToSchema opts = gsumConToSchema tagSchemaRef opts
270 gsumToSchema opts = gsumConToSchema tagSchemaRef opts
test/Data/Swagger/SchemaSpec.hs+7−3
@@ -304,7 +304,11 @@ playersSchemaJSON = [aesonQQ|
304data Status
304data Status
305 = StatusOk String
305 = StatusOk String
306 | StatusError String
306 | StatusError String
307− deriving (Generic, ToSchema)
307+ deriving (Generic)
308+
309+instance ToSchema Status where
310+ toNamedSchema = genericToNamedSchema defaultSchemaOptions
311+ { constructorTagModifier = map toLower . drop (length "Status") }
308
312
309statusSchemaJSON :: Value
313statusSchemaJSON :: Value
310statusSchemaJSON = [aesonQQ|
314statusSchemaJSON = [aesonQQ|
@@ -312,8 +316,8 @@ statusSchemaJSON = [aesonQQ|
312 "type": "object",
316 "type": "object",
313 "properties":
317 "properties":
314 {
318 {
315− "StatusOk": { "type": "string" },
319+ "ok": { "type": "string" },
316− "StatusError": { "type": "string" }
320+ "error": { "type": "string" }
317 },
321 },
318 "maxProperties": 1,
322 "maxProperties": 1,
319 "minProperties": 1
323 "minProperties": 1