Auto download openapi spec

This commit is contained in:
Illya Marchenko 2024-05-12 12:09:16 +03:00
parent 557ede6095
commit 976d464ef8
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
4 changed files with 27 additions and 22 deletions

5
.gitignore vendored

@ -30,6 +30,7 @@ _testmain.go
/.swagger-codegen-ignore /.swagger-codegen-ignore
/.swagger-codegen/VERSION /.swagger-codegen/VERSION
/.travis.yml /.travis.yml
/git_push.sh
# Firefly III YAML files # Swagger schema files
/firefly-*.yaml /openapi.yaml

@ -2,24 +2,27 @@
swagger_codegen_jar=~/.local/bin/swagger-codegen-cli-3.0.54.jar swagger_codegen_jar=~/.local/bin/swagger-codegen-cli-3.0.54.jar
if [ $# -eq 0 ]; then swagger_spec="openapi.yaml"
echo "Usage: $0 <swagger-spec-file>"
exit 1
fi
swagger_spec=$1 # download api spec
url=$(curl -s https://api-docs.firefly-iii.org | grep -oP '(?<=url: ")[^"]*v1[^"]*' | head -n 1)
if [ ! -f "$swagger_spec" ]; then url="${url#./}"
echo "Swagger spec file not found: $swagger_spec" echo $url
exit 1 full_url="https://api-docs.firefly-iii.org/$url"
fi echo $full_url
curl -o openapi.yaml "$full_url"
# rm old files # rm old files
rm *.go rm -R\
rm git_push.sh *.go \
rm README.md git_push.sh \
rm -R docs README.md \
rm -R api .swagger-codegen-ignore \
.travis.yml \
docs \
api \
test \
.swagger-codegen
# generate new spec # generate new spec
java -jar "$swagger_codegen_jar" generate -i "$swagger_spec" -l go -o . java -jar "$swagger_codegen_jar" generate -i "$swagger_spec" -l go -o .
@ -58,9 +61,10 @@ cat >> .gitignore << EOL
/.swagger-codegen-ignore /.swagger-codegen-ignore
/.swagger-codegen/VERSION /.swagger-codegen/VERSION
/.travis.yml /.travis.yml
/git_push.sh
# Firefly III YAML files # Swagger schema files
/firefly-*.yaml /$swagger_spec
EOL EOL
# add info to README.md # add info to README.md

2
go.mod

@ -4,5 +4,5 @@ go 1.22.2
require ( require (
github.com/antihax/optional v1.0.0 github.com/antihax/optional v1.0.0
golang.org/x/oauth2 v0.19.0 golang.org/x/oauth2 v0.20.0
) )

4
go.sum

@ -2,5 +2,5 @@ github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwc
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=