refactor: helper method for register swagger api (#12955)

* refactor: helper method for register swagger api

* updates swagger.yaml

* `make update-swagger-docs`
This commit is contained in:
Julien Robert
2022-08-18 12:19:27 +02:00
committed by GitHub
parent e397434d9e
commit 72b1a39238
7 changed files with 3334 additions and 45 deletions
-3
View File
@@ -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.
+29
View File
@@ -0,0 +1,29 @@
package server
import (
"fmt"
"net/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)
// RegisterSwaggerAPI provides a common function which registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool) error {
if !swaggerEnabled {
return nil
}
statikFS, err := fs.New()
if err != nil {
return fmt.Errorf("failed to create filesystem: %w", err)
}
staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
return nil
}