Skip to content

Commit

Permalink
Add grpc gateway missing endpoints to swagger docs (cosmos#8232)
Browse files Browse the repository at this point in the history
* Add missing endpoints

* Fix swagger gen

* update

* Update static.go

* Fix format

* Fix tests
  • Loading branch information
anilcse authored Jan 1, 2021
1 parent ed7bd24 commit 6a9b0ca
Show file tree
Hide file tree
Showing 10 changed files with 25,527 additions and 14,884 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ go.sum: go.mod
### Documentation ###
###############################################################################

update-swagger-docs: statik
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
else \
echo "\033[92mSwagger docs are in sync\033[0m";\
fi
.PHONY: update-swagger-docs

godocs:
@echo "--> Wait a few seconds and visit http://localhost:6060/pkg/github.com/cosmos/cosmos-sdk/types"
godoc -http=:6060
Expand Down
14 changes: 14 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/base/tendermint/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "BaseParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/distribution/v1beta1/query.swagger.json",
"operationIds": {
Expand Down Expand Up @@ -85,6 +93,12 @@
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/tx/v1beta1/service.swagger.json",
"dereference": {
"circular": "ignore"
}
},
{
"url": "./tmp-swagger-gen/cosmos/upgrade/v1beta1/query.swagger.json",
"operationIds": {
Expand Down
9 changes: 5 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

40,115 changes: 25,369 additions & 14,746 deletions client/docs/swagger-ui/swagger.yaml

Large diffs are not rendered by default.

136 changes: 68 additions & 68 deletions client/grpc/tmservice/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/grpc/tmservice/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions client/grpc/tmservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func (s IntegrationTestSuite) TestQueryLatestValidatorSet() {
s.Require().NoError(err)

// rest request without pagination
_, err = rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validators/latest", val.APIAddress))
_, err = rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", val.APIAddress))
s.Require().NoError(err)

// rest request with pagination
restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validators/latest?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 0, 1))
restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 0, 1))
s.Require().NoError(err)
var validatorSetRes tmservice.GetLatestValidatorSetResponse
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(restRes, &validatorSetRes))
Expand Down Expand Up @@ -150,11 +150,11 @@ func (s IntegrationTestSuite) TestQueryValidatorSetByHeight() {
s.Require().NoError(err)

// no pagination rest
_, err = rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validators/%d", val.APIAddress, 1))
_, err = rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", val.APIAddress, 1))
s.Require().NoError(err)

// rest query with pagination
restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validators/%d?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 1, 0, 1))
restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 1, 0, 1))
var validatorSetRes tmservice.GetValidatorSetByHeightResponse
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(restRes, &validatorSetRes))
}
Expand Down
4 changes: 2 additions & 2 deletions proto/cosmos/base/tendermint/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ service Service {

// GetLatestValidatorSet queries latest validator-set.
rpc GetLatestValidatorSet(GetLatestValidatorSetRequest) returns (GetLatestValidatorSetResponse) {
option (google.api.http).get = "/cosmos/base/tendermint/v1beta1/validators/latest";
option (google.api.http).get = "/cosmos/base/tendermint/v1beta1/validatorsets/latest";
}
// GetValidatorSetByHeight queries validator-set at a given height.
rpc GetValidatorSetByHeight(GetValidatorSetByHeightRequest) returns (GetValidatorSetByHeightResponse) {
option (google.api.http).get = "/cosmos/base/tendermint/v1beta1/validators/{height}";
option (google.api.http).get = "/cosmos/base/tendermint/v1beta1/validatorsets/{height}";
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/protoc-swagger-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1
for dir in $proto_dirs; do

# generate swagger files (filter query files)
query_file=$(find "${dir}" -maxdepth 1 -name 'query.proto')
query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \))
if [[ ! -z "$query_file" ]]; then
buf protoc \
-I "proto" \
Expand Down
Loading

0 comments on commit 6a9b0ca

Please sign in to comment.