go-monobank/generate.sh
2024-05-12 12:36:55 +03:00

68 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
swagger_codegen_jar=~/.local/bin/swagger-codegen-cli-3.0.54.jar
swagger_spec="openapi.json"
# download api spec
curl -s "https://api.monobank.ua/docs/index.html" | sed -n 's/.*const __redoc_state = \(.*\);.*/\1/p' | jq .spec.data > $swagger_spec
# rm old files
rm -R\
*.go \
git_push.sh \
README.md \
.swagger-codegen-ignore \
.travis.yml \
docs \
api \
.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 monobank/g' {} +
echo "type Array []string" >> configuration.go
find . -type f -name "*.go" -exec sed -i 's/_ApiService/ApiService/g' {} +
cat <<EOF > model_webhook_response.go
package monobank
type WebHookResponse struct {
Type string `json:"type"` // "StatementItem"
Data WebHookResponseData `json:"data"`
}
type WebHookResponseData struct {
Account string `json:"account"`
StatementItem StatementItemsInner `json:"statementItem"`
}
EOF
sed -i 's/_Api \*ApiService/Api \*ApiService/g' client.go
sed -i 's/c\._Api = (\*ApiService)(&c\.common)/c\.Api = (\*ApiService)(\&c\.common)/g' client.go
# format
go fmt .
# fix .gitignore
cat >> .gitignore << EOL
# Editor and IDE files
/.idea/
# Swagger Codegen files
/.swagger-codegen-ignore
/.swagger-codegen/VERSION
/.travis.yml
# Swagger schema files
/$swagger_spec.yaml
EOL
# add info to README.md
sed -i '1i\
[![Go Reference](https://pkg.go.dev/badge/gitea.stuzer.link/stuzer05/go-monobank.svg)](https://pkg.go.dev/gitea.stuzer.link/stuzer05/go-monobank)
' README.md
# sync go dependencies
go mod tidy