From 09b87ca403a1fbecea8d10c81973ebeb753cd7c2 Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Sat, 11 May 2024 17:06:54 +0300 Subject: [PATCH] Add generate script --- .gitignore | 36 +++++++++++++++++++++- README.md | 1 - generate.sh | 70 +++++++++++++++++++++++++++++++++++++++++- model_configuration.go | 17 ---------- 4 files changed, 104 insertions(+), 20 deletions(-) mode change 100644 => 100755 generate.sh delete mode 100644 model_configuration.go diff --git a/.gitignore b/.gitignore index 757fee3..ac9c093 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,35 @@ -/.idea \ No newline at end of file +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof + +# Editor and IDE files +/.idea/ + +# Swagger Codegen files +/.swagger-codegen-ignore +/.swagger-codegen/VERSION +/.travis.yml + +# Firefly III YAML files +/firefly-*.yaml diff --git a/README.md b/README.md index da0a545..b022967 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ [![Go Reference](https://pkg.go.dev/badge/gitea.stuzer.link/stuzer05/go-firefly3.svg)](https://pkg.go.dev/gitea.stuzer.link/stuzer05/go-firefly3) - # Go API client for swagger This is the documentation of the Firefly III API. You can find accompanying documentation on the website of Firefly III itself (see below). Please report any bugs or issues. You may use the \"Authorize\" button to try the API below. This file was last generated on 2024-04-20T05:28:29+00:00 Please keep in mind that the demo site does not accept requests from curl, colly, wget, etc. You must use a browser or a tool like Postman to make requests. Too many script kiddies out there, sorry about that. diff --git a/generate.sh b/generate.sh old mode 100644 new mode 100755 index 7b24f9b..633b7f1 --- a/generate.sh +++ b/generate.sh @@ -1 +1,69 @@ -java -jar ~/.local/bin/swagger-codegen-cli-3.0.54.jar generate -i firefly-iii-2.0.14-v1.yaml -l go -o firefly3 +#!/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 \ No newline at end of file diff --git a/model_configuration.go b/model_configuration.go deleted file mode 100644 index fdc4b81..0000000 --- a/model_configuration.go +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Firefly III API v2.0.14 - * - * This is the documentation of the Firefly III API. You can find accompanying documentation on the website of Firefly III itself (see below). Please report any bugs or issues. You may use the \"Authorize\" button to try the API below. This file was last generated on 2024-04-20T05:28:29+00:00 Please keep in mind that the demo site does not accept requests from curl, colly, wget, etc. You must use a browser or a tool like Postman to make requests. Too many script kiddies out there, sorry about that. - * - * API version: 2.0.14 - * Contact: james@firefly-iii.org - * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - */ -package firefly3 - -//type Configuration struct { -// Title *ConfigValueFilter `json:"title"` -// Value *PolymorphicProperty `json:"value"` -// // If this config variable can be edited by the user -// Editable bool `json:"editable"` -//}