go-firefly3/generate.sh

72 lines
1.6 KiB
Bash
Raw Normal View History

2024-05-11 17:06:54 +03:00
#!/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)
2024-05-12 11:50:56 +03:00
' README.md
# sync go dependencies
go mod tidy