#!/bin/bash swagger_codegen_jar=~/.local/bin/swagger-codegen-cli-3.0.54.jar swagger_spec="openapi.yaml" # download api spec url=$(curl -s https://api-docs.firefly-iii.org | grep -oP '(?<=url: ")[^"]*v1[^"]*' | head -n 1) url="${url#./}" echo $url full_url="https://api-docs.firefly-iii.org/$url" echo $full_url curl -o openapi.yaml "$full_url" # rm old files rm -R\ *.go \ git_push.sh \ README.md \ .swagger-codegen-ignore \ .travis.yml \ docs \ api \ test \ .swagger-codegen # 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 /git_push.sh # Swagger schema files /$swagger_spec 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