From f5db11ec41fb7d72f9a544760312f61c380b8b75 Mon Sep 17 00:00:00 2001 From: deepto Date: Sat, 25 Jun 2022 03:44:34 +0530 Subject: [PATCH 1/9] added re-usable helper method for RegisterSwaggerAPI --- baseapp/register_swagger_api.go | 21 +++++++++++++++++++++ simapp/app.go | 21 ++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 baseapp/register_swagger_api.go diff --git a/baseapp/register_swagger_api.go b/baseapp/register_swagger_api.go new file mode 100644 index 00000000000..8f1f80de9c2 --- /dev/null +++ b/baseapp/register_swagger_api.go @@ -0,0 +1,21 @@ +package baseapp + +import ( + "net/http" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/gorilla/mux" + "github.com/rakyll/statik/fs" +) + +// RegisterSwaggerAPI - a common function which registers swagger route with API Server +func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool) { + if swaggerEnabled { + statikFS, err := fs.New() + if err != nil { + panic(err) + } + staticServer := http.FileServer(statikFS) + rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) + } +} diff --git a/simapp/app.go b/simapp/app.go index 0f4c8536121..bf2d3b6e23d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -3,12 +3,9 @@ package simapp import ( _ "embed" "io" - "net/http" "os" "path/filepath" - "github.com/gorilla/mux" - "github.com/rakyll/statik/fs" "github.com/spf13/cast" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" @@ -19,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -418,21 +414,8 @@ func (app *SimApp) SimulationManager() *module.SimulationManager { func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { app.App.RegisterAPIRoutes(apiSvr, apiConfig) - // register swagger API from root so that other applications can override easily - if apiConfig.Swagger { - RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router) - } -} - -// RegisterSwaggerAPI registers swagger route with API Server -func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) { - statikFS, err := fs.New() - if err != nil { - panic(err) - } - - staticServer := http.FileServer(statikFS) - rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) + // register swagger API (using common function from baseapp package) from root so that other applications can override easily + baseapp.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger) } // GetMaccPerms returns a copy of the module account permissions From d03703698050d2185fdb4439701ac7e7ca65b800 Mon Sep 17 00:00:00 2001 From: deepto Date: Mon, 4 Jul 2022 00:02:50 +0530 Subject: [PATCH 2/9] moved RegisterSwaggerAPI from baseapp to server, added changelog --- CHANGELOG.md | 2 +- {baseapp => server}/register_swagger_api.go | 2 +- simapp/app.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) rename {baseapp => server}/register_swagger_api.go (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cd1265333b..c85f9f55075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] - +* (server) [\#12352](https://github.com/cosmos/cosmos-sdk/pull/12352) Move the `RegisterSwaggerAPI` logic into a separate helper function in the server package ### Features * (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration. diff --git a/baseapp/register_swagger_api.go b/server/register_swagger_api.go similarity index 96% rename from baseapp/register_swagger_api.go rename to server/register_swagger_api.go index 8f1f80de9c2..a73d7c6d62d 100644 --- a/baseapp/register_swagger_api.go +++ b/server/register_swagger_api.go @@ -1,4 +1,4 @@ -package baseapp +package server import ( "net/http" diff --git a/simapp/app.go b/simapp/app.go index aec29e85986..835daf3402f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/core/appconfig" "github.com/cosmos/cosmos-sdk/depinject" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -408,7 +409,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon app.App.RegisterAPIRoutes(apiSvr, apiConfig) // register swagger API (using common function from baseapp package) from root so that other applications can override easily - baseapp.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger) + server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger) } // GetMaccPerms returns a copy of the module account permissions From 409157b4aae00f009b07d833c91c9f8f9e4d8b9e Mon Sep 17 00:00:00 2001 From: deepto Date: Mon, 4 Jul 2022 09:37:25 +0530 Subject: [PATCH 3/9] removed unused import from spi/server.go, changed swagger file name to swagger.go --- server/api/server.go | 3 --- server/{register_swagger_api.go => swagger.go} | 0 2 files changed, 3 deletions(-) rename server/{register_swagger_api.go => swagger.go} (100%) diff --git a/server/api/server.go b/server/api/server.go index c052c03f52c..b21763b97b8 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -20,9 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/telemetry" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" - - // unnamed import of statik for swagger UI support - _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) // Server defines the server's API interface. diff --git a/server/register_swagger_api.go b/server/swagger.go similarity index 100% rename from server/register_swagger_api.go rename to server/swagger.go From 0b1d51c35f45f3ed3b41bca85e0f8254fd602c45 Mon Sep 17 00:00:00 2001 From: deepto Date: Mon, 4 Jul 2022 09:40:35 +0530 Subject: [PATCH 4/9] fixed comment --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index 835daf3402f..d94a9c9cc96 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -408,7 +408,7 @@ func (app *SimApp) SimulationManager() *module.SimulationManager { func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { app.App.RegisterAPIRoutes(apiSvr, apiConfig) - // register swagger API (using common function from baseapp package) from root so that other applications can override easily + // register swagger API (using common function from server package) from root so that other applications can override easily server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger) } From 84a1dc993478b120b279e4523507ef67045365b9 Mon Sep 17 00:00:00 2001 From: deepto Date: Sun, 10 Jul 2022 18:16:15 +0530 Subject: [PATCH 5/9] fixed changelog message --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c85f9f55075..747610f2999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,13 +36,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] -* (server) [\#12352](https://github.com/cosmos/cosmos-sdk/pull/12352) Move the `RegisterSwaggerAPI` logic into a separate helper function in the server package + ### Features * (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration. ### Improvements - +* [#12352](https://github.com/cosmos/cosmos-sdk/pull/12352) Move the `RegisterSwaggerAPI` logic into a separate helper function in the server package * [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Mark the `TipDecorator` as beta, don't include it in simapp by default. * [#12153](https://github.com/cosmos/cosmos-sdk/pull/12153) Add a new `NewSimulationManagerFromAppModules` constructor, to simplify simulation wiring. * [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module. From 03375ec4f07a23f211d6b637b06a9902b5be9a8f Mon Sep 17 00:00:00 2001 From: deepto Date: Sun, 10 Jul 2022 18:25:17 +0530 Subject: [PATCH 6/9] fix --- simapp/app.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index d01a225c6b5..1c63a2bb7af 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -88,9 +88,6 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - // unnamed import of statik for swagger UI support - _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) var ( From 2e11b03c0d31da2c4c6e742079fb0ed151c1eafe Mon Sep 17 00:00:00 2001 From: Deepto Date: Sun, 10 Jul 2022 23:39:23 +0530 Subject: [PATCH 7/9] Update server/swagger.go Co-authored-by: Aleksandr Bezobchuk --- server/swagger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/swagger.go b/server/swagger.go index a73d7c6d62d..66ac090c1d7 100644 --- a/server/swagger.go +++ b/server/swagger.go @@ -8,7 +8,7 @@ import ( "github.com/rakyll/statik/fs" ) -// RegisterSwaggerAPI - a common function which registers swagger route with API Server +// RegisterSwaggerAPI provides a common function which registers swagger route with API Server func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool) { if swaggerEnabled { statikFS, err := fs.New() From 6ee25b6f074b2e3bdff6ab1fdf9339bf927d7b56 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Jul 2022 21:50:08 +0200 Subject: [PATCH 8/9] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f31a544cc7..312530f151f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry. ### Improvements + * [#12352](https://github.com/cosmos/cosmos-sdk/pull/12352) Move the `RegisterSwaggerAPI` logic into a separate helper function in the server package * [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Mark the `TipDecorator` as beta, don't include it in simapp by default. * [#12153](https://github.com/cosmos/cosmos-sdk/pull/12153) Add a new `NewSimulationManagerFromAppModules` constructor, to simplify simulation wiring. From 896dfa2584b8d0ed33f5bf1432bde40d2d5d8d83 Mon Sep 17 00:00:00 2001 From: Deepto Date: Mon, 18 Jul 2022 20:02:43 +0530 Subject: [PATCH 9/9] Update simapp/app.go Co-authored-by: Julien Robert --- simapp/app.go | 1 - 1 file changed, 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index 1c63a2bb7af..1301ae8432e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -13,7 +13,6 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/server" "cosmossdk.io/depinject"