Skip to content

Commit

Permalink
fix: add back swagger UI for KYVE and Cosmos REST queries (backport #163
Browse files Browse the repository at this point in the history
) (#168)

Co-authored-by: Maximilian Breithecker <72022235+mbreithecker@users.noreply.github.com>
  • Loading branch information
mergify[bot] and mbreithecker authored Dec 14, 2023
1 parent 9d4519e commit 92503d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ An '!' indicates a state machine breaking change.

- (`x/query`) [#159](https://github.com/KYVENetwork/chain/pull/159) Add pool params back to kyve params query.
- (`x/query`) [#160](https://github.com/KYVENetwork/chain/pull/160) Add funders back to pool query.
- [#163](https://github.com/KYVENetwork/chain/pull/163) Add back swagger UI for KYVE and Cosmos REST queries.

## [v1.4.0](https://github.com/KYVENetwork/chain/releases/tag/v1.4.0) - 2023-11-17

Expand Down
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 92503d5

Please sign in to comment.