Skip to content

Commit 8930230

Browse files
authored
feat(server): integrate swagger UI setup
1 parent 2ac2555 commit 8930230

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

server/v2/server.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88
"path/filepath"
99
"strings"
1010

11+
"github.com/cosmos/cosmos-sdk/server/v2/api/swagger"
1112
"github.com/pelletier/go-toml/v2"
1213
"github.com/spf13/cobra"
1314
"github.com/spf13/pflag"
1415

1516
"cosmossdk.io/core/transaction"
1617
"cosmossdk.io/log"
18+
"github.com/rakyll/statik/fs"
1719
)
1820

1921
// ServerComponent is a server component that can be started and stopped.
@@ -73,6 +75,7 @@ var _ ServerComponent[transaction.Tx] = (*Server[transaction.Tx])(nil)
7375
type Server[T transaction.Tx] struct {
7476
components []ServerComponent[T]
7577
config ServerConfig
78+
router *http.ServeMux
7679
}
7780

7881
func NewServer[T transaction.Tx](
@@ -82,6 +85,7 @@ func NewServer[T transaction.Tx](
8285
return &Server[T]{
8386
config: config,
8487
components: components,
88+
router: http.NewServeMux(),
8589
}
8690
}
8791

@@ -242,3 +246,18 @@ func (s *Server[T]) StartFlags() []*pflag.FlagSet {
242246

243247
return flags
244248
}
249+
250+
func (s *Server[T]) setupSwagger() error {
251+
cfg := s.config.API.Swagger
252+
if !cfg.Enable {
253+
return nil
254+
}
255+
256+
statikFS, err := fs.New()
257+
if err != nil {
258+
return err
259+
}
260+
261+
s.router.PathPrefix(cfg.Path).Handler(swagger.Handler(statikFS))
262+
return nil
263+
}

0 commit comments

Comments
 (0)