Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add back swagger UI for KYVE and Cosmos REST queries #163

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading