API Contract: Automate Schema Updates#892
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a CLI to export the FastAPI OpenAPI schema, a GitHub Actions workflow that diffs base vs head schemas with oasdiff and posts a Markdown PR comment, enforces a merge gate for breaking changes, and updates LLM response models by adding ChangesOpenAPI Diffing and API Schema Validation
Sequence DiagramsequenceDiagram
participant Actions as GitHub Actions
participant ExportScript as kaapi_export_openapi.py
participant OASDiff as tufin/oasdiff
participant Formatter as WorkflowFormatter
participant StickyComment as PR Sticky Comment
Actions->>ExportScript: export base openapi.yaml (bootstrap script if missing)
Actions->>ExportScript: export head openapi.yaml
Actions->>OASDiff: run breaking diff (base vs head)
Actions->>OASDiff: run full changelog diff (base vs head)
OASDiff->>Actions: breaking.json, changelog.json
Actions->>Formatter: render JSON -> Markdown tables (with counts)
Actions->>StickyComment: post/update sticky PR comment and write step summary
alt breaking changes detected AND label missing
StickyComment->>Actions: workflow fails (merge gate)
else approved or no breaking changes
StickyComment->>Actions: workflow passes
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…contract' into chore/diffs-in-api-contract
|
restart PR |
|
test the oasdiff workflow queued forever |
OpenAPI changes ⚪ No API surface changesNote This PR does not modify the API contract.
|
17097d4 to
c40815b
Compare
|
CI will auto enable after the tests (removing mandatory params removed) |
…contract' into chore/diffs-in-api-contract
Ayush8923
left a comment
There was a problem hiding this comment.
Added the few comments.
|
|
||
| on: | ||
| pull_request: | ||
| branches: ["main"] |
There was a problem hiding this comment.
Not need this branches filter here, run on PRs targeting any base branch.
There was a problem hiding this comment.
let's run it on main, since that's where the action is i.e to be deployed in staging; other base branches (that eventually will me merged to main so redundant) or prod. We can add other branches in future if we have separate releases for staging and prod
There was a problem hiding this comment.
Mostly to reduce github actions quota
| # get_settings() loads `../.env.test` relative to the backend cwd when | ||
| # ENVIRONMENT=testing, so the file must sit at the repo root of each checkout. |
There was a problem hiding this comment.
Remove these unwanted comments.
| cp "$GITHUB_WORKSPACE/head/backend/scripts/export_openapi.py" scripts/ | ||
| uv run python scripts/export_openapi.py "$GITHUB_WORKSPACE/base-openapi.yaml" |
There was a problem hiding this comment.
Can we change the file name from export_openapi and use similar related to kaapi?
Co-authored-by: Ayush <80516839+Ayush8923@users.noreply.github.com>
Co-authored-by: Ayush <80516839+Ayush8923@users.noreply.github.com>
Co-authored-by: Ayush <80516839+Ayush8923@users.noreply.github.com>
Co-authored-by: Ayush <80516839+Ayush8923@users.noreply.github.com>
Co-authored-by: Ayush <80516839+Ayush8923@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.github/workflows/api-breaking-changes.yaml (1)
173-177: ⚡ Quick winSticky comment won't post if an earlier step fails.
This step uses the default
if: success(). If the diff/build steps fail (e.g., theOASDIFF_IMAGEissue above), the comment is silently skipped even though "Build PR comment body" runs underif: always(). Addif: always()so the report still posts.Proposed fix
- name: Post sticky PR comment + if: always() uses: marocchino/sticky-pull-request-comment@v3🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/api-breaking-changes.yaml around lines 173 - 177, The "Post sticky PR comment" job step uses the default conditional and is skipped if earlier steps fail; update the step titled "Post sticky PR comment" that uses marocchino/sticky-pull-request-comment@v3 (with header: oasdiff and path: comment.md) to include "if: always()" so it runs regardless of prior step failure and ensures the built comment is posted.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/api-breaking-changes.yaml:
- Around line 6-7: The branches filter contains an invalid pattern ("-- '**'")
that prevents the workflow from triggering; edit the YAML under the branches key
to either remove the branches filter entirely for the pull_request trigger
(since pull_request without branches matches all targets) or correct the list
entry to a single hyphen and proper glob ('- "**"') so it reads branches:
followed by - "**"; update the entry that currently reads "-- '**'" to one of
these two fixes in the workflow file.
- Around line 78-90: The workflow step fails because the shell function run_diff
uses the undefined variable OASDIFF_IMAGE; define OASDIFF_IMAGE at the job or
step level before run_diff is invoked (e.g., export or env entry) and set it to
a pinned oasdiff image tag or digest (not latest) for reproducibility; update
the workflow to ensure OASDIFF_IMAGE is available in the run environment so
run_diff (and its calls run_diff changelog changelog.json / run_diff breaking
breaking.json) can successfully execute and produce the JSON outputs.
---
Nitpick comments:
In @.github/workflows/api-breaking-changes.yaml:
- Around line 173-177: The "Post sticky PR comment" job step uses the default
conditional and is skipped if earlier steps fail; update the step titled "Post
sticky PR comment" that uses marocchino/sticky-pull-request-comment@v3 (with
header: oasdiff and path: comment.md) to include "if: always()" so it runs
regardless of prior step failure and ensures the built comment is posted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 17f0621f-97de-43e8-9a8d-a2a382fe5f6a
📒 Files selected for processing (3)
.github/workflows/api-breaking-changes.yamlbackend/app/models/llm/response.pybackend/scripts/kaapi_export_openapi.py
| class CallbackResponse(SQLModel): | ||
| status: str | ||
| response_id: str | ||
| # status: str |
There was a problem hiding this comment.
make sure to uncomment this before merging
|
|
||
| job_id: UUID | ||
| status: str | ||
| # status: str |
| job_id: UUID | ||
| status: str | ||
| message: str | ||
| test: str | None = None |
…contract' into chore/diffs-in-api-contract
Issue: #885
Summary
Currently breaking changes stay latent unless specified explicitly by the developer. This PR adds
oasdiffa CI tool to automate the process of seeing diffs acrossbaseandmainOpenAPI schemas. If the breaking changes are deliberate the developer can addbreaking-change-approvedtag to pass the test. It's defaulted to fail on making breaking changes. Also changelog of API is shown.Checklist
Before submitting a pull request, please ensure that you mark these task.
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Notes