Skip to content

Commit

Permalink
fix: add back swagger UI for KYVE and Cosmos REST queries (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker authored Dec 14, 2023
1 parent e217046 commit 8105602
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 8105602

Please sign in to comment.