From 30fa5a0cc6d44be64ac0356bc58f84e0be91575f Mon Sep 17 00:00:00 2001 From: Michele Carignani Date: Tue, 30 Jan 2018 19:24:55 +0100 Subject: [PATCH] Added generation of PDF exports for each OpenAPI artifact. Change-Id: I0b0ca10d454a2fbab170f7b22bb29eeabb05df71 Signed-off-by: Michele Carignani --- .jenkins.sh | 1 + docker/Dockerfile | 13 ++++++++ docker/oas2pdf | 61 ++++++++++++++++++++++++++++++++++++ docker/run-container.sh | 6 ++-- docker/swg2mrkup | 17 ++++++++++ docker/validate-in-docker.sh | 7 +++++ 6 files changed, 102 insertions(+), 3 deletions(-) create mode 100755 docker/oas2pdf create mode 100755 docker/swg2mrkup diff --git a/.jenkins.sh b/.jenkins.sh index 84524f73..b7b88b88 100755 --- a/.jenkins.sh +++ b/.jenkins.sh @@ -8,6 +8,7 @@ run_dir="$(pwd)" rm build/*-API.yaml rm build/*-API.json +rm build/*-API.pdf cd docker diff --git a/docker/Dockerfile b/docker/Dockerfile index 51a201d7..604e5a79 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,6 +14,13 @@ RUN apk update RUN apk add bash RUN apk add nodejs RUN apk add nodejs-npm +RUN apk add asciidoctor +RUN apk add openjdk8 +RUN apk add ca-certificates && update-ca-certificates +RUN apk add openssl +RUN gem install rdoc --pre || gem install rdoc --pre +RUN gem install asciidoctor-pdf-cjk +RUN wget https://forge.etsi.org/swagger2markup-cli-1.3.2.jar RUN npm config set proxy $http_proxy RUN npm install -g swagger-tools@0.10.3 RUN npm install -g json-refs@3.0.2 @@ -22,5 +29,11 @@ RUN npm install -g yamljs@0.3.0 ADD validate-in-docker.sh /validate-in-docker.sh RUN chmod +x /validate-in-docker.sh +ADD swg2mrkup /bin/swg2mrkup +RUN chmod +x /bin/swg2mrkup + +ADD oas2pdf /bin/oas2pdf +RUN chmod +x /bin/oas2pdf + ENTRYPOINT ["/validate-in-docker.sh"] diff --git a/docker/oas2pdf b/docker/oas2pdf new file mode 100755 index 00000000..70a36a05 --- /dev/null +++ b/docker/oas2pdf @@ -0,0 +1,61 @@ +#!/bin/bash +#Copyright (c) ETSI 2017. + +# This software is subject to copyrights owned by ETSI. Non-exclusive permission +# is hereby granted, free of charge, to copy, reproduce and amend this file +# under the following conditions: It is provided "as is", without warranty of any +# kind, expressed or implied. + +# ETSI shall never be liable for any claim, damages, or other liability arising +# from its use or inability of use.This permission does not apply to any documentation +# associated with this file for which ETSI keeps all rights reserved. The present +# copyright notice shall be included in all copies of whole or part of this +# software and shall not imply any sub-license right. +# +# Author: michele.carignani@etsi.org +# +# This script takes an OpenAPI file in input and creates +# a PDF file with the content. +# +# Prerequisites: +# - https://github.com/Swagger2Markup/swagger2markup-cli +# - Asciidoctor (sudo apt-get install asciidoctor) +# - Asciidoctor-pdf (sudo gem install asciidoctor-pdf) +# +# Usage: +# oas2pdf (e.g. myapi.json) +# +# Result: +# A new pdf file is created in the working directory (e.g. myapi.pdf) +# +# +# +# + +# Configuration + +# Change this if needed +SWG2MRKUP=swg2mrkup +ASCIIDOCPDF=asciidoctor-pdf + +# Setup +WD=$(pwd) +TWD=$(mktemp -d) + +INFILE=$(basename ${1?"Error: missing input file name"} ) +OUTFILE="${INFILE%.*}" + +echo "$INFILE, $OUTFILE" + +echo "Converting to asciidoc.." +${SWG2MRKUP} convert -i "$1" -f "$TWD/$OUTFILE" +echo + +echo "Converting to PDF.." +"${ASCIIDOCPDF}" "$TWD/${OUTFILE}.adoc" -o "$WD/${OUTFILE}.pdf" +echo + +echo "Done." +# Clean up +rm -r $TWD + diff --git a/docker/run-container.sh b/docker/run-container.sh index 2b7d6f83..7118514c 100755 --- a/docker/run-container.sh +++ b/docker/run-container.sh @@ -16,10 +16,10 @@ 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 "/work" "/storage" "$filter" + echo "Mounting dir $s as /storage" + docker run -v "$f":/work -v "$s":/storage openapivalidator "/work" "/storage" "$filter" else - docker run -v "$f":/work openapivalidator "/work" "/storage" "$filter" + docker run -v "$f":/work openapivalidator "/work" "/storage" "$filter" fi diff --git a/docker/swg2mrkup b/docker/swg2mrkup new file mode 100755 index 00000000..b5493719 --- /dev/null +++ b/docker/swg2mrkup @@ -0,0 +1,17 @@ +#!/bin/bash +#Copyright (c) ETSI 2017. + +# This software is subject to copyrights owned by ETSI. Non-exclusive permission +# is hereby granted, free of charge, to copy, reproduce and amend this file +# under the following conditions: It is provided "as is", without warranty of any +# kind, expressed or implied. + +# ETSI shall never be liable for any claim, damages, or other liability arising +# from its use or inability of use.This permission does not apply to any documentation +# associated with this file for which ETSI keeps all rights reserved. The present +# copyright notice shall be included in all copies of whole or part of this +# software and shall not imply any sub-license right. +# +# Author: michele.carignani@etsi.org + +java -jar /swagger2markup-cli-1.3.2.jar $@ diff --git a/docker/validate-in-docker.sh b/docker/validate-in-docker.sh index 5f0c4e7d..f6738fe7 100755 --- a/docker/validate-in-docker.sh +++ b/docker/validate-in-docker.sh @@ -25,6 +25,11 @@ function validate_api () { json_file="../build/${deliverable}-${api}-API.json" json-refs resolve "${file}" > "${merged_file}" yaml2json "${merged_file}" > "${json_file}" + + # Create the PDF version + echo "--- Create PDF..." + oas2pdf "${json_file}" 2>/dev/null 1>/dev/null + mv "${deliverable}-${api}-API.pdf" "../build/" echo "--- Validating ${merged_file}" swagger-tools validate "${merged_file}" @@ -34,6 +39,8 @@ function validate_api () { # If validation succedes, store the generated file [ $vres -a -d "/storage" ] && store_api "${merged_file}" [ $vres -a -d "/storage" ] && store_api "${json_file}" + [ $vres -a -d "/storage" ] && store_api "../build/${deliverable}-${api}-API.pdf" + return $vres } -- GitLab