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:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user