@@ -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,11 +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 (D1, Meta(..), Rep)
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)
41+import Servant.API.Generic (ToServantApi, AsApi)
38import Servant.API.Modifiers (FoldRequired)
42import Servant.API.Modifiers (FoldRequired)
40import Servant.Swagger.Internal.TypeLevel.API
44import Servant.Swagger.Internal.TypeLevel.API
@@ -149,6 +153,10 @@ mkEndpointNoContentVerb path _ = mempty
149addParam :: Param -> Swagger -> Swagger
153addParam :: Param -> Swagger -> Swagger
150addParam 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] <>)
152-- | Add accepted content types to every operation in the spec.
160-- | Add accepted content types to every operation in the spec.
153addConsumes :: [MediaType] -> Swagger -> Swagger
161addConsumes :: [MediaType] -> Swagger -> Swagger
154addConsumes cs = allOperations.consumes %~ (<> Just (MimeList cs))
162addConsumes cs = allOperations.consumes %~ (<> Just (MimeList cs))
@@ -439,6 +447,9 @@ instance (ToSchema a, Accept ct, HasSwagger sub, KnownSymbol (FoldDescription mo
439 & required ?~ True
447 & required ?~ True
440 & schema .~ ParamBody ref
448 & schema .~ ParamBody ref
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)))
442-- =======================================================================
453-- =======================================================================
443-- Below are the definitions that should be in Servant.API.ContentTypes
454-- Below are the definitions that should be in Servant.API.ContentTypes
444-- =======================================================================
455-- =======================================================================