From 976d464ef8211118bc2e8dd9217e2a7b97a943cb Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Sun, 12 May 2024 12:09:16 +0300 Subject: [PATCH] Auto download openapi spec --- .gitignore | 5 +++-- generate.sh | 38 +++++++++++++++++++++----------------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index ac9c093..7cb55cd 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ _testmain.go /.swagger-codegen-ignore /.swagger-codegen/VERSION /.travis.yml +/git_push.sh -# Firefly III YAML files -/firefly-*.yaml +# Swagger schema files +/openapi.yaml diff --git a/generate.sh b/generate.sh index b20d022..9381771 100755 --- a/generate.sh +++ b/generate.sh @@ -2,24 +2,27 @@ swagger_codegen_jar=~/.local/bin/swagger-codegen-cli-3.0.54.jar -if [ $# -eq 0 ]; then - echo "Usage: $0 " - exit 1 -fi +swagger_spec="openapi.yaml" -swagger_spec=$1 - -if [ ! -f "$swagger_spec" ]; then - echo "Swagger spec file not found: $swagger_spec" - exit 1 -fi +# download api spec +url=$(curl -s https://api-docs.firefly-iii.org | grep -oP '(?<=url: ")[^"]*v1[^"]*' | head -n 1) +url="${url#./}" +echo $url +full_url="https://api-docs.firefly-iii.org/$url" +echo $full_url +curl -o openapi.yaml "$full_url" # rm old files -rm *.go -rm git_push.sh -rm README.md -rm -R docs -rm -R api +rm -R\ + *.go \ + git_push.sh \ + README.md \ + .swagger-codegen-ignore \ + .travis.yml \ + docs \ + api \ + test \ + .swagger-codegen # generate new spec java -jar "$swagger_codegen_jar" generate -i "$swagger_spec" -l go -o . @@ -58,9 +61,10 @@ cat >> .gitignore << EOL /.swagger-codegen-ignore /.swagger-codegen/VERSION /.travis.yml +/git_push.sh -# Firefly III YAML files -/firefly-*.yaml +# Swagger schema files +/$swagger_spec EOL # add info to README.md diff --git a/go.mod b/go.mod index c2cc113..846fe82 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.22.2 require ( github.com/antihax/optional v1.0.0 - golang.org/x/oauth2 v0.19.0 + golang.org/x/oauth2 v0.20.0 ) diff --git a/go.sum b/go.sum index 6d33a95..3cb9426 100644 --- a/go.sum +++ b/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/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 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.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= +golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= +golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=