git.iko.soy/typeable/openapi3
on master help sign in
Add constructorTagModifier option
commitb4f1e60d695642cb5798c3107a2100db5ad0e647 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateWed 25 Nov 2015, 13:25 (11 years ago) parentd1f97f1
2 files changed+10−4
src/Data/Swagger/Schema/Internal.hs+3−1 test/Data/Swagger/SchemaSpec.hs+7−3
src/Data/Swagger/Schema/Internal.hs+3−1
@@ -135,6 +135,7 @@ instance ToSchema a => ToSchema (Dual a) where toNamedSchema _ = unnamed $ to
135135
136136data SchemaOptions = SchemaOptions
137137 { fieldLabelModifier :: String -> String
138+ , constructorTagModifier :: String -> String
138139 , datatypeNameModifier :: String -> String
139140 , useReferences :: Bool
140141 , unwrapUnaryRecords :: Bool
@@ -143,6 +144,7 @@ data SchemaOptions = SchemaOptions
143144defaultSchemaOptions :: SchemaOptions
144145defaultSchemaOptions = SchemaOptions
145146 { fieldLabelModifier = id
147+ , constructorTagModifier = id
146148 , datatypeNameModifier = id
147149 , useReferences = True
148150 , unwrapUnaryRecords = False
@@ -262,7 +264,7 @@ gsumConToSchema tagSchemaRef opts _ schema = schema
262264 & schemaMaxProperties ?~ 1
263265 & schemaMinProperties ?~ 1
264266 where
265− tag = T.pack (conName (Proxy3 :: Proxy3 c f p))
267+ tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
266268
267269instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
268270 gsumToSchema opts = gsumConToSchema tagSchemaRef opts
test/Data/Swagger/SchemaSpec.hs+7−3
@@ -304,7 +304,11 @@ playersSchemaJSON = [aesonQQ|
304304data Status
305305 = StatusOk String
306306 | 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") }
308312
309313statusSchemaJSON :: Value
310314statusSchemaJSON = [aesonQQ|
@@ -312,8 +316,8 @@ statusSchemaJSON = [aesonQQ|
312316 "type": "object",
313317 "properties":
314318 {
315− "StatusOk": { "type": "string" },
316− "StatusError": { "type": "string" }
319+ "ok": { "type": "string" },
320+ "error": { "type": "string" }
317321 },
318322 "maxProperties": 1,
319323 "minProperties": 1