#!/bin/bash

# Tool to create HTML browseable version of the specifications.
# Requires raml2html (https://github.com/kevinrenskers/raml2html)
# (c) AMWA 2016

havecmd ()
{
    type $1 > /dev/null 2>&1
}

if ! havecmd raml2html; then
    echo "Please install raml2html"
    exit 1
fi

# In case script is run from elsewhere
cd $(dirname "${BASH_SOURCE[0]}")

# Proper behaviour when no glob match
shopt -s nullglob

for INFILE in *.raml
do
  echo "Found RAML file" $INFILE
  OUTFILE=${INFILE%%raml}html
  echo $OUTFILE
  raml2html $INFILE > $OUTFILE
  echo "Generated" $OUTFILE
done
echo ""
echo "Linting..."
jsonlint -v ../examples/*.json
echo ""
jsonlint -v schemas/*.json
