Skip to content

Commit

Permalink
feat(server): integrate swagger UI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
crStiv authored Dec 25, 2024
1 parent 2ac2555 commit 8930230
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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](
Expand All @@ -82,6 +85,7 @@ func NewServer[T transaction.Tx](
return &Server[T]{
config: config,
components: components,
router: http.NewServeMux(),
}
}

Expand Down Expand Up @@ -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
}

0 comments on commit 8930230

Please sign in to comment.