From 0ad5d80654fae677a4cd673e6bfb0beeabe9026d Mon Sep 17 00:00:00 2001 From: cubicroot Date: Sun, 6 Oct 2024 09:06:50 +0200 Subject: [PATCH] build openapi spec from golang annotations --- .github/workflows/openapi2_golang_build.yaml | 35 +++++++++++++++++++ .../workflows/openapi2_golang_build_test.yaml | 7 ++++ tests/openapi2/main.go | 22 ++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/openapi2_golang_build.yaml create mode 100644 .github/workflows/openapi2_golang_build_test.yaml create mode 100644 tests/openapi2/main.go diff --git a/.github/workflows/openapi2_golang_build.yaml b/.github/workflows/openapi2_golang_build.yaml new file mode 100644 index 0000000..809d170 --- /dev/null +++ b/.github/workflows/openapi2_golang_build.yaml @@ -0,0 +1,35 @@ +on: + workflow_call: + inputs: + entrypoint: + required: true + type: string + default: "main.go" + +jobs: + build_with_swagger: + runs-on: ubuntu-latest + if: "!startsWith(github.ref, 'refs/tags/')" + container: + image: cubicrootxyz/golang-ci:v1.23.0 + options: --user root + steps: + - name: Checkout the repository + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + - uses: actions/setup-node@v3 + with: + node-version: "14" + - name: Get dependencies + run: go get ./... + - name: Make docs folder + run: mkdir -p docs + - name: Build the api documentation + run: swag init --parseDependency=true -d . -g cmd/remindme/main.go + - name: Archive OpenAPI spec + uses: actions/upload-artifact@v4 + with: + name: openapi-spec + path: | + docs/ \ No newline at end of file diff --git a/.github/workflows/openapi2_golang_build_test.yaml b/.github/workflows/openapi2_golang_build_test.yaml new file mode 100644 index 0000000..481fb51 --- /dev/null +++ b/.github/workflows/openapi2_golang_build_test.yaml @@ -0,0 +1,7 @@ +on: push + +jobs: + openapi2_golang_build_test: + uses: ./.github/workflows/openapi2_golang_build.yaml + with: + entrypoint: tests/openapi2/main.go \ No newline at end of file diff --git a/tests/openapi2/main.go b/tests/openapi2/main.go new file mode 100644 index 0000000..320a5cd --- /dev/null +++ b/tests/openapi2/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "os" +) + +// @title Matrix Reminder and Calendar Bot (RemindMe) +// @version 2.0.0 +// @description API documentation for the matrix reminder and calendar bot. + +// @contact.name Support + +// @host your-bot-domain.tld +// @BasePath / +// @query.collection.format multi + +// @securityDefinitions.apikey APIKeyAuthentication +// @in header +// @name Authorization +func main() { + os.Exit(0) +}