3
3
{-# LANGUAGE DataKinds #-}
4
4
{-# LANGUAGE FlexibleContexts #-}
5
5
{-# LANGUAGE FlexibleInstances #-}
6
+ {-# LANGUAGE OverloadedLists #-}
6
7
{-# LANGUAGE OverloadedStrings #-}
7
8
{-# LANGUAGE PolyKinds #-}
8
9
{-# LANGUAGE RankNTypes #-}
9
10
{-# LANGUAGE ScopedTypeVariables #-}
10
11
{-# LANGUAGE TypeOperators #-}
12
+ {-# LANGUAGE TypeFamilies #-}
11
13
#if __GLASGOW_HASKELL__ >= 806
12
14
{-# LANGUAGE UndecidableInstances #-}
13
15
#endif
@@ -30,11 +32,13 @@ import qualified Data.Swagger as Swagger
30
32
import Data.Swagger.Declare
31
33
import Data.Text (Text )
32
34
import qualified Data.Text as Text
35
+ import GHC.Generics (D1 , Meta (.. ), Rep )
33
36
import GHC.TypeLits
34
37
import Network.HTTP.Media (MediaType )
35
38
import Servant.API
36
39
import Servant.API.Description (FoldDescription ,
37
40
reflectDescription )
41
+ import Servant.API.Generic (ToServantApi , AsApi )
38
42
import Servant.API.Modifiers (FoldRequired )
39
43
40
44
import Servant.Swagger.Internal.TypeLevel.API
@@ -149,6 +153,10 @@ mkEndpointNoContentVerb path _ = mempty
149
153
addParam :: Param -> Swagger -> Swagger
150
154
addParam param = allOperations. parameters %~ (Inline param : )
151
155
156
+ -- | Add a tag to every operation in the spec.
157
+ addTag :: Text -> Swagger -> Swagger
158
+ addTag tag = allOperations. tags %~ ([tag] <> )
159
+
152
160
-- | Add accepted content types to every operation in the spec.
153
161
addConsumes :: [MediaType ] -> Swagger -> Swagger
154
162
addConsumes cs = allOperations. consumes %~ (<> Just (MimeList cs))
@@ -439,6 +447,9 @@ instance (ToSchema a, Accept ct, HasSwagger sub, KnownSymbol (FoldDescription mo
439
447
& required ?~ True
440
448
& schema .~ ParamBody ref
441
449
450
+ instance (HasSwagger (ToServantApi routes ), KnownSymbol datatypeName , Rep (routes AsApi ) ~ D1 ('MetaData datatypeName moduleName packageName isNewtype ) f ) => HasSwagger (NamedRoutes routes ) where
451
+ toSwagger _ = addTag (Text. pack $ symbolVal (Proxy :: Proxy datatypeName )) (toSwagger (Proxy :: Proxy (ToServantApi routes )))
452
+
442
453
-- =======================================================================
443
454
-- Below are the definitions that should be in Servant.API.ContentTypes
444
455
-- =======================================================================
0 commit comments