From 8930230caad5c29b127368004aa4858a237f0560 Mon Sep 17 00:00:00 2001 From: crStiv Date: Wed, 25 Dec 2024 21:00:44 +0100 Subject: [PATCH] feat(server): integrate swagger UI setup --- server/v2/server.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/v2/server.go b/server/v2/server.go index 9f4f3ee66e58..e2eb97bca79b 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -8,12 +8,14 @@ import ( "path/filepath" "strings" + "github.com/cosmos/cosmos-sdk/server/v2/api/swagger" "github.com/pelletier/go-toml/v2" "github.com/spf13/cobra" "github.com/spf13/pflag" "cosmossdk.io/core/transaction" "cosmossdk.io/log" + "github.com/rakyll/statik/fs" ) // ServerComponent is a server component that can be started and stopped. @@ -73,6 +75,7 @@ var _ ServerComponent[transaction.Tx] = (*Server[transaction.Tx])(nil) type Server[T transaction.Tx] struct { components []ServerComponent[T] config ServerConfig + router *http.ServeMux } func NewServer[T transaction.Tx]( @@ -82,6 +85,7 @@ func NewServer[T transaction.Tx]( return &Server[T]{ config: config, components: components, + router: http.NewServeMux(), } } @@ -242,3 +246,18 @@ func (s *Server[T]) StartFlags() []*pflag.FlagSet { return flags } + +func (s *Server[T]) setupSwagger() error { + cfg := s.config.API.Swagger + if !cfg.Enable { + return nil + } + + statikFS, err := fs.New() + if err != nil { + return err + } + + s.router.PathPrefix(cfg.Path).Handler(swagger.Handler(statikFS)) + return nil +}