#!/bin/bash swagger_codegen_jar=~/.local/bin/swagger-codegen-cli-3.0.54.jar if [ $# -eq 0 ]; then echo "Usage: $0 " exit 1 fi swagger_spec=$1 if [ ! -f "$swagger_spec" ]; then echo "Swagger spec file not found: $swagger_spec" exit 1 fi # rm old files rm *.go rm git_push.sh rm README.md rm -R docs rm -R api # generate new spec java -jar "$swagger_codegen_jar" generate -i "$swagger_spec" -l go -o . # patch code find . -name "*.go" -exec sed -i 's/package swagger/package firefly3/g' {} + rm model_configuration.go sed -i '/localVarPostBody = &body/d' api_configuration.go sed -i 's@} else if strings.Contains(contentType, "application/json") {@} else if strings.Contains(contentType, "application/json") || strings.Contains(contentType, "application/vnd.api+json") {@g' client.go sed -i '/^import (/,/^)/ { /^)/ i \ "os" }' api_data.go api_attachments.go files=( "api_accounts.go" "api_bills.go" "api_budgets.go" "api_categories.go" "api_preferences.go" "api_users.go" ) for file in "${files[@]}"; do sed -i '/^import (/,/^)/ { /^[[:space:]]*"time"[[:space:]]*$/d }' "$file" done # format go fmt . # fix .gitignore cat >> .gitignore << EOL # Editor and IDE files /.idea/ # Swagger Codegen files /.swagger-codegen-ignore /.swagger-codegen/VERSION /.travis.yml # Firefly III YAML files /firefly-*.yaml EOL # add info to README.md sed -i '1i\ [![Go Reference](https://pkg.go.dev/badge/gitea.stuzer.link/stuzer05/go-firefly3.svg)](https://pkg.go.dev/gitea.stuzer.link/stuzer05/go-firefly3) ' README.md # sync go dependencies go mod tidy