Skip to content

Commit

Permalink
make swagger gen
Browse files Browse the repository at this point in the history
  • Loading branch information
quaisx committed Mar 21, 2024
1 parent 39c77de commit a07b707
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
21 changes: 21 additions & 0 deletions buf.gen.swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: v1

plugins:

- name: gocosmos
out: .
opt:
- plugins=grpc

- name: grpc-gateway
out: .
opt:
- logtostderr=true

- name: swagger
out: ./tmp-swagger-gen
opt:
- logtostderr=true
- fqn_for_swagger_name=true
- simple_operation_ids=true
strategy: all
5 changes: 0 additions & 5 deletions proto/buf.gen.swagger.yaml

This file was deleted.

38 changes: 30 additions & 8 deletions scripts/protoc-swagger-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
set -eo pipefail

mkdir -p ./tmp-swagger-gen
cd proto
proto_dirs=$(find ./secret -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
# Note: need to add ./third_party/proto/cosmos ./third_party/proto/ibc to a list of proto dirs when imports are fixed
proto_dirs=$(find ./proto ./third_party/proto/cosmos_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' -o -name 'service.proto' \))
Expand All @@ -13,11 +13,33 @@ for dir in $proto_dirs; do
fi
done

cd ..
# 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/docs/config.json -o ./client/docs/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true
#jq 'del(.definitions["cosmos.tx.v1beta1.ModeInfo.Multi"].properties.mode_infos.items["$ref"])' ./tmp-swagger-gen/cosmos/tx/v1beta1/service.swagger.json > ./tmp-swagger-gen/cosmos/tx/v1beta1/fixed-service.swagger.json
# # Tag everything as "gRPC Gateway API"
# perl -i -pe 's/"(Query|Service)"/"gRPC Gateway API"/' $(find ./tmp-swagger-gen -name '*.swagger.json' -print0 | xargs -0)

# clean swagger files
# (
# cd ./client/docs

# # Generate config.json
# # There's some operationIds naming collision, for sake of automation we're
# # giving all of them a unique name
# find ../../tmp-swagger-gen -name 'query.swagger.json' -o -name 'fixed-service.swagger.json' |
# sort |
# awk '{print "{\"url\":\""$1"\",\"operationIds\":{\"rename\":{\"Params\":\""$1"Params\",\"Pool\":\""$1"Pool\",\"DelegatorValidators\":\""$1"DelegatorValidators\",\"UpgradedConsensusState\":\""$1"UpgradedConsensusState\"}}}"}' |
# jq -s '{swagger:"2.0","info":{"title":"Secret Network","description":"A REST interface for queries and transactions","version":"'"${CHAIN_VERSION}"'"},apis:.} | .apis += [{"url":"./swagger_legacy.yaml","dereference":{"circular":"ignore"}}]' > ./config.json

# # Derive openapi & swagger from config.json
# yarn install
# yarn combine
# yarn convert
# yarn build
# )

# cd ..
# # 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/docs/config.json -o ./client/docs/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true

# # clean swagger files
rm -rf ./tmp-swagger-gen

0 comments on commit a07b707

Please sign in to comment.