Skip to content

Commit 2c0bf47

Browse files
authored
Merge pull request #125 from aschmois/master
Default Capture To TypeName
2 parents ae8cf9f + 140e342 commit 2c0bf47

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Servant/Swagger/Internal.hs

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
2222
import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
2323
import Data.Foldable (toList)
2424
import Data.Proxy
25+
import Data.Typeable
2526
import Data.Singletons.Bool
2627
import Data.Swagger hiding (Header)
2728
import qualified Data.Swagger as Swagger
@@ -236,13 +237,16 @@ instance (KnownSymbol sym, HasSwagger sub) => HasSwagger (sym :> sub) where
236237
where
237238
piece = symbolVal (Proxy :: Proxy sym)
238239

239-
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub, KnownSymbol (FoldDescription mods)) => HasSwagger (Capture' mods sym a :> sub) where
240+
instance (KnownSymbol sym, Typeable a, ToParamSchema a, HasSwagger sub, KnownSymbol (FoldDescription mods)) => HasSwagger (Capture' mods sym a :> sub) where
240241
toSwagger _ = toSwagger (Proxy :: Proxy sub)
241242
& addParam param
242243
& prependPath capture
243244
& addDefaultResponse404 tname
244245
where
245-
pname = symbolVal (Proxy :: Proxy sym)
246+
symbol = symbolVal (Proxy :: Proxy sym)
247+
pname = if symbol == ""
248+
then camelTo2 '-' . tyConName . typeRepTyCon $ typeRep (Proxy :: Proxy a)
249+
else symbol
246250
tname = Text.pack pname
247251
transDesc "" = Nothing
248252
transDesc desc = Just (Text.pack desc)
@@ -256,7 +260,7 @@ instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub, KnownSymbol (FoldDes
256260
& paramSchema .~ toParamSchema (Proxy :: Proxy a))
257261

258262
-- | Swagger Spec doesn't have a notion of CaptureAll, this instance is the best effort.
259-
instance (KnownSymbol sym, ToParamSchema a, HasSwagger sub) => HasSwagger (CaptureAll sym a :> sub) where
263+
instance (KnownSymbol sym, Typeable a, ToParamSchema a, HasSwagger sub) => HasSwagger (CaptureAll sym a :> sub) where
260264
toSwagger _ = toSwagger (Proxy :: Proxy (Capture sym a :> sub))
261265

262266
instance (KnownSymbol desc, HasSwagger api) => HasSwagger (Description desc :> api) where
@@ -352,7 +356,7 @@ instance (ToSchema a, AllAccept cs, HasSwagger sub, KnownSymbol (FoldDescription
352356
& schema .~ ParamBody ref
353357

354358
-- | This instance is an approximation.
355-
--
359+
--
356360
-- @since 1.1.7
357361
instance (ToSchema a, Accept ct, HasSwagger sub, KnownSymbol (FoldDescription mods)) => HasSwagger (StreamBody' mods fr ct a :> sub) where
358362
toSwagger _ = toSwagger (Proxy :: Proxy sub)

0 commit comments

Comments
 (0)