Commit bdc9a9be authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add 3 basic categories to swagger UI

This commit adds three major tags to the swagger UI:

* Gargantext (like before): this spells out all the endpoints;
* Private operations: lists private backend ops;
* Public  operations: lists public backend ops.

More can be added, but the machinery used here should serve as a
blueprint.
parent 246321a8
Pipeline #7065 failed with stages
in 34 minutes and 29 seconds
......@@ -15,6 +15,7 @@ module Gargantext.API.Routes.Named (
, ForgotPasswordAPI(..)
, ForgotPasswordAsyncAPI(..)
, GargVersion(..)
, module Gargantext.API.Routes.Named.Private
) where
import Data.Text (Text)
......@@ -74,10 +75,9 @@ data GargAPI' mode = GargAPI'
, gargForgotPasswordAsyncAPI :: mode :- "async" :> "forgot-password" :> NamedRoutes ForgotPasswordAsyncAPI
, gargVersionAPI :: mode :- NamedRoutes GargVersion
, gargPrivateAPI :: mode :- NamedRoutes GargPrivateAPI
, gargPublicAPI :: mode :- "public" :> NamedRoutes GargPublicAPI
, gargPublicAPI :: mode :- NamedRoutes GargPublicAPI
} deriving Generic
newtype AuthAPI mode = AuthAPI
{ authEp :: mode :- "auth" :> Summary "AUTH API"
:> ReqBody '[JSON] AuthRequest
......
......@@ -2,7 +2,8 @@
module Gargantext.API.Routes.Named.Public (
-- * Routes types
GargPublicAPI(..)
GargPublicAPI'(..)
, GargPublicAPI(..)
, HomeAPI(..)
, NodeAPI(..)
) where
......@@ -13,8 +14,11 @@ import Gargantext.API.Routes.Named.File
import Gargantext.Database.Admin.Types.Node ( NodeId )
import Servant.API
newtype GargPublicAPI mode = GargPublicAPI
{ gargAPIVersion :: mode :- "public" :> NamedRoutes GargPublicAPI'
} deriving Generic
data GargPublicAPI mode = GargPublicAPI
data GargPublicAPI' mode = GargPublicAPI'
{ publicHomeAPI :: mode :- NamedRoutes HomeAPI
, publicNodeAPI :: mode :- NamedRoutes NodeAPI
} deriving Generic
......
......@@ -26,8 +26,8 @@ import qualified Gargantext.API.Routes.Named.File as Named
import qualified Gargantext.API.Routes.Named.Public as Named
serverPublicGargAPI :: IsGargServer env err m => Text -> Named.GargPublicAPI (AsServerT m)
serverPublicGargAPI baseUrl =
Named.GargPublicAPI
serverPublicGargAPI baseUrl = Named.GargPublicAPI $
Named.GargPublicAPI'
{ publicHomeAPI = api_home baseUrl
, publicNodeAPI = Named.NodeAPI api_node
}
......
{-# OPTIONS_GHC -freduction-depth=400 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-|
Module : Gargantext.API.Swagger
......@@ -18,19 +20,26 @@ module Gargantext.API.Swagger (
) where
import Control.Lens
import Data.Version (showVersion)
import Servant.OpenApi
import Data.OpenApi
import Data.Version (showVersion)
import Paths_gargantext qualified as PG -- cabal magic build module
import Servant
import qualified Paths_gargantext as PG -- cabal magic build module
import Servant.OpenApi
import Gargantext.API.Routes.Named.Public qualified as Named
import Gargantext.API.Routes.Named qualified as Named
import Gargantext.Prelude
import Gargantext.Orphans () -- instance HasOpenApi
import Gargantext.Prelude
backendApiProxy :: Proxy (ToServantApi Named.BackEndAPI)
backendApiProxy :: Proxy (NamedRoutes (Named.MkBackEndAPI (Named.GargAPIVersion Named.GargAPI')))
backendApiProxy = Proxy
privateOps :: Proxy (NamedRoutes (Named.MkBackEndAPI (Named.GargAPIVersion Named.GargPrivateAPI)))
privateOps = Proxy
publicOps :: Proxy (NamedRoutes (Named.MkBackEndAPI (Named.GargAPIVersion Named.GargPublicAPI)))
publicOps = Proxy
-- | OpenAPI Specification. It supports programmatically adding the `Bearer` to the `Authorization`
-- header, which makes the Swagger UI actually useable, unlike the 'swaggerDoc' counterpart which
-- is stuck on version 2.x of the OpenAPI spec.
......@@ -40,7 +49,11 @@ openApiDoc = toOpenApi backendApiProxy
& info.version .~ (cs $ showVersion PG.version)
& info.description ?~ "REST API specifications"
& applyTagsFor (subOperations backendApiProxy backendApiProxy)
["Gargantext" & description ?~ "Main operations"]
["Gargantext" & description ?~ "All operations"]
& applyTagsFor (subOperations privateOps backendApiProxy)
["Private operations" & description ?~ "Operations requiring authentications"]
& applyTagsFor (subOperations publicOps backendApiProxy)
["Public operations" & description ?~ "Operations which don't require a valid authentication"]
& info.license ?~ ("AGPLV3 (English) and CECILL (French)" & url ?~ URL urlLicence )
where
urlLicence = "https://gitlab.iscpif.fr/gargantext/haskell-gargantext/blob/master/LICENSE"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment