Skip to content
Snippets Groups Projects
Commit 9c8ebfec authored by Michele Carignani's avatar Michele Carignani
Browse files

Validation in a docker container of the API descriptions + documentation


Change-Id: I9a01cc8c307d26058b1c2775abe828e1f0e5016b
Signed-off-by: default avatarMichele Carignani <michele.carignani@etsi.org>
parent 6ef35650
No related branches found
No related tags found
No related merge requests found
build/
#!/bin/bash
# Copyright ETSI 2017
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
cd "$(dirname "$0")"
run_dir="$(pwd)/src"
store_dir="$(pwd)/build"
mkdir -p "$store_dir"
cd docker
./build-container.sh
./run-container.sh "${run_dir}" "${store_dir}"
exit $?
......@@ -9,6 +9,27 @@ The APIs described in this repository are defined for the following reference po
More information at [NFV Solutions wiki](https://nfvwiki.etsi.org/index.php?title=NFV_Solutions).
## Content structure
All the main OpenAPI files should be put in the `src` directory and organized with the following schema:
src/deliverable-number/api-name/api-name.yaml
e.g.
src/SOL003/LifeCycleManagement/lifeCycleManagement.yaml
## Building
The build file `.jenkins.sh` will validate the files, evaluate JSON references and store the generated files in the build directory. In case the build is executed by Jenkins, the merged file will be store in a specific directory to be web-served.
To build locally, once Docker is installed, simple run
$sudo bash .jenkins.sh
and the results will be stored in a `build/` directory in the project folder.
## How to raise issues
Change requests can be filed at [ETSI Forge Bugzilla](https://forge.etsi.org/bugzilla/enter_bug.cgi?product=NFV).
......
# Copyright ETSI 2017
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
FROM alpine:3.6
RUN apk update
RUN apk add bash
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
ADD validate-in-docker.sh /validate-in-docker.sh
RUN chmod +x /validate-in-docker.sh
CMD ["/validate-in-docker.sh", "/work", "/storage"]
#!/bin/bash
# Copyright ETSI 2017
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
docker build -t openapivalidator .
\ No newline at end of file
#!/bin/bash
# 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"
else
s="${2:-`pwd`}"
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
#!/bin/bash
# Copyright ETSI 2017
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
# Merges OpenAPIs interfaces in the working directory
# and validates them individually.
# Exit status is 0 if all validation passed, 1 otherwise
# Usage:
# $0 <working-directory> <storage-dir>
#set -x
function store_api () {
f="$1"
cp -v "$1" "${storage_dir}/"
}
function validate_api () {
file="$1"
api="$2"
deliverable="$3"
echo "--- Merging file."
merged_file="${deliverable}-${api}-API.yaml"
json-refs resolve "${file}" > "${merged_file}"
echo "--- Validating ${merged_file}"
swagger-tools validate "${merged_file}"
vres=$?
echo "--- Validation done ($res)."
# If validation succedes, store the generated file
[ $vres ] && store_api "${merged_file}"
return $vres
}
## Main ##
wd="${1?"Usage: $0 <working-directory> <storage-directory>"}"
storage_dir="${2?"Usage: $0 <working-directory> <storage-directory>"}"
echo "Entering dir $wd"
cd "$wd"
# Stores the overall validation result
# (single results in OR)
fres=0
for d in */ ; do
if [ -z "$d" -o "$d" = "*/" ]; then
continue
fi
deliverable="${d::-1}"
echo "#### Checking directory $deliverable ($d)"
cd "$deliverable"
for dd in */ ; do
if [ -z "$dd" -o "$dd" = "*/" ]; then
continue
fi
api="${dd::-1}"
echo "########## Checking directory $api ($dd)"
cd "$dd"
for file in ./*; do
file_name="${file:2}"
#echo "-- $file"
#echo "-- Checking file $file_name"
if [ "$file_name" == "$api.yaml" ]; then
validate_api "$file_name" "$api" "$deliverable"
res=$?
fres=$(($fres||$res))
fi
done
echo
cd ..
done
cd ..
done
# Exit code needed for jenkins to know the verdict of the build
echo "-- Final validator returns $fres."
exit $fres
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment