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
|
#!/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
|
# safety measure
|
||||||
if [ -d output ]; then
|
if [ -d output ]; then
|
||||||
echo "output directory already exist"
|
echo "output directory already exist"
|
||||||
echo "remove manually and try again"
|
echo "remove manually and try again"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# PACKAGE_NAME will be loaded here
|
# PACKAGE_NAME will be loaded here
|
||||||
. ENV
|
. 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 \
|
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 \
|
generate -i /work/openapi.yaml -g aspnetcore -o /work/output \
|
||||||
--package-name $PACKAGE_NAME \
|
--package-name $PACKAGE_NAME \
|
||||||
--additional-properties="packageVersion=0.0.1,aspnetCoreVersion=5.0,operationIsAsync=true,modelPropertyNaming=camelCase,\
|
--additional-properties="packageVersion=0.0.1,aspnetCoreVersion=5.0,operationIsAsync=true,modelPropertyNaming=camelCase,\
|
||||||
generateBody=false,classModifier=abstract,operationModifier=abstract"
|
generateBody=false,classModifier=abstract,operationModifier=abstract"
|
||||||
|
|
||||||
# patch DbService registering into generated startup code
|
echo "patch DbService registering into generated startup code"
|
||||||
sed -i output/src/$PACKAGE_NAME/Startup \
|
sed -i output/src/$PACKAGE_NAME/Startup.cs \
|
||||||
-e 's/\(using '$PACKAGE_NAME'.OpenApi;\)/\1\nusing '$PACKAGE_NAME'.Services;/'\
|
-e 's#\(using '$PACKAGE_NAME'.OpenApi;\)#\1\n\n// added by post-processor\nusing '$PACKAGE_NAME'.Services;\n#' \
|
||||||
-e 's#\(// Add framework services.\)#services.AddTransient<IDbService, DbService>();\n\1#'
|
-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/Implementations
|
||||||
mkdir output/src/$PACKAGE_NAME/Services
|
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
|
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
|
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
|
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