-
-
Save vvsevolodovich/6c22811c6a6cf1632f2101810d410f3f to your computer and use it in GitHub Desktop.
Openapi Automation with Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ] | |
then | |
echo "usage: ./tools/openapi-generate <your_service> <project_id> <token>" | |
exit | |
fi | |
BASE_PATH=`pwd`"/$1/lib" | |
BASE_MODEL_PATH="$BASE_PATH/model" | |
GENERATED_PATH="$BASE_PATH/newversion/lib" | |
GENERATED_MODEL_PATH="$GENERATED_PATH/model" | |
TMP=/tmp/genoutput.dart | |
FILE="`pwd`/openapi-generator-cli-4.3.1.jar" | |
if [ -f "$FILE" ]; then | |
echo "$FILE exists." | |
else | |
echo "openapi-generator-cli-4.3.1.jar file not found, downloading..." | |
curl "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar" --output "$FILE" | |
fi | |
echo "Downloading new openapi.yaml" | |
curl -XGET --header "PRIVATE-TOKEN: $3" "https://gitlab.com/api/v4/projects/$2/repository/files/api%2fopenapi.yaml/raw?ref=master" > "$BASE_PATH/openapi.yaml" | |
echo "Generating client for $BASE_PATH/openapi.yaml" | |
java -jar "`pwd`/openapi-generator-cli-4.3.1.jar" generate -i "$BASE_PATH/openapi.yaml" -g dart-dio -o "$BASE_PATH/newversion" | |
echo "Generating done." | |
#sed -e 's/package:openapi\/model\///g' "$INPUT" > $TMP && mv $TMP "$INPUT" | |
cd "$GENERATED_MODEL_PATH"; | |
for i in $(ls); | |
do | |
#echo $i; | |
sed -e 's/package:openapi\/model\///g' "$GENERATED_MODEL_PATH/$i" > $TMP && mv $TMP "$BASE_MODEL_PATH/$i" | |
flutter format "$BASE_MODEL_PATH/$i" | |
done | |
sed -e 's/package:openapi\/model\//..\/model\//g' "$GENERATED_PATH/api/default_api.dart" > $TMP && mv $TMP "$BASE_PATH/api/default_api.dart" | |
flutter format "$BASE_PATH/api/default_api.dart" | |
sed -e 's/package:openapi\/model\//model\//g' "$GENERATED_PATH/serializers.dart" > $TMP && mv $TMP "$BASE_PATH/serializers.dart" | |
flutter format "$BASE_PATH/serializers.dart" | |
echo "Removing temporary files" | |
cd "$BASE_PATH" | |
rm -rf ./newversion | |
cd ../ | |
echo "generating build_value..." | |
flutter pub run build_runner build | |
echo "Done" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment