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

refactor: remove pkg/openapiconsole import in scaffolded chain #3337

Merged
merged 14 commits into from
Dec 26, 2022
Merged
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
- [#3183](https://github.com/ignite/cli/pull/3183/) Make config optional for init phase.
- [#3224](https://github.com/ignite/cli/pull/3224) Remove grpc_* prefix from query files in scaffolded chains
- [#3229](https://github.com/ignite/cli/pull/3229) Rename `campaign` to `project` in ignite network set of commands
- [#3244](https://github.com/ignite/cli/pull/3244) updated actions.yml for resolving deprecation message
- [#3244](https://github.com/ignite/cli/pull/3244) Update actions.yml for resolving deprecation message
- [#3337](https://github.com/ignite/cli/pull/3337) Remove `pkg/openapiconsole` import from scaffold template.

### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func generateOpenAPISpec(g *generator) error {
return nil
}

// protoc openapi generator acts weird on conccurrent run, so do not use goroutines here.
// protoc openapi generator acts weird on concurrent run, so do not use goroutines here.
if err := add(g.appPath, g.appModules); err != nil {
return err
}
Expand Down
41 changes: 23 additions & 18 deletions ignite/templates/app/files/app/app.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package app
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -102,7 +102,6 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"
"github.com/ignite/cli/ignite/pkg/openapiconsole"

// this line is used by starport scaffolding # stargate/app/moduleImport

Expand Down Expand Up @@ -492,7 +491,7 @@ func New(

// this line is used by starport scaffolding # stargate/app/keeperDefinition

/**** IBC Routing ****/
/**** IBC Routing ****/

// Sealing prevents other modules from creating scoped sub-keepers
app.CapabilityKeeper.Seal()
Expand All @@ -506,21 +505,21 @@ func New(

/**** Module Hooks ****/

// register hooks after all modules have been initialized
// register hooks after all modules have been initialized

app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
// insert staking hooks receivers here
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
),
)
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
// insert staking hooks receivers here
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
),
)

app.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// insert governance hooks receivers here
),
)
app.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// insert governance hooks receivers here
),
)

/**** Module Options ****/

Expand Down Expand Up @@ -815,13 +814,14 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register node gRPC service for grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml"))
docs.RegisterOpenAPIService(Name, apiSvr.Router)
}

// RegisterTxService implements the Application.RegisterTxService method.
Expand All @@ -839,6 +839,11 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
)
}

// RegisterNodeService implements the Application.RegisterNodeService method.
func (app *App) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
Expand Down
33 changes: 32 additions & 1 deletion ignite/templates/app/files/docs/docs.go.plush
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
package docs

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

"github.com/gorilla/mux"
)

const apiFile = "/static/openapi.yml"

//go:embed static
var Docs embed.FS

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

func RegisterOpenAPIService(appName string, rtr *mux.Router) {
rtr.Handle(apiFile, http.FileServer(http.FS(Docs)))
rtr.HandleFunc("/", handler(appName, apiFile))
}

// handler returns an 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,
})
}
}
28 changes: 28 additions & 0 deletions ignite/templates/app/files/docs/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{{ .Title }}</title>
<link rel="stylesheet" type="text/css" href="//unpkg.com/[email protected]/swagger-ui.css" />
<link rel="icon" type="image/png" href="//unpkg.com/[email protected]/favicon-16x16.png" />
</head>
<body>
<div id="swagger-ui"></div>

<script src="//unpkg.com/[email protected]/swagger-ui-bundle.js"></script>
<script>
// init Swagger for faucet's openapi.yml.
window.onload = function() {
window.ui = SwaggerUIBundle({
url: {{ .URL }},
dom_id: "#swagger-ui",
deepLinking: true,
layout: "BaseLayout",
});
}
</script>
</body>
</html>
Footer
© 2022 GitHub, Inc.
Footer navigation