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,12 +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 (Rep , datatypeName , D1 , Meta (.. ))
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 )
38
- import Servant.API.Generic (ToServantApi )
41
+ import Servant.API.Generic (ToServantApi , AsApi )
39
42
import Servant.API.Modifiers (FoldRequired )
40
43
41
44
import Servant.Swagger.Internal.TypeLevel.API
@@ -150,6 +153,10 @@ mkEndpointNoContentVerb path _ = mempty
150
153
addParam :: Param -> Swagger -> Swagger
151
154
addParam param = allOperations. parameters %~ (Inline param : )
152
155
156
+ -- | Add a tag to every operation in the spec.
157
+ addTag :: Text -> Swagger -> Swagger
158
+ addTag tag = allOperations. tags %~ ([tag] <> )
159
+
153
160
-- | Add accepted content types to every operation in the spec.
154
161
addConsumes :: [MediaType ] -> Swagger -> Swagger
155
162
addConsumes cs = allOperations. consumes %~ (<> Just (MimeList cs))
@@ -440,8 +447,8 @@ instance (ToSchema a, Accept ct, HasSwagger sub, KnownSymbol (FoldDescription mo
440
447
& required ?~ True
441
448
& schema .~ ParamBody ref
442
449
443
- instance HasSwagger (ToServantApi routes ) => HasSwagger (NamedRoutes routes ) where
444
- toSwagger _ = toSwagger (Proxy :: Proxy (ToServantApi routes ))
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 ) ))
445
452
446
453
-- =======================================================================
447
454
-- Below are the definitions that should be in Servant.API.ContentTypes
0 commit comments