github.com/cosmos/cosmos-sdk@v0.50.10/server/swagger.go (about) 1 package server 2 3 import ( 4 "io/fs" 5 "net/http" 6 7 "github.com/gorilla/mux" 8 9 "github.com/cosmos/cosmos-sdk/client" 10 "github.com/cosmos/cosmos-sdk/client/docs" 11 ) 12 13 // RegisterSwaggerAPI provides a common function which registers swagger route with API Server 14 func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool) error { 15 if !swaggerEnabled { 16 return nil 17 } 18 19 root, err := fs.Sub(docs.SwaggerUI, "swagger-ui") 20 if err != nil { 21 return err 22 } 23 24 staticServer := http.FileServer(http.FS(root)) 25 rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) 26 27 return nil 28 }