Added Dockerfile and scripts to enable Jenkins validation of OpenAPI schemas
Change-Id: I7837b1d3e5bdfbe83af9c0d1233d7e317a3eed23
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/Dockerfile b/Dockerfile
index ac08971..8d78265 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,5 +13,12 @@
FROM ubuntu:18.04
-RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install git \
- make python3 debhelper python3-setuptools apt-utils
+RUN apt-get update && apt-get install -y git build-essential curl \
+ && curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
+ && echo "deb https://deb.nodesource.com/node_10.x bionic main" | tee -a /etc/apt/sources.list.d/nodesource.list \
+ && echo "deb-src https://deb.nodesource.com/node_10.x bionic main" | tee -a /etc/apt/sources.list.d/nodesource.list \
+ && apt-get update && apt-get install -y nodejs
+RUN npm install --save @openapi-contrib/json-schema-to-openapi-schema
+RUN npm install -g swagger-cli
+RUN npm install -g speccy
+
diff --git a/Jenkinsfile b/Jenkinsfile
index 9f67d36..59f05ef 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -15,7 +15,7 @@
properties([
parameters([
string(defaultValue: env.BRANCH_NAME, description: '', name: 'GERRIT_BRANCH'),
- string(defaultValue: 'osm/TEMPLATE', description: '', name: 'GERRIT_PROJECT'),
+ string(defaultValue: 'osm/SOL003', description: '', name: 'GERRIT_PROJECT'),
string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'),
string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'),
string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX'),
@@ -35,7 +35,7 @@
devops_checkout()
ci_stage_2 = load "devops/jenkins/ci-pipelines/ci_stage_2.groovy"
- ci_stage_2.ci_pipeline( 'TEMPLATE',
+ ci_stage_2.ci_pipeline( 'SOL003',
params.PROJECT_URL_PREFIX,
params.GERRIT_PROJECT,
params.GERRIT_BRANCH,
diff --git a/devops-stages/stage-test.sh b/devops-stages/stage-test.sh
index 337cf59..b7693a7 100644
--- a/devops-stages/stage-test.sh
+++ b/devops-stages/stage-test.sh
@@ -1,4 +1,5 @@
#!/bin/sh
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -11,4 +12,21 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-echo "TEST"
+#
+specfiles=$(ls | egrep "^[^.]*.(json|yaml)")
+
+fres=0
+for i in $specfiles ; do
+ echo "-- Validating and linting OpenAPI file $i..."
+ swagger-cli validate "$i"
+ res=$?
+ speccy lint "$i" --skip openapi-tags-alphabetical
+ res2=$?
+ fres=$(($fres||$res||$res2))
+ echo "--- Validator returned $res, linter returned $res2."
+done
+
+echo "-- Final validation returns $fres."
+
+exit $fres
+