-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to generate and update openapi3.0 docs
- Loading branch information
Showing
2 changed files
with
48 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,10 @@ | ||
#!/bin/bash | ||
|
||
swagger2fileName="swagger2.yaml" | ||
openAPIspecfileName="gateway-swagger.yaml" | ||
|
||
fatal() { | ||
echo "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
swagger generate spec -o "$swagger2fileName" | ||
|
||
if [ $? -ne 0 ]; then | ||
fatal "could not generate swagger2.0 spec to the specified path, $swagger2fileName" | ||
fi | ||
|
||
swagger validate "$swagger2fileName" | ||
|
||
if [ $? -ne 0 ]; then | ||
fatal "swagger spec is invalid... swagger spec is located at $swagger2fileName" | ||
fi | ||
|
||
api-spec-converter --from=swagger_2 --to=openapi_3 --syntax=yaml "$swagger2fileName" > "$openAPIspecfileName" | ||
|
||
if [ $? -ne 0 ]; then | ||
fatal "could not convert swagger2.0 spec to opeenapi 3.0" | ||
fi | ||
|
||
## clean up | ||
rm "$swagger2fileName" | ||
ciUtilsDirectory=$(dirname "$0") | ||
source "$ciUtilsDirectory/generate-swagger.sh" | ||
|
||
## Ideally, CI should push $openAPIspecfileName to GitHub | ||
## but for now, it can be committed by users and pushed alonside their changes. | ||
## but for now, `generate-swagger.sh` can be run by users locally and committed | ||
## then pushed alonside their changes. | ||
rm "$openAPIspecfileName" | ||
|
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,42 @@ | ||
#!/bin/bash | ||
|
||
|
||
swagger2fileName="swagger2.yaml" | ||
openAPIspecfileName="gateway-swagger.yaml" | ||
|
||
fatal() { | ||
echo "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
mustExists() { | ||
hash $1 > /dev/null 2>&1 | ||
if [ $? -ne 0 ]; then | ||
fatal "command not found: $1. Run $2" | ||
fi | ||
} | ||
|
||
mustExists "swagger" "go get github.com/go-swagger/go-swagger/cmd/swagger" | ||
mustExists "api-spec-converter" "npm install -g api-spec-converter" | ||
|
||
swagger generate spec -o "$swagger2fileName" | ||
|
||
if [ $? -ne 0 ]; then | ||
fatal "could not generate swagger2.0 spec to the specified path, $swagger2fileName" | ||
fi | ||
|
||
swagger validate "$swagger2fileName" | ||
|
||
if [ $? -ne 0 ]; then | ||
fatal "swagger spec is invalid... swagger spec is located at $swagger2fileName" | ||
fi | ||
|
||
api-spec-converter --from=swagger_2 --to=openapi_3 --syntax=yaml "$swagger2fileName" > "$openAPIspecfileName" | ||
|
||
if [ $? -ne 0 ]; then | ||
fatal "could not convert swagger2.0 spec to opeenapi 3.0" | ||
fi | ||
|
||
## clean up | ||
rm "$swagger2fileName" | ||
|