#!/bin/bash

DIR=`dirname "$0"`
TARGET="${DIR}/../src-gen/openapi_server/"

echo "Preparing symlinks"
mkdir -p "${TARGET}"
cd "${TARGET}"
if [ ! -L server_impl ]; then
	ln -s ../../src/server_impl/
fi

#echo "Copying static files"
#cp -a ../../src/templates ./
#cp -a ../../src/static ./
#mkdir -p static/css/
#mkdir -p static/js/
#mkdir -p static/resources/
#cp -a ../../common/css/* static/css/
#cp -a ../../common/js/* static/js/
#cp -a ../../common/resources/* static/resources/
#cp -a ../../common/icon/gnuboat-256-256-transparent.png static/resources/

echo "Generating backend and client API code"
cd ../../
# backend
codegen/openapi-generator-cli generate -i openapi.yaml -g python-flask -t codegen/templates/ -o src-gen
# client
#codegen/openapi-generator-cli generate -i openapi.yaml -g javascript -o src-gen/openapi_server/static/
#rm -R src-gen/openapi_server/static/.openapi*


cd src-gen/
tox > /tmp/openapi_tox.log
python3 -m openapi_server
