Skip to content

Commit

Permalink
add script to generate and update openapi3.0 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adelowo committed Feb 20, 2019
1 parent 7e7ea2f commit d9ffca6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
35 changes: 6 additions & 29 deletions utils/ci-swagger.sh
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"

42 changes: 42 additions & 0 deletions utils/generate-swagger.sh
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"

0 comments on commit d9ffca6

Please sign in to comment.