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