-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: updating the swagger docs (#2055)
* WIP: adding cosmos,ibc swagger docs * chore: remove cosmos and ibc-go swagger * chore: add update-swagger docs as per release * chore: removed statik and swagger-ui data * move statik import to tools * chore: updating release workflow and swagger docs section in readme * chore: add update swagger docs to docker build action * fix: fix the lint issue * fix: fix the markdown lint
- Loading branch information
Showing
12 changed files
with
2,868 additions
and
537 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,10 @@ private* | |
#IntelliJ | ||
.idea/ | ||
|
||
#VsCode | ||
#Vscode | ||
.vscode | ||
|
||
# Swagger UI | ||
swagger/statik/statik.go | ||
swagger/swagger-ui | ||
|
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,55 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
SWAGGER_DIR=./swagger | ||
SWAGGER_UI_DIR=${SWAGGER_DIR}/swagger-ui | ||
|
||
# TODO: needs to fix merge issue of cosmos swagger and ibc-go swagger | ||
# SDK_VERSION=$(go list -m -f '{{ .Version }}' github.com/cosmos/cosmos-sdk) | ||
# IBC_VERSION=$(go list -m -f '{{ .Version }}' github.com/cosmos/ibc-go/v6) | ||
|
||
# SDK_RAW_URL=https://raw.githubusercontent.com/cosmos/cosmos-sdk/${SDK_VERSION}/client/docs/swagger-ui/swagger.yaml | ||
# IBC_RAW_URL=https://raw.githubusercontent.com/cosmos/ibc-go/${IBC_VERSION}/docs/client/swagger-ui/swagger.yaml | ||
|
||
# # download Cosmos SDK swagger yaml file | ||
# echo "SDK version ${SDK_VERSION}" | ||
# wget "${SDK_RAW_URL}" -O ./tmp-swagger-gen/cosmos-sdk-swagger.yaml | ||
|
||
# # download IBC swagger yaml file | ||
# echo "IBC version ${IBC_VERSION}" | ||
# wget "${IBC_RAW_URL}" -O ./tmp-swagger-gen/ibc-go-swagger.yaml | ||
|
||
SWAGGER_UI_VERSION=4.18.3 | ||
SWAGGER_UI_DOWNLOAD_URL=https://github.com/swagger-api/swagger-ui/archive/refs/tags/v${SWAGGER_UI_VERSION}.zip | ||
SWAGGER_UI_PACKAGE_NAME=${SWAGGER_DIR}/swagger-ui-${SWAGGER_UI_VERSION} | ||
|
||
# if swagger-ui does not exist locally, download swagger-ui and move dist directory to | ||
# swagger-ui directory, then remove zip file and unzipped swagger-ui directory | ||
if [ ! -d ${SWAGGER_UI_DIR} ]; then | ||
# download swagger-ui | ||
wget ${SWAGGER_UI_DOWNLOAD_URL} -O ${SWAGGER_UI_PACKAGE_NAME}.zip | ||
# unzip swagger-ui package | ||
unzip ${SWAGGER_UI_PACKAGE_NAME}.zip -d ${SWAGGER_DIR} | ||
# move swagger-ui dist directory to swagger-ui directory | ||
mv ${SWAGGER_UI_PACKAGE_NAME}/dist ${SWAGGER_UI_DIR} | ||
# remove swagger-ui zip file and unzipped swagger-ui directory | ||
rm -rf ${SWAGGER_UI_PACKAGE_NAME}.zip ${SWAGGER_UI_PACKAGE_NAME} | ||
# replacing default swagger with our generated swagger yaml file | ||
sed -i 's+https://petstore.swagger.io/v2/swagger.json+./swagger.yaml+g' ${SWAGGER_DIR}/swagger-ui/swagger-initializer.js | ||
fi | ||
|
||
# move generated swagger yaml file to swagger-ui directory | ||
cp ${SWAGGER_DIR}/swagger.yaml ${SWAGGER_DIR}/swagger-ui/ | ||
|
||
# install statik if not present | ||
go install github.com/rakyll/statik | ||
|
||
# generate statik golang code using updated swagger-ui directory | ||
statik -src=${SWAGGER_DIR}/swagger-ui -dest=${SWAGGER_DIR} -f -m | ||
|
||
# log whether or not the swagger directory was updated | ||
if [ -n "$(git status ${SWAGGER_DIR} --porcelain)" ]; then | ||
echo "Swagger is updated" | ||
else | ||
echo "Swagger in sync" | ||
fi |
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 @@ | ||
package statik |
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
package swagger | ||
|
||
import ( | ||
"embed" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/ignite/cli/ignite/pkg/openapiconsole" | ||
) | ||
"github.com/rakyll/statik/fs" | ||
|
||
//go:embed swagger.yaml | ||
var Docs embed.FS | ||
// unnamed import of statik for swagger UI support | ||
_ "github.com/umee-network/umee/v5/swagger/statik" | ||
) | ||
|
||
// RegisterSwaggerAPI registers swagger route with API Server | ||
func RegisterSwaggerAPI(rtr *mux.Router) { | ||
rtr.Handle("/swagger.yaml", http.FileServer(http.FS(Docs))) | ||
rtr.HandleFunc("/swagger/", openapiconsole.Handler("umee", "/swagger.yaml")) | ||
statikFS, err := fs.New() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
staticServer := http.FileServer(statikFS) | ||
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) | ||
} |
Oops, something went wrong.