forked from Gravity-Bridge/Gravity-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db3075b
commit 6a3e980
Showing
14 changed files
with
117,881 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
# go get ./... | ||
# go install github.com/cosmos/gogoproto/protoc-gen-gocosmos | ||
# go install github.com/grpc-ecosystem/grpc-gateway/[email protected] | ||
# apk add nodejs-current npm | ||
# npm install -g swagger-combine | ||
|
||
BASEDIR=$(dirname $0) | ||
PROJECTDIR=$BASEDIR/../.. | ||
# default is tmp folder | ||
SOURCEDIR=$(realpath ${1:-$PROJECTDIR/tmp}) | ||
DOC_DIR=$(realpath $PROJECTDIR/doc) | ||
|
||
COSMOS_SDK_DIR=${COSMOS_SDK_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk)} | ||
IBC_DIR=${IBC_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/ibc-go/v3)} | ||
|
||
|
||
# scan all folders that contain proto file | ||
proto_dirs=$(find $PROJECTDIR/proto $COSMOS_SDK_DIR/proto $COSMOS_SDK_DIR/third_party/proto $IBC_DIR/proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) | ||
|
||
GEN_DIR=$SOURCEDIR/swagger-gen | ||
# clean swagger files | ||
rm -rf $GEN_DIR | ||
mkdir -p $GEN_DIR | ||
|
||
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 | ||
buf alpha protoc \ | ||
-I="$PROJECTDIR/proto" \ | ||
-I="$IBC_DIR/proto" \ | ||
-I="$COSMOS_SDK_DIR/third_party/proto" \ | ||
-I="$COSMOS_SDK_DIR/proto" \ | ||
--gocosmos_out=Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,plugins=interfacetype+grpc,paths=source_relative:$COSMOS_SDK_DIR \ | ||
--swagger_out=$GEN_DIR \ | ||
--swagger_opt=logtostderr=true,fqn_for_swagger_name=true,simple_operation_ids=true \ | ||
$query_file | ||
|
||
fi | ||
done | ||
|
||
if [ $(uname) == 'Darwin' ] | ||
then | ||
sed -i '' 's/UpgradedConsensusState/UpgradedIBCConsensusState/' $GEN_DIR/ibc/core/client/v1/query.swagger.json | ||
else | ||
# fix for darwin | ||
sed -i 's/UpgradedConsensusState/UpgradedIBCConsensusState/' $GEN_DIR/ibc/core/client/v1/query.swagger.json | ||
fi | ||
|
||
swagger_files=$(find $GEN_DIR/gravity $GEN_DIR/ibc -name 'query.swagger.json' | xargs) | ||
|
||
node -e "var fs = require('fs'),file='$COSMOS_SDK_DIR/client/docs/config.json',result = fs.readFileSync(file).toString().replace('./client','$COSMOS_SDK_DIR/client').replace(/.\/tmp-swagger-gen/g, '$GEN_DIR'); | ||
var swaggerFiles = '$swagger_files'.split(' '), obj = JSON.parse(result); | ||
swaggerFiles.forEach(swaggerFile => { | ||
obj.apis.push({ | ||
url: swaggerFile, | ||
operationIds: { | ||
rename: { | ||
Params: swaggerFile.split('/').slice(3,-2).map(dir=>dir[0].toUpperCase() + dir.slice(1)).join('') + 'Params' | ||
} | ||
} | ||
}); | ||
}); | ||
fs.writeFileSync('$GEN_DIR/config.json', JSON.stringify(obj, null, 2)); | ||
" | ||
|
||
|
||
# combine swagger files | ||
# all the individual swagger files need to be configured in `config.json` for merging | ||
swagger-combine $GEN_DIR/config.json -o $DOC_DIR/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true | ||
|
||
|
||
# make statik | ||
# statik -src doc/swagger-ui/ -dest doc -f |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- HTML for static distribution bundle build --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Swagger UI</title> | ||
<link rel="stylesheet" type="text/css" href="swagger-ui.css" > | ||
<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" /> | ||
<style> | ||
html | ||
{ | ||
box-sizing: border-box; | ||
overflow: -moz-scrollbars-vertical; | ||
overflow-y: scroll; | ||
} | ||
|
||
*, | ||
*:before, | ||
*:after | ||
{ | ||
box-sizing: inherit; | ||
} | ||
|
||
body | ||
{ | ||
margin:0; | ||
background: #fafafa; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="swagger-ui"></div> | ||
|
||
<script src="swagger-ui-bundle.js"> </script> | ||
<script src="swagger-ui-standalone-preset.js"> </script> | ||
<script> | ||
window.onload = function() { | ||
|
||
// Build a system | ||
const ui = SwaggerUIBundle({ | ||
url: "./swagger.yaml", | ||
dom_id: '#swagger-ui', | ||
deepLinking: true, | ||
presets: [ | ||
SwaggerUIBundle.presets.apis, | ||
SwaggerUIStandalonePreset | ||
], | ||
plugins: [ | ||
SwaggerUIBundle.plugins.DownloadUrl | ||
], | ||
layout: "StandaloneLayout" | ||
}) | ||
|
||
window.ui = ui | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<body onload="run()"> | ||
</body> | ||
</html> | ||
<script> | ||
'use strict'; | ||
function run () { | ||
var oauth2 = window.opener.swaggerUIRedirectOauth2; | ||
var sentState = oauth2.state; | ||
var redirectUrl = oauth2.redirectUrl; | ||
var isValid, qp, arr; | ||
|
||
if (/code|token|error/.test(window.location.hash)) { | ||
qp = window.location.hash.substring(1); | ||
} else { | ||
qp = location.search.substring(1); | ||
} | ||
|
||
arr = qp.split("&") | ||
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';}) | ||
qp = qp ? JSON.parse('{' + arr.join() + '}', | ||
function (key, value) { | ||
return key === "" ? value : decodeURIComponent(value) | ||
} | ||
) : {} | ||
|
||
isValid = qp.state === sentState | ||
|
||
if (( | ||
oauth2.auth.schema.get("flow") === "accessCode"|| | ||
oauth2.auth.schema.get("flow") === "authorizationCode" | ||
) && !oauth2.auth.code) { | ||
if (!isValid) { | ||
oauth2.errCb({ | ||
authId: oauth2.auth.name, | ||
source: "auth", | ||
level: "warning", | ||
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server" | ||
}); | ||
} | ||
|
||
if (qp.code) { | ||
delete oauth2.state; | ||
oauth2.auth.code = qp.code; | ||
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl}); | ||
} else { | ||
let oauthErrorMsg | ||
if (qp.error) { | ||
oauthErrorMsg = "["+qp.error+"]: " + | ||
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") + | ||
(qp.error_uri ? "More info: "+qp.error_uri : ""); | ||
} | ||
|
||
oauth2.errCb({ | ||
authId: oauth2.auth.name, | ||
source: "auth", | ||
level: "error", | ||
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server" | ||
}); | ||
} | ||
} else { | ||
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl}); | ||
} | ||
window.close(); | ||
} | ||
</script> |
Oops, something went wrong.