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

Backport: Update swagger generation for 1.19: #2070. #2075

Merged
merged 2 commits into from
Jul 11, 2024
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
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ linters-settings:

- github.com/provenance-io/provenance

- github.com/rakyll/statik/fs

- github.com/spf13/cast
- github.com/spf13/cobra
- github.com/spf13/pflag
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* Update the Swagger API documentation [#2063](https://github.com/provenance-io/provenance/pull/2063).
* Update all the proto links in the spec docs to point to `v1.19.0` versions of the proto files [#2068](https://github.com/provenance-io/provenance/pull/2068).
* Add the (empty) `umber-rc2` upgrade [#2069](https://github.com/provenance-io/provenance/pull/2069).

Expand Down
18 changes: 5 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ clean:
rm -rf $(BUILDDIR)/*

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" -not -path "*/statik*" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" -not -path "*/statik*" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" -not -path "*/statik*" | xargs goimports -w -local github.com/provenance-io/provenance
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs goimports -w -local github.com/provenance-io/provenance

check-built:
@if [ ! -f "$(BUILDDIR)/provenanced" ]; then \
Expand Down Expand Up @@ -455,9 +455,9 @@ indexer-db-down:
##############################
# Proto -> golang compilation
##############################
proto-all: proto-update-deps proto-format proto-lint proto-check-breaking proto-check-breaking-third-party proto-gen update-swagger-docs
proto-all: proto-update-deps proto-format proto-lint proto-check-breaking proto-check-breaking-third-party proto-gen proto-swagger-gen
proto-checks: proto-update-deps proto-lint proto-check-breaking proto-check-breaking-third-party
proto-regen: proto-format proto-gen update-swagger-docs
proto-regen: proto-format proto-gen proto-swagger-gen

containerProtoVer=0.14.0
containerProtoImage=ghcr.io/cosmos/proto-builder:$(containerProtoVer)
Expand Down Expand Up @@ -527,14 +527,6 @@ proto-update-deps:
.PHONY: proto-all proto-checks proto-regen proto-gen proto-format proto-lint proto-check-breaking proto-check-breaking-third-party proto-update-deps proto-update-check


##############################
### Docs
##############################
update-swagger-docs: statik proto-swagger-gen
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m

.PHONY: update-swagger-docs

##############################
### Relayer
##############################
Expand Down
27 changes: 16 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"encoding/json"
"io"
"io/fs"
"net/http"
"os"
"path/filepath"
Expand All @@ -13,7 +14,6 @@ import (
wasmv2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"github.com/spf13/viper"

Expand Down Expand Up @@ -137,6 +137,7 @@ import (
ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"

simappparams "github.com/provenance-io/provenance/app/params"
"github.com/provenance-io/provenance/client/docs"
"github.com/provenance-io/provenance/internal/antewrapper"
piohandlers "github.com/provenance-io/provenance/internal/handlers"
"github.com/provenance-io/provenance/internal/pioconfig"
Expand Down Expand Up @@ -185,8 +186,6 @@ import (
triggerkeeper "github.com/provenance-io/provenance/x/trigger/keeper"
triggermodule "github.com/provenance-io/provenance/x/trigger/module"
triggertypes "github.com/provenance-io/provenance/x/trigger/types"

_ "github.com/provenance-io/provenance/client/docs/statik" // registers swagger-ui files with statik
)

var (
Expand Down Expand Up @@ -1277,9 +1276,9 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig serverconfig.API
// Register grpc-gateway routes for all modules.
app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
RegisterSwaggerAPI(clientCtx, apiSvr.Router)
// Register swagger API
if err := RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
panic(err)
}
}

Expand Down Expand Up @@ -1320,15 +1319,21 @@ func (app *App) AutoCliOpts() autocli.AppOptions {
}
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
// RegisterSwaggerAPI provides a common function which registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool) error {
if !swaggerEnabled {
return nil
}

root, err := fs.Sub(docs.SwaggerUI, "swagger-ui")
if err != nil {
panic(err)
return err
}

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

return nil
}

// GetMaccPerms returns a copy of the module account permissions
Expand Down
2 changes: 1 addition & 1 deletion client/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To get a new version of `swagger_third_party.yaml`:

Finally, to update the rest of the swagger files (regardless of whether the 3rd party file needed updating), run this command:
```bash
> make update-swagger-docs
> make proto-swagger-gen
```

Commit any files with changes so they can be included in a PR.
Expand Down
Loading
Loading