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

Add swagger for gRPC REST #7075

Merged
merged 34 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3913bd2
swagger gen command added
atheeshp Aug 17, 2020
2bbfd2e
proto file changed
atheeshp Aug 17, 2020
a13bffa
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Aug 17, 2020
1bcdd34
Add filter for swagger files
anilcse Aug 20, 2020
355fb1c
Remove loop
anilcse Aug 20, 2020
60de7ac
Add go-swagger installation
anilcse Aug 20, 2020
e7ee599
Add swagger mixer command
anilcse Aug 20, 2020
4108303
add swagger options
anilcse Aug 21, 2020
c1ce287
remove files
anilcse Aug 21, 2020
4932f48
Fix swagger-combine
anilcse Aug 22, 2020
7babacc
Fix description
anilcse Aug 22, 2020
73a3078
remove unnecessary config option
anilcse Aug 22, 2020
148bce9
remove go-swagger dependency
anilcse Aug 22, 2020
0491866
refactor
anilcse Aug 22, 2020
eeeca44
Add proto-gen-swagger installation tool
anilcse Aug 22, 2020
a9b42cb
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
anilcse Aug 22, 2020
40d1eee
fix tool
anilcse Aug 22, 2020
3fe9a20
refactor
anilcse Aug 22, 2020
747e615
don't push individual swagger files to repo
anilcse Aug 22, 2020
7ced203
refactor
anilcse Aug 22, 2020
e1fcaaa
Fix doc
anilcse Aug 22, 2020
e951e6d
move proto-swagger-gen to a separate target
anilcse Aug 24, 2020
92d925a
Merge branch 'master' into atheesh/5921-swagger-gen
anilcse Aug 26, 2020
81e6289
Fix permissions
anilcse Aug 27, 2020
b219a4c
Merge branch 'master' into atheesh/5921-swagger-gen
anilcse Aug 27, 2020
e5f8ab9
Add ibc swagger gen
anilcse Aug 27, 2020
4518e3b
Merge branch 'atheesh/5921-swagger-gen' of github.com:cosmos/cosmos-s…
anilcse Aug 27, 2020
3f1b6d1
Update swagger generation doc
anilcse Aug 27, 2020
9461dd3
cleanup
anilcse Aug 27, 2020
05512e2
gofmt
anilcse Aug 27, 2020
41d8baf
refactor
anilcse Aug 27, 2020
1b77732
Merge branch 'master' into atheesh/5921-swagger-gen
anilcse Aug 27, 2020
6c63a04
Merge branch 'master' into atheesh/5921-swagger-gen
anilcse Aug 28, 2020
c26067d
update Makefile
fedekunze Aug 28, 2020
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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ go.sum: go.mod
###############################################################################

update-swagger-docs: statik
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
$(BINDIR)/statik -src=client/grpc-gateway -dest=client/grpc-gateway -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
Expand Down Expand Up @@ -312,7 +312,7 @@ devdoc-update:
### Protobuf ###
###############################################################################

proto-all: proto-tools proto-gen proto-lint proto-check-breaking
proto-all: proto-tools proto-gen proto-lint proto-check-breaking proto-swagger-gen

proto-gen:
@./scripts/protocgen.sh
Expand All @@ -321,6 +321,9 @@ proto-gen:
proto-gen-any:
@./scripts/protocgen-any.sh

proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh

proto-lint:
@buf check lint --error-format=json

Expand Down
122 changes: 122 additions & 0 deletions client/grpc-gateway/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"swagger": "2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i'm not mistaken, there's a new version 3, rebranded to OpenAPI. Why don't we use v3 instead? Maybe the merging issue will not even be relevant anymore.

Edit: that's why grpc-ecosystem/grpc-gateway#441. Keeping this comment for an FYI.

"info": {
"title": "Cosmos SDK - GRPC Gateway",
"version": "1.0.0"
},
"apis": [
{
"url": "./cosmos/auth/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "AuthParams"
}
}
},
{
"url": "./cosmos/bank/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "BankParams"
}
}
},
{
"url": "./cosmos/distribution/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "DistributionParams"
}
}
},
{
"url": "./cosmos/evidence/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "EvidenceParams"
}
}
},
{
"url": "./cosmos/gov/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GovParams"
}
}
},
{
"url": "./cosmos/mint/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "MintParams"
}
}
},
{
"url": "./cosmos/params/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "Params"
}
}
},
{
"url": "./cosmos/slashing/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "SlashingParams"
}
}
},
{
"url": "./cosmos/staking/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "StakingParams",
"DelegatorValidators": "StakingDelegatorValidators"
}
}
},
{
"url": "./cosmos/upgrade/v1beta1/query.swagger.json",
anilcse marked this conversation as resolved.
Show resolved Hide resolved
"operationIds": {
"rename": {
"Params": "UpgradeParams"
}
}
},
{
"url": "./ibc/channel/query.swagger.json",
"operationIds": {
"rename": {
"Params": "IBCChannelParams"
}
}
},
{
"url": "./ibc/client/query.swagger.json",
"operationIds": {
"rename": {
"Params": "IBCClientParams"
}
}
},
{
"url": "./ibc/connection/query.swagger.json",
"operationIds": {
"rename": {
"Params": "IBCConnectionParams"
}
}
},
{
"url": "./ibc/transfer/query.swagger.json",
"operationIds": {
"rename": {
"Params": "IBCTransferParams"
}
}
}
]
}
13 changes: 13 additions & 0 deletions client/grpc-gateway/statik/statik.go

Large diffs are not rendered by default.

13,302 changes: 13,302 additions & 0 deletions client/grpc-gateway/swagger.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ else
@echo "protoc-gen-grpc-gateway already installed; skipping..."
endif

ifeq (, $(shell which protoc-gen-swagger))
@echo "Installing protoc-gen-swagger..."
@go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
@npm install -g swagger-combine
else
@echo "protoc-gen-grpc-gateway already installed; skipping..."
endif

buf: buf-stamp

buf-stamp:
Expand Down
25 changes: 25 additions & 0 deletions scripts/protoc-swagger-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
anilcse marked this conversation as resolved.
Show resolved Hide resolved

set -eo pipefail

proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do

# generate swagger files (filter query files)
query_file=$(find "${dir}" -maxdepth 1 -name 'query.proto')
if [[ ! -z "$query_file" ]]; then
protoc \
-I "proto" \
-I "third_party/proto" \
"$query_file" \
--swagger_out=logtostderr=true,stderrthreshold=1000,fqn_for_swagger_name=true,simple_operation_ids=true:.
fi
done

# combine swagger files
# uses nodejs package `swagger-combine`.
# all the individual swagger files need to be configured in `config.json` for merging
swagger-combine ./client/grpc-gateway/config.json -o ./client/grpc-gateway/swagger.json --continueOnConflictingPaths true --includeDefinitions true
anilcse marked this conversation as resolved.
Show resolved Hide resolved

# clean swagger files
find ./ -name 'query.swagger.json' -exec rm {} \;
3 changes: 1 addition & 2 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
-I "third_party/proto" \
--grpc-gateway_out=logtostderr=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')

done

# generate codec/testdata proto code
Expand All @@ -26,5 +27,3 @@ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. ./testutil
# move proto files to the right places
cp -r github.com/cosmos/cosmos-sdk/* ./
rm -rf github.com


6 changes: 3 additions & 3 deletions x/gov/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func TestRandomizedGenState1(t *testing.T) {
module.SimulationState{}, "invalid memory address or nil pointer dereference"},
{ // panic => reason: incomplete initialization of the simState
module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: cdc,
Rand: r,
AppParams: make(simtypes.AppParams),
Cdc: cdc,
Rand: r,
}, "assignment to entry in nil map"},
}

Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() {
suite.Equal(tc.numVals, len(valsResp.Validators))
suite.Equal(uint64(len(vals)), valsResp.Pagination.Total)

if (tc.hasNext) {
if tc.hasNext {
suite.NotNil(valsResp.Pagination.NextKey)
} else {
suite.Nil(valsResp.Pagination.NextKey)
Expand Down
Loading