Skip to content

Commit

Permalink
build openapi spec from golang annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
CubicrootXYZ committed Oct 6, 2024
1 parent d27b17f commit 5eaf727
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/openapi2_golang_build.yaml
Original file line number Diff line number Diff line change
@@ -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 ${{ inputs.entrypoint }}
- name: Archive OpenAPI spec
uses: actions/upload-artifact@v4
with:
name: openapi-spec
path: |
docs/
7 changes: 7 additions & 0 deletions .github/workflows/openapi2_golang_build_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
on: push

jobs:
openapi2_golang_build_test:
uses: ./.github/workflows/openapi2_golang_build.yaml
with:
entrypoint: tests/openapi2/main.go
3 changes: 3 additions & 0 deletions tests/openapi2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module openapi2

go 1.23.0
22 changes: 22 additions & 0 deletions tests/openapi2/main.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5eaf727

Please sign in to comment.