Commit e14e9de9 authored by Michele Carignani's avatar Michele Carignani
Browse files

Improvements in the validation process:


 - Files are generated directly in the build directory in any case
 - If enabled, files are also copied under /var/www/html/api/nfv/..
 - Both YAML and JSON versions are generated

Change-Id: I1f64926892a9476293d5224a8d9d78e238f25da6
Signed-off-by: Michele Carignani's avatarMichele Carignani <michele.carignani@etsi.org>
parent 087e656a
......@@ -4,14 +4,11 @@
cd "$(dirname "$0")"
run_dir="$(pwd)/src"
store_dir="$(pwd)/build"
mkdir -p "$store_dir"
run_dir="$(pwd)"
cd docker
./build-container.sh
./run-container.sh "${run_dir}" "${store_dir}"
./run-container.sh "${run_dir}"
exit $?
......@@ -9,6 +9,7 @@ RUN apk add nodejs
RUN apk add nodejs-npm
RUN npm install -g swagger-tools@0.10.3
RUN npm install -g json-refs@3.0.2
RUN npm install -g yamljs@0.3.0
ADD validate-in-docker.sh /validate-in-docker.sh
RUN chmod +x /validate-in-docker.sh
......
......@@ -2,17 +2,25 @@
# Copyright ETSI 2017
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
if [ -n "$JOB_BASE_NAME" ] ; then
s="/var/www/html/api/nfv/$JOB_BASE_NAME/$GIT_COMMIT"
# Change this variable to true if you want
# to copy the created yaml files to a web served directory
#
#
WEB_PUBLISH=true
f="${1:-`pwd`}"
echo "Mounting dir $f as /work"
if [ -n "$JOB_BASE_NAME" -a "$WEB_PUBLISH" = true ] ; then
s="/var/www/html/api/nfv/$JOB_BASE_NAME/$BUILD_NUMBER"
mkdir -v -p "$s"
echo "Mounting dir $s as /storage"
docker run -v "$f":/work -v "$s":/storage openapivalidator
else
s="${2:-`pwd`}"
docker run -v "$f":/work openapivalidator
fi
f="${1:-`pwd`}"
mkdir -v -p "$s"
echo "Mounting dir $f as /work"
echo "Mounting dir $s as /storage"
docker run -v "$f":/work -v "$s":/storage openapivalidator
......@@ -14,6 +14,7 @@
function store_api () {
f="$1"
cp -v "$1" "${storage_dir}/"
rm "$1"
}
function validate_api () {
......@@ -21,16 +22,19 @@ function validate_api () {
api="$2"
deliverable="$3"
echo "--- Merging file."
merged_file="${deliverable}-${api}-API.yaml"
merged_file="../build/${deliverable}-${api}-API.yaml"
json_file="../build/${deliverable}-${api}-API.json"
json-refs resolve "${file}" > "${merged_file}"
yaml2json "${merged_file}" > "${json_file}"
echo "--- Validating ${merged_file}"
swagger-tools validate "${merged_file}"
vres=$?
echo "--- Validation done ($res)."
echo "--- Validation done ($vres)."
# If validation succedes, store the generated file
[ $vres ] && store_api "${merged_file}"
[ $vres -a -d "/storage" ] && store_api "${merged_file}"
[ $vres -a -d "/storage" ] && store_api "${json_file}"
return $vres
}
......@@ -52,8 +56,9 @@ function get_deliverable_from_fn () {
wd="${1?"Usage: $0 <working-directory> <storage-directory>"}"
storage_dir="${2?"Usage: $0 <working-directory> <storage-directory>"}"
echo "Entering dir $wd"
cd "$wd"
echo "Entering dir $wd/src"
cd "$wd/src"
mkdir -p "$wd/build"
# Stores the overall validation result
# (single results in OR)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment