extend generateAll.sh script
This commit is contained in:
parent
bd85599a98
commit
ebb0b87543
57
generateAll.sh
Normal file → Executable file
57
generateAll.sh
Normal file → Executable file
@ -1,42 +1,81 @@
|
||||
#!/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
|
||||
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
|
||||
|
||||
# generate server code and endpoint stubs from openapi.yaml
|
||||
echo "generate server code and endpoint stubs from openapi.yaml"
|
||||
docker run -it --rm -v $PWD:/work -u $UID openapitools/openapi-generator:cli-v5.1.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=true,modelPropertyNaming=camelCase,\
|
||||
generateBody=false,classModifier=abstract,operationModifier=abstract"
|
||||
|
||||
# patch DbService registering into generated startup code
|
||||
sed -i output/src/$PACKAGE_NAME/Startup \
|
||||
-e 's/\(using '$PACKAGE_NAME'.OpenApi;\)/\1\nusing '$PACKAGE_NAME'.Services;/'\
|
||||
-e 's#\(// Add framework services.\)#services.AddTransient<IDbService, DbService>();\n\1#'
|
||||
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#'
|
||||
|
||||
# create directories for manually developed code
|
||||
echo "create directories for manually developed code"
|
||||
mkdir output/src/$PACKAGE_NAME/Implementations
|
||||
mkdir output/src/$PACKAGE_NAME/Services
|
||||
|
||||
# copy database service into source code try
|
||||
echo "copy database service into source code try"
|
||||
cp DbService.cs output/src/$PACKAGE_NAME/Services
|
||||
|
||||
# generate endpoint code from openapi.yaml
|
||||
echo "generate endpoint code from openapi.yaml"
|
||||
python3.10 generate.py
|
||||
|
||||
# copy endpoint code into source code try
|
||||
echo "copy endpoint code into source code try"
|
||||
cp regular.cs output/src/$PACKAGE_NAME/Implementations
|
||||
|
||||
|
||||
if [ "$BUILD" = "1" ]; then
|
||||
echo "build service"
|
||||
cd output
|
||||
sh build.sh
|
||||
fi
|
||||
|
||||
if [ "$EXECUTE" = "1" ]; then
|
||||
echo "execute service"
|
||||
dotnet run -p src/$PACKAGE_NAME/$PACKAGE_NAME.csproj
|
||||
fi
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user