85 lines
2.2 KiB
Bash
Executable File
85 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
|
|
REMOVE="0"
|
|
BUILD="0"
|
|
EXECUTE="0"
|
|
while getopts rxbh flag
|
|
do
|
|
case "${flag}" in
|
|
h)
|
|
echo "r ... remove output directory";
|
|
echo "b ... build after generating";
|
|
echo "x ... execute after building";
|
|
echo "h ... show help";
|
|
;;
|
|
b)
|
|
BUILD="1"
|
|
;;
|
|
r)
|
|
REMOVE="1"
|
|
;;
|
|
x)
|
|
EXECUTE="1"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ "$REMOVE" = "1" ]; then
|
|
echo "remove output directory"
|
|
rm -rf output
|
|
fi
|
|
|
|
# safety measure
|
|
if [ -d output ]; then
|
|
echo "output directory already exist"
|
|
echo "remove manually and try again"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# PACKAGE_NAME will be loaded here
|
|
. ENV
|
|
|
|
echo "generate server code and endpoint stubs from openapi.yaml"
|
|
docker run -it --rm -v $PWD:/work -u $UID openapitools/openapi-generator-cli:v5.3.0 \
|
|
generate -i /work/openapi.yaml -g aspnetcore -o /work/output \
|
|
--package-name $PACKAGE_NAME \
|
|
--additional-properties="packageVersion=0.0.1,aspnetCoreVersion=5.0,operationIsAsync=false,operationResultTask=true,\
|
|
generateBody=false,classModifier=abstract,operationModifier=abstract"
|
|
|
|
echo "patch DbService registering into generated startup code"
|
|
sed -i output/src/$PACKAGE_NAME/Startup.cs \
|
|
-e 's#\(using '$PACKAGE_NAME'.OpenApi;\)#\1\n\n// added by post-processor\nusing '$PACKAGE_NAME'.Services;\n#' \
|
|
-e 's#^\([[:space:]]*\)\(// Add framework services.\)#\1// added by post-processor\n\1services.AddTransient<IDbService, DbService>();\n\n\1\2#'
|
|
|
|
echo "create directories for manually developed code"
|
|
mkdir output/src/$PACKAGE_NAME/Implementations
|
|
mkdir output/src/$PACKAGE_NAME/Services
|
|
|
|
echo "copy database service into source code try"
|
|
cp DbService.cs output/src/$PACKAGE_NAME/Services
|
|
|
|
echo "generate endpoint code from openapi.yaml"
|
|
python3.10 generate.py
|
|
|
|
echo "copy endpoint code into source code tree"
|
|
cp regular.cs output/src/$PACKAGE_NAME/Implementations
|
|
|
|
|
|
if [ "$BUILD" = "1" ]; then
|
|
echo "build service"
|
|
cd output
|
|
pushd src/$PACKAGE_NAME
|
|
dotnet add package MySqlConnector --version 2.0.0
|
|
popd
|
|
sh build.sh
|
|
fi
|
|
|
|
if [ "$EXECUTE" = "1" ]; then
|
|
echo "execute service"
|
|
dotnet run -p src/$PACKAGE_NAME/$PACKAGE_NAME.csproj
|
|
fi
|
|
|
|
|
|
|