Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shell script that uses shUnit2 for validating OpenAPI specification file. This file is taken from https://github.com/amardeshbd/medium-api-specification and **modified** for embedding on web, see github project for details.
#!/bin/sh
# NOTE: This file is modified version taken from:
# https://github.com/amardeshbd/medium-api-specification/blob/master/api-spec_validation_test.sh
# Tests the swagger specificaton using online service
testOpenApiSpecValidity() {
expectedOutput="{}"
expectedOutputSize=${#expectedOutput}
# Prepares the spec URL from GitHub Pull-Request (PR)
specUrl="https://raw.githubusercontent.com/amardeshbd/medium-api-specification/$BRANCH/medium-api-specification.yaml"
# Now prepare the open API spec file to use the online validator service.
validationUrl="http://online.swagger.io/validator/debug?url=$specUrl"
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "Validating ENV Variables: TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH"
echo "OpenAPI Specification File=$validationUrl"
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
validationOutput=$(curl $validationUrl)
validationOutputSize=${#validationOutput}
echo "Testing swagger validation - current output is: $validationOutput"
echo "Expected valid size: $expectedOutputSize, current output: $validationOutputSize"
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
assertEquals "Validation failed - service unavailable or error found." $expectedOutputSize $validationOutputSize
}
# Execute shunit2 to run the tests (downloaded via `.travis.yaml`)
. shunit2-2.1.6/src/shunit2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment