Add generate script

This commit is contained in:
Illya Marchenko 2024-05-11 17:06:54 +03:00
parent dd1cae608b
commit 09b87ca403
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
4 changed files with 104 additions and 20 deletions

36
.gitignore vendored

@ -1 +1,35 @@
/.idea # 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

@ -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 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 # 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. 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.

70
generate.sh Normal file → Executable file

@ -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 <swagger-spec-file>"
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

@ -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"`
//}