Skip to content

Commit

Permalink
fix: swagger UI for KYVE
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Dec 14, 2023
1 parent ed63b12 commit e77aed4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"

"github.com/rakyll/statik/fs"

v1p4 "github.com/KYVENetwork/chain/app/upgrades/v1_4"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -32,6 +35,8 @@ import (
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cast"

kyveDocs "github.com/KYVENetwork/chain/docs"

// Auth
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand Down Expand Up @@ -1050,8 +1055,19 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
panic(err)
if apiConfig.Swagger {
statikFS, err := fs.New()
if err != nil {
panic(err)
}

// cosmos swagger ui
staticServer := http.FileServer(statikFS)
apiSvr.Router.PathPrefix("/swagger-cosmos/").Handler(http.StripPrefix("/swagger-cosmos/", staticServer))

// kyve swagger ui
apiSvr.Router.Handle("/swagger.yml", http.FileServer(http.FS(kyveDocs.Swagger)))
apiSvr.Router.HandleFunc("/", kyveDocs.Handler(Name, "/swagger.yml"))
}
}

Expand Down
6 changes: 6 additions & 0 deletions docs/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<link rel="icon" type="image/png" href="//unpkg.com/swagger-ui-dist@latest/favicon-16x16.png" />
</head>
<body>
<div class="swagger-ui">
<div class="information-container wrapper">
<h3>Cosmos - REST API</h3>
The native Cosmos queries can be found at: <a href="/swagger-cosmos/">/swagger-cosmos/</a>
</div>
</div>
<div id="swagger-ui"></div>

<script src="//unpkg.com/swagger-ui-dist@latest/swagger-ui-bundle.js"></script>
Expand Down

0 comments on commit e77aed4

Please sign in to comment.