oas2pdf 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 <oasfile> (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