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/enable alliance swagger #320

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ data
screenlog.0
_build
.idea
build
build
tmp-swagger-gen

cosmos-sdk
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ install: go.sum
build:
go build $(BUILD_FLAGS) -o bin/migalood ./cmd/migalood

.PHONY: build

docker-build-debug:
@DOCKER_BUILDKIT=1 docker build -t migaloo:debug -f Dockerfile .

Expand Down Expand Up @@ -216,6 +218,7 @@ test:

docs:
@echo
@echo "Heloo"
@echo "=========== Generate Message ============"
@echo
./scripts/generate-docs.sh
Expand Down Expand Up @@ -243,11 +246,26 @@ proto-gen:
@$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen.sh;

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@$(DOCKER) run --rm -v $(CURDIR):/workspace -v $(CURDIR)/proto:/proto --workdir /workspace $(containerProtoImage) \
sh ./scripts/protoc-swagger-gen.sh;

proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \; ; fi

update-swagger-docs:
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m -ns migaloo
@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

###############################################################################
### Localnet ###
###############################################################################
Expand Down
16 changes: 13 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
appparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/params"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
"github.com/rakyll/statik/fs"

v3_0_2 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v3_0_2"
v4 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_1_0"

_ "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/client/docs/statik"

Check warning on line 162 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

blank-imports: a blank import should be only in a main or test package, or have a comment justifying it (revive)
)

const (
Expand Down Expand Up @@ -1108,12 +1109,21 @@

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
cosmosStatikFs, err := fs.New()
if err != nil {
panic(err)
}

cosmosStaticServer := http.FileServer(cosmosStatikFs)

statikFS, err := fs.NewWithNamespace("migaloo")
if err != nil {
panic(err)
}

staticServer := http.FileServer(statikFS)

rtr.PathPrefix("/swagger/cosmos-sdk/").Handler(http.StripPrefix("/swagger/cosmos-sdk/", cosmosStaticServer))
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}

Expand Down
6 changes: 6 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v1
plugins:
- name: grpc-gateway
out: ./tmp-swagger-gen
opt:
- logtostderr=true
173 changes: 173 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"swagger": "2.0",

"info": {
"description": "Swagger for migaloo chain",
"version": "4.1.0"
},

"apis": [
{
"url": "./tmp-swagger-gen/cosmos/auth/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "AuthParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/bank/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "BankParams"
}
}
},
{
"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": {
"rename": {
"Params": "DistributionParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/evidence/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "EvidenceParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/gov/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GovParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/gov/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GovV1Params",
"Proposal": "GovV1Proposal",
"Proposals": "GovV1Proposal",
"Vote": "GovV1Vote",
"Votes": "GovV1Votes",
"Deposit": "GovV1Deposit",
"Deposits": "GovV1Deposit",
"TallyResult": "GovV1TallyResult"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/mint/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "MintParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/params/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "Params"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/slashing/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "SlashingParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/staking/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "StakingParams",
"DelegatorValidators": "StakingDelegatorValidators"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/tx/v1beta1/service.swagger.json",
"dereference": {
"circular": "ignore"
}
},
{
"url": "./tmp-swagger-gen/cosmos/upgrade/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "UpgradeParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/authz/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "AuthzParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/feegrant/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "FeegrantParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/nft/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "NftParams",
"Balance": "NftBalance"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/group/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GroupParams",
"Proposal": "GroupProposal",
"TallyResult": "GroupTallyResult"
}
}
},
{
"url": "./tmp-swagger-gen/alliance/alliance/query.swagger.json",
"operationIds": {
"rename": {
"Params": "AllianceParams"
}
}
},

{
"url": "./tmp-swagger-gen/migaloo/feeburn/query.swagger.json",
"operationIds": {
"rename": {
"Params": "FeeBurnParams"
}
}
}
]
}
3 changes: 3 additions & 0 deletions client/docs/statik/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package statik

//This just for fixing the error in importing empty github.com/cosmos/cosmos-sdk/client/lcd/statik

Check failure on line 3 in client/docs/statik/init.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
16 changes: 16 additions & 0 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

Binary file added client/docs/swagger-ui/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/docs/swagger-ui/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions client/docs/swagger-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Migaloo Blockchain Swagger UI</title>
<link rel="stylesheet" type="text/css" href="swagger-ui.css" >
<link rel="stylesheet" type="text/css" href="swagger-ui-dark.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;
}

.info hgroup.main{
display: none;
}

.information-container .info {
margin: 0;
}
</style>
</head>

<body>
<div id="swagger-ui"></div>
<script src="swagger-ui-bundle.js"> </script>
<script src="swagger-ui-standalone-preset.js"> </script>
<script>
// This is a test 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>
Loading
Loading