@@ -27,10 +27,10 @@ import Data.Swagger.Lens
2727class ToSchema a where
2828 toSchema :: proxy a -> Schema
2929 default toSchema :: (Generic a, GToSchema (Rep a)) => proxy a -> Schema
30− toSchema = genericToSchema
30+ toSchema = genericToSchema defaultSchemaOptions
3131
3232class GToSchema (f :: * -> *) where
33− gtoSchema :: proxy f -> Schema -> Schema
33+ gtoSchema :: SchemaOptions -> proxy f -> Schema -> Schema
3434
3535instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
3636 toSchema _ = mempty
@@ -107,6 +107,13 @@ instance ToSchema a => ToSchema (First a) where toSchema _ = toSchema (Proxy :
107107instance ToSchema a => ToSchema (Last a) where toSchema _ = toSchema (Proxy :: Proxy a)
108108instance ToSchema a => ToSchema (Dual a) where toSchema _ = toSchema (Proxy :: Proxy a)
109109
110+data SchemaOptions = SchemaOptions
111+ { fieldLabelModifier :: String -> String }
112+
113+defaultSchemaOptions :: SchemaOptions
114+defaultSchemaOptions = SchemaOptions
115+ { fieldLabelModifier = id }
116+
110117toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
111118toSchemaBoundedIntegral _ = mempty
112119 & schemaType .~ SchemaInteger
@@ -118,15 +125,15 @@ toSchemaBoundedEnum _ = mempty
118125 & schemaType .~ SchemaString
119126 & schemaEnum ?~ map toJSON [minBound..maxBound :: a]
120127
121−genericToSchema :: forall a proxy. (Generic a, GToSchema (Rep a)) => proxy a -> Schema
122−genericToSchema _ = gtoSchema (Proxy :: Proxy (Rep a)) mempty
128+genericToSchema :: forall a proxy. (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Schema
129+genericToSchema opts _ = gtoSchema opts (Proxy :: Proxy (Rep a)) mempty
123130
124131instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
125− gtoSchema _ = gtoSchema (Proxy :: Proxy f) . gtoSchema (Proxy :: Proxy g)
132+ gtoSchema opts _ = gtoSchema opts (Proxy :: Proxy f) . gtoSchema opts (Proxy :: Proxy g)
126133
127134-- | Single constructor data types.
128135instance GToSchema f => GToSchema (D1 d (C1 c f)) where
129− gtoSchema _ = gtoSchema (Proxy :: Proxy f)
136+ gtoSchema opts _ = gtoSchema opts (Proxy :: Proxy f)
130137
131138appendItem :: Referenced Schema -> Maybe SchemaItems -> Maybe SchemaItems
132139appendItem x Nothing = Just (SchemaItemsArray [x])
@@ -135,7 +142,7 @@ appendItem _ _ = error "GToSchema.appendItem: cannot append to SchemaItemsObject
135142
136143-- | Optional record fields.
137144instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
138− gtoSchema _ schema
145+ gtoSchema opts _ schema
139146 | T.null fieldName = schema
140147 & schemaType .~ SchemaArray
141148 & schemaItems %~ appendItem (Inline fieldSchema)
@@ -143,12 +150,12 @@ instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (
143150 & schemaType .~ SchemaObject
144151 & schemaProperties . at fieldName ?~ Inline fieldSchema
145152 where
146− fieldName = T.pack (selName (undefined :: S1 s f p))
153+ fieldName = T.pack (fieldLabelModifier opts (selName (undefined :: S1 s f p)))
147154 fieldSchema = toSchema (Proxy :: Proxy c)
148155
149156-- | Record fields.
150157instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
151− gtoSchema _ schema
158+ gtoSchema opts _ schema
152159 | T.null fieldName = schema
153160 & schemaType .~ SchemaArray
154161 & schemaItems %~ appendItem (Inline fieldSchema)
@@ -157,9 +164,9 @@ instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) wh
157164 & schemaProperties . at fieldName ?~ Inline fieldSchema
158165 & schemaRequired %~ (fieldName :)
159166 where
160− fieldName = T.pack (selName (undefined :: S1 s f p))
161− fieldSchema = gtoSchema (Proxy :: Proxy f) mempty
167+ fieldName = T.pack (fieldLabelModifier opts (selName (undefined :: S1 s f p)))
168+ fieldSchema = gtoSchema opts (Proxy :: Proxy f) mempty
162169
163170instance ToSchema c => GToSchema (K1 i c) where
164− gtoSchema _ _ = toSchema (Proxy :: Proxy c)
171+ gtoSchema _ _ _ = toSchema (Proxy :: Proxy c)
165172