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

feat: swagger.yaml #2818

Closed
wants to merge 17 commits into from
Closed
129 changes: 129 additions & 0 deletions docs/swagger-ui/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
rootulp marked this conversation as resolved.
Show resolved Hide resolved
"swagger": "2.0",
"info": {
"description": "Source code for the Celestia Blockchain",
"version": "1.3.0"
},
"apis": [
{
"url": "./cosmos/auth/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "AuthParams"
}
}
},
{
"url": "./cosmos/authz/v1beta1/query.swagger.json"
},
{
"url": "./cosmos/bank/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "BankParams"
}
}
},
{
"url": "./cosmos/base/tendermint/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "TendermintBaseParams"
}
}
},
{
"url": "./cosmos/distribution/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "DistributionParams"
}
}
},
{
"url": "./cosmos/evidence/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "EvidenceParams"
}
}
},
{
"url": "./cosmos/base/node/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "CosmosBaseParams"
}
}
},
{
"url": "./cosmos/feegrant/v1beta1/query.swagger.json"
},
{
"url": "./cosmos/gov/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GovParams",
"Proposal": "GovProposal",
"Tally": "GovTally",
"TallyResult" : "GovTallyResult"
}
}
},
{
"url": "./cosmos/group/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GroupParams"
}
}
},
{
"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/tx/v1beta1/service.swagger.json",
"dereference": {
"circular": "ignore"
}
},
{
"url": "./cosmos/upgrade/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "UpgradeParams"
}
}
}
]
}
70 changes: 70 additions & 0 deletions scripts/protoc-swagger-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

set -eo pipefail

work_dir="$(dirname "$(dirname "$(realpath "$0")")")"
Copy link
Contributor

Choose a reason for hiding this comment

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

The realpath command is not available by default on all systems, such as macOS. Consider using a more portable alternative or ensure that realpath is installed as part of the prerequisites.


# Create a temporary directory and store its name in a variable.
tmp_dir=$(mktemp -d)

# Exit if the temp directory wasn't created successfully.
if [ ! -e "$tmp_dir" ]; then
>&2 echo "Failed to create temp directory"
exit 1
fi

# Make sure the temp directory gets removed on script exit.
trap "exit 1" HUP INT PIPE QUIT TERM
trap 'rm -rf "$tmp_dir"' EXIT

# Get the path of the cosmos-sdk repo from go/pkg/mod
gogo_proto_dir=$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)
google_api_dir=$(go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)
cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk)
cosmos_proto_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-proto)
ibc_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/ibc-go/v6)

proto_dirs=$(find \
$cosmos_sdk_dir/proto \
$cosmos_proto_dir/proto \
$work_dir/proto \
-path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq
#$ibc_dir/proto \
gregnuj marked this conversation as resolved.
Show resolved Hide resolved
)

cd $google_api_dir
go mod download
go build -o $tmp_dir/protoc-gen-swagger protoc-gen-swagger/main.go
cd $tmp_dir

PATH=./:$PATH
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the current directory to the PATH can be a security risk. Consider specifying the full path to the protoc-gen-swagger binary instead of modifying the PATH.


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' \))

if [[ ! -z "$query_file" ]]; then
#-I "$ibc_dir/proto" \
gregnuj marked this conversation as resolved.
Show resolved Hide resolved
protoc \
-I "$gogo_proto_dir" \
-I "$gogo_proto_dir/protobuf" \
-I "$google_api_dir" \
-I "$google_api_dir/third_party" \
-I "$google_api_dir/third_party/googleapis" \
-I "$cosmos_proto_dir/proto" \
-I "$cosmos_sdk_dir/proto" \
-I "$work_dir/proto" \
"$query_file" \
--swagger_out $tmp_dir \
--swagger_opt logtostderr=true \
--swagger_opt fqn_for_swagger_name=true \
--swagger_opt simple_operation_ids=true
fi
done

npm install -g swagger-combine
gregnuj marked this conversation as resolved.
Show resolved Hide resolved
npx swagger-combine -f yaml \
$work_dir/docs/swagger-ui/config.json \
-o $work_dir/docs/swagger-ui/swagger.yaml \
--continueOnConflictingPaths true \
--includeDefinitions true
Loading