Skip to content

build: track the OpenAPI spec and regenerate the client in pre-commit - #177

Merged
lewisjared merged 4 commits into
mainfrom
chore/track-openapi-spec
Nov 4, 2026
Merged

lewisjared merged 4 commits into
mainfrom
chore/track-openapi-spec

Conversation

@lewisjared

@lewisjared lewisjared commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Tracks the OpenAPI spec as backend/openapi.json and adds a pre-commit hook that runs make generate-client, so API schema changes show up in review as a spec diff instead of only through types.gen.ts.

  • The hook runs when backend/src/, backend/uv.lock, scripts/generate-client-sdk.sh backend/openapi.json, frontend/openapi-ts.config.ts or frontend/package.json changes, and fails the commit when the spec or client moved, like any fixing hook.
  • The spec is written with indent=2 for readable diffs. Regenerating on main leaves the client unchanged, so it was already in sync.
  • It adds about 8 seconds to backend commits, and the first run fetches openapi-ts through npx.

Checked by making ExecutionOutput.filename nullable and committing. The hook failed and rewrote both backend/openapi.json and types.gen.ts.

CI does not run pre-commit, so a --no-verify commit can still drift. A CI job running make generate-client then git diff --exit-code would close that, and I left it out to keep this small. Whichever of this and #173 merges second needs the spec regenerated, because #173 changes ExecutionOutput.

Commits frontend/openapi.json, written with indentation so schema changes show as readable diffs.
A pre-commit hook runs make generate-client when backend code, the lock file or the generator config changes, and fails the commit if the spec or client moved.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d984053-f99c-4c69-ba92-b48be0f848b2
Commits

Reviewing files that changed from the base of the PR and between 7130f0f and 2a5266a.

Files selected for processing: 8
  • .pre-commit-config.yaml
  • README.md
  • backend/openapi.json
  • changelog/177.trivial.md
  • frontend/.gitignore
  • frontend/README.md
  • frontend/openapi-ts.config.ts
  • scripts/generate-client-sdk.sh
Walkthrough

The OpenAPI JSON output now uses two-space indentation and is no longer ignored. A serial pre-commit hook runs client generation when matching backend, generator-script or OpenAPI paths change. The changelog records this workflow.

Changes: OpenAPI generation

Layer / File(s) Summary
Generation and tracking
scripts/generate-client-sdk.sh, frontend/.gitignore, .pre-commit-config.yaml, changelog/177.trivial.md
The generator writes indented OpenAPI JSON. The OpenAPI file is no longer ignored. A serial pre-commit hook runs make generate-client for matching paths without passing filenames. The changelog describes the tracked specification and hook.

Possibly related issues

Possibly related PRs

  • Climate-REF/ref-app#172: This PR changes backend API responses and generated client types; this change adds regeneration for backend changes.
  • Climate-REF/ref-app#147: This PR changes API routes and the generated frontend client; this change adds automatic regeneration.
  • Climate-REF/ref-app#173: This PR changes an API contract, and its description identifies OpenAPI regeneration as relevant when combined with this change.

Change: Other

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "build: track the OpenAPI spec and regenerate the client in pre-commit" matches the main changes. The PR adds frontend/openapi.json to version control (removed from frontend/.gitignore), and…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "build: track the OpenAPI spec and regenerate the client in pre-commit" matches the main changes. The PR adds frontend/openapi.json to version control (removed from frontend/.gitignore), and adds a pre-commit generate-client hook that runs make generate-client. The title is specific and concise, and a reviewer scanning history can identify the primary change.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (2 skipped: 2 unsupported.)

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Review coverage is incomplete: 1 file could not be fully reviewed. Findings from completed review steps are included; see review info for details.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lewisjared
lewisjared marked this pull request as ready for review November 4, 2026 00:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Nitpick comments: 1
.pre-commit-config.yaml: 1

71-77: Trivial · Data Integrity & Integration · Heavy lift

Add a CI job that fails when the committed OpenAPI spec or client is stale.

The pre-commit hook is the only step that regenerates frontend/openapi.json and frontend/src/client/. The hook is installed only by make setup, and git commit --no-verify skips it. No job in .github/workflows/ci.yml regenerates these files or compares them with the committed versions. The frontend build also uses the committed client without regenerating it. A stale spec or client can therefore merge.

Add a job that regenerates both files and fails on any difference, then add it to ci-pass so that it gates merges:

Suggested CI change
+  generated-client:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v7
+      - name: Install uv
+        uses: astral-sh/setup-uv@v10.3.2
+        with:
+          enable-cache: true
+      - name: Setup Node.js
+        uses: actions/setup-node@v7
+        with:
+          node-version: '24'
+      - name: Regenerate the OpenAPI spec and client
+        run: make generate-client
+      - name: Fail if the committed spec or client differs
+        run: test -z "$(git status --porcelain -- frontend/openapi.json frontend/src/client)"
     needs:
       - check-changelog
       - frontend
       - backend
+      - generated-client

Confirm that generation is deterministic on the runner before making the job required.

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f4f1555d-dca0-4a69-b588-cd2715257326
Commits

Reviewing files that changed from the base of the PR and between 7130f0f and eb45f49.

Files selected for processing: 5
  • .pre-commit-config.yaml
  • changelog/177.trivial.md
  • frontend/.gitignore
  • frontend/openapi.json
  • scripts/generate-client-sdk.sh
Files not fully reviewed because their changes were unavailable: 1
  • frontend/openapi.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread .pre-commit-config.yaml Resolved
The spec is generated from the backend, so it lives with it. The client generator reads it from there.
@lewisjared
lewisjared merged commit 7a12d24 into main Nov 4, 2026
7 checks passed
@lewisjared
lewisjared deleted the chore/track-openapi-spec branch November 4, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant