From 5c32f41f22cd94e191f96e6b51762915a029c38d Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 15 Mar 2026 16:22:50 +0200 Subject: [PATCH] ci: add GitHub Action to auto-generate OpenAPI SDK types Adds workflow that triggers on server code changes to: - Export OpenAPI spec from NestJS Swagger module - Generate TypeScript types with openapi-typescript - Build the SDK package - Create PR with changes if any exist Co-Authored-By: Claude Opus 4.6 --- .github/workflows/generate-openapi.yml | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/generate-openapi.yml diff --git a/.github/workflows/generate-openapi.yml b/.github/workflows/generate-openapi.yml new file mode 100644 index 000000000..e9887a8c6 --- /dev/null +++ b/.github/workflows/generate-openapi.yml @@ -0,0 +1,83 @@ +name: Generate OpenAPI SDK Types + +on: + push: + branches: + - main + - develop + paths: + - 'packages/server/src/**/*.ts' + - 'packages/server/src/**/*.dto.ts' + - '!packages/server/src/**/*.spec.ts' + - '!packages/server/src/**/*.test.ts' + workflow_dispatch: + +defaults: + run: + shell: 'bash' + +jobs: + generate-openapi: + name: Generate OpenAPI and SDK Types + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Generate OpenAPI spec and SDK types + run: pnpm run generate:sdk-types + + - name: Check for changes + id: check-changes + run: | + if git diff --quiet shared/sdk-ts/; then + echo "has_changes=false" >> $GITHUB_OUTPUT + else + echo "has_changes=true" >> $GITHUB_OUTPUT + fi + + - name: Create Pull Request + if: steps.check-changes.outputs.has_changes == 'true' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: 'chore(sdk): update OpenAPI spec and generated types' + title: 'chore(sdk): update OpenAPI spec and generated types' + body: | + ## Summary + Automated update of OpenAPI specification and generated TypeScript SDK types. + + This PR was automatically generated by the `generate-openapi.yml` workflow due to server code changes. + + ## Changes + - Updated `shared/sdk-ts/openapi.json` + - Regenerated `shared/sdk-ts/src/schema.ts` + + ## Test plan + - [ ] Verify the generated types compile correctly + - [ ] Check that no breaking changes were introduced to the API types + branch: chore/update-openapi-sdk-types + base: ${{ github.ref_name }} + labels: | + automated + sdk + delete-branch: true