Skip to content

Commit

Permalink
feat: use Buf for proto generation (#359)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Johnson <[email protected]>
  • Loading branch information
2 people authored and Joe Bowman committed Mar 28, 2023
1 parent 01554e7 commit e0165c2
Show file tree
Hide file tree
Showing 128 changed files with 5,280 additions and 8,639 deletions.
19 changes: 4 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v5/testing/types"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/ingenuity-build/quicksilver/app/keepers"
"github.com/ingenuity-build/quicksilver/docs"
airdroptypes "github.com/ingenuity-build/quicksilver/x/airdrop/types"
interchainstakingtypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types"
)
Expand Down Expand Up @@ -352,9 +351,10 @@ func (app *Quicksilver) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.A

ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
// register swagger API
if apiConfig.Swagger {
RegisterSwaggerAPI(clientCtx, apiSvr.Router)
apiSvr.Router.Handle("/swagger.yml", http.FileServer(http.FS(docs.Swagger)))
apiSvr.Router.HandleFunc("/", docs.Handler(Name, "/swagger.yml"))
}
}

Expand Down Expand Up @@ -400,17 +400,6 @@ func (app *Quicksilver) GetTxConfig() client.TxConfig {
return cfg.TxConfig
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
if err != nil {
panic(err)
}

staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
Expand Down
1 change: 0 additions & 1 deletion buf.work.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: v1
directories:
- proto
- third_party/proto
122 changes: 122 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"swagger": "2.0",
"info": {
"title": "Quicksilver Chain - REST API",
"description": "REST interface for query and transaction services",
"version": "1.0.0"
},
"apis": [
{
"url": "./tmp-swagger-gen/quicksilver/airdrop/v1/messages.swagger.json"
},
{
"url": "./tmp-swagger-gen/quicksilver/airdrop/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "AirdropParams"
}
},
"tags": {
"rename": {
"Query": "QueryAirdrop"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/claimsmanager/v1/messages.swagger.json"
},
{
"url": "./tmp-swagger-gen/quicksilver/claimsmanager/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "ClaimsManagerParams"
}
},
"tags": {
"rename": {
"Query": "QueryClaimsManager"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/epochs/v1/query.swagger.json",
"tags": {
"rename": {
"Query": "QueryEpochs"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/interchainquery/v1/messages.swagger.json",
},
{
"url": "./tmp-swagger-gen/quicksilver/interchainquery/v1/query.swagger.json",
"tags": {
"rename": {
"QuerySrvr": "QueryInterchainQuery"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/interchainstaking/v1/messages.swagger.json"
},
{
"url": "./tmp-swagger-gen/quicksilver/interchainstaking/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "InterchainStakingParams"
}
},
"tags": {
"rename": {
"Query": "QueryInterchainStaking"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/mint/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "MintParams"
}
},
"tags": {
"rename": {
"Query": "QueryMint"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/participationrewards/v1/messages.swagger.json"
},
{
"url": "./tmp-swagger-gen/quicksilver/participationrewards/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "ParticipationRewardsParams"
}
},
"tags": {
"rename": {
"Query": "QueryParticipationRewards"
}
}
},
{
"url": "./tmp-swagger-gen/quicksilver/tokenfactory/v1beta1/tx.swagger.json"
},
{
"url": "./tmp-swagger-gen/quicksilver/tokenfactory/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "TokenFactoryParams"
}
},
"tags": {
"rename": {
"Query": "QueryTokenFactory"
}
}
}
]
}
8 changes: 8 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package docs

import "embed"

// Swagger is the data of the swagger page generated by protobuf
//
//go:embed swagger.yml
var Swagger embed.FS
27 changes: 27 additions & 0 deletions docs/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// https://github.com/ignite/cli/blob/main/ignite/pkg/openapiconsole/console.go

package docs

import (
"embed"
"html/template"
"net/http"
)

//go:embed index.tpl
var index embed.FS

// Handler returns a http handler that servers OpenAPI console for an OpenAPI spec at specURL.
func Handler(title, specURL string) http.HandlerFunc {
t, _ := template.ParseFS(index, "index.tpl")

return func(w http.ResponseWriter, req *http.Request) {
_ = t.Execute(w, struct {
Title string
URL string
}{
title,
specURL,
})
}
}
24 changes: 24 additions & 0 deletions docs/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{{ .Title }}</title>
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist@latest/swagger-ui.css" />
<link rel="icon" type="image/png" href="//unpkg.com/swagger-ui-dist@latest/favicon-16x16.png" />
</head>
<body>
<div id="swagger-ui"></div>

<script src="//unpkg.com/swagger-ui-dist@latest/swagger-ui-bundle.js"></script>
<script>
window.onload = function() {
window.ui = SwaggerUIBundle({
url: {{ .URL }},
dom_id: "#swagger-ui",
deepLinking: true,
layout: "BaseLayout",
});
}
</script>
</body>
</html>
Loading

0 comments on commit e0165c2

Please sign in to comment.