Commit b2ed29cf 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 07b7a6b7
...@@ -15,6 +15,7 @@ module Gargantext.API.Routes.Named ( ...@@ -15,6 +15,7 @@ module Gargantext.API.Routes.Named (
, ForgotPasswordAPI(..) , ForgotPasswordAPI(..)
, ForgotPasswordAsyncAPI(..) , ForgotPasswordAsyncAPI(..)
, GargVersion(..) , GargVersion(..)
, module Gargantext.API.Routes.Named.Private
) where ) where
import Data.Text (Text) import Data.Text (Text)
...@@ -74,10 +75,9 @@ data GargAPI' mode = GargAPI' ...@@ -74,10 +75,9 @@ data GargAPI' mode = GargAPI'
, gargForgotPasswordAsyncAPI :: mode :- "async" :> "forgot-password" :> NamedRoutes ForgotPasswordAsyncAPI , gargForgotPasswordAsyncAPI :: mode :- "async" :> "forgot-password" :> NamedRoutes ForgotPasswordAsyncAPI
, gargVersionAPI :: mode :- NamedRoutes GargVersion , gargVersionAPI :: mode :- NamedRoutes GargVersion
, gargPrivateAPI :: mode :- NamedRoutes GargPrivateAPI , gargPrivateAPI :: mode :- NamedRoutes GargPrivateAPI
, gargPublicAPI :: mode :- "public" :> NamedRoutes GargPublicAPI , gargPublicAPI :: mode :- NamedRoutes GargPublicAPI
} deriving Generic } deriving Generic
newtype AuthAPI mode = AuthAPI newtype AuthAPI mode = AuthAPI
{ authEp :: mode :- "auth" :> Summary "AUTH API" { authEp :: mode :- "auth" :> Summary "AUTH API"
:> ReqBody '[JSON] AuthRequest :> ReqBody '[JSON] AuthRequest
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
module Gargantext.API.Routes.Named.Public ( module Gargantext.API.Routes.Named.Public (
-- * Routes types -- * Routes types
GargPublicAPI(..) GargPublicAPI'(..)
, GargPublicAPI(..)
, HomeAPI(..) , HomeAPI(..)
, NodeAPI(..) , NodeAPI(..)
) where ) where
...@@ -13,8 +14,11 @@ import Gargantext.API.Routes.Named.File (FileAPI) ...@@ -13,8 +14,11 @@ import Gargantext.API.Routes.Named.File (FileAPI)
import Gargantext.Database.Admin.Types.Node ( NodeId ) import Gargantext.Database.Admin.Types.Node ( NodeId )
import Servant.API 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 { publicHomeAPI :: mode :- NamedRoutes HomeAPI
, publicNodeAPI :: mode :- NamedRoutes NodeAPI , publicNodeAPI :: mode :- NamedRoutes NodeAPI
} deriving Generic } deriving Generic
......
...@@ -26,8 +26,8 @@ import Servant ...@@ -26,8 +26,8 @@ import Servant
import Servant.Server.Generic (AsServerT) import Servant.Server.Generic (AsServerT)
serverPublicGargAPI :: IsGargServer env err m => Text -> Named.GargPublicAPI (AsServerT m) serverPublicGargAPI :: IsGargServer env err m => Text -> Named.GargPublicAPI (AsServerT m)
serverPublicGargAPI baseUrl = serverPublicGargAPI baseUrl = Named.GargPublicAPI $
Named.GargPublicAPI Named.GargPublicAPI'
{ publicHomeAPI = api_home baseUrl { publicHomeAPI = api_home baseUrl
, publicNodeAPI = Named.NodeAPI api_node , publicNodeAPI = Named.NodeAPI api_node
} }
......
{-# OPTIONS_GHC -freduction-depth=400 #-} {-# OPTIONS_GHC -freduction-depth=400 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-| {-|
Module : Gargantext.API.Swagger Module : Gargantext.API.Swagger
...@@ -21,17 +23,24 @@ import Control.Lens ((?~)) ...@@ -21,17 +23,24 @@ import Control.Lens ((?~))
import Data.OpenApi (OpenApi) import Data.OpenApi (OpenApi)
import Data.Swagger import Data.Swagger
import Data.Version (showVersion) import Data.Version (showVersion)
import Gargantext.API.Routes.Named.Public qualified as Named
import Gargantext.API.Routes.Named qualified as Named import Gargantext.API.Routes.Named qualified as Named
import Gargantext.Orphans () -- instance HasOpenApi import Gargantext.Orphans () -- instance HasOpenApi
import Gargantext.Prelude import Gargantext.Prelude
import qualified Paths_gargantext as PG -- cabal magic build module import Paths_gargantext qualified as PG -- cabal magic build module
import Servant import Servant
import Servant.OpenApi (toOpenApi) import Servant.OpenApi (toOpenApi)
import Servant.Swagger import Servant.Swagger
backendApiProxy :: Proxy (ToServantApi Named.BackEndAPI) backendApiProxy :: Proxy (NamedRoutes (Named.MkBackEndAPI (Named.GargAPIVersion Named.GargAPI')))
backendApiProxy = Proxy 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` -- | OpenAPI Specification. It supports programmatically adding the `Bearer` to the `Authorization`
-- header, which makes the Swagger UI actually useable, unlike the 'swaggerDoc' counterpart which -- header, which makes the Swagger UI actually useable, unlike the 'swaggerDoc' counterpart which
-- is stuck on version 2.x of the OpenAPI spec. -- is stuck on version 2.x of the OpenAPI spec.
...@@ -41,7 +50,11 @@ openApiDoc = toOpenApi backendApiProxy ...@@ -41,7 +50,11 @@ openApiDoc = toOpenApi backendApiProxy
& info.version .~ (cs $ showVersion PG.version) & info.version .~ (cs $ showVersion PG.version)
& info.description ?~ "REST API specifications" & info.description ?~ "REST API specifications"
& applyTagsFor (subOperations backendApiProxy backendApiProxy) & 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 ) & info.license ?~ ("AGPLV3 (English) and CECILL (French)" & url ?~ URL urlLicence )
where where
urlLicence = "https://gitlab.iscpif.fr/gargantext/haskell-gargantext/blob/master/LICENSE" 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