Skip to content

feat(apidocs): Check test responses against the OpenAPI schema - #131077

Merged
BYK merged 3 commits into
masterfrom
byk/poc/openapi-response-check
Nov 20, 2026
Merged

BYK merged 3 commits into
masterfrom
byk/poc/openapi-response-check

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Refs #131073

Our OpenAPI docs drift from what endpoints actually return, and nothing catches it. This compares the responses tests get from public operations with the schema drf-spectacular generates from the code:

  • S036: the status isn't in the operation's responses
  • S037: the JSON body doesn't match that status's schema

304, 429 and 5xx are exempt: a 304 only answers a conditional request, the rate limiter can return a 429 from any endpoint, and a 5xx is a bug rather than part of the contract. S035 is taken by #130924.

This stands alone and doesn't touch the API guidelines work in #131117 → #131088 → #131135 → #131407. Findings use the same signature (endpoint file, EndpointClass.method, status:<code>, owner) and entry shape as that stack's exceptions.json, which is where the baseline goes once the stack lands.

The pytest plugin is opt-in, with two modes. Report mode records findings and annotates endpoints whose findings aren't baselined. Strict mode also fails the test that got one. The schema is generated while xdist workers start, so it always matches the code and doesn't need node.

A new baseline tool adds a run's findings to a baseline file. It only touches the endpoint methods that run called, and keeps reviewed statuses.

Backend CI runs in report mode, so nothing blocks merges. CI moves to strict mode together with the baseline.

via @BYK.

--

View Session [Sentry]

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 13, 2026
@sentry-junior
sentry-junior Bot force-pushed the byk/poc/openapi-response-check branch from 0b2e0e5 to b02d5c9 Compare November 17, 2026 19:38
@sentry-junior sentry-junior Bot changed the title feat(apidocs): Opt-in check of test responses against the OpenAPI schema feat(apidocs): Check test responses against the OpenAPI schema Nov 17, 2026
@sentry-junior
sentry-junior Bot changed the base branch from master to akhilpindiprolu/eng-9065-read-the-report-card-from November 17, 2026 20:57
Every response the Django test client gets from a public operation is
checked against the schema drf-spectacular generates from the code: its
status must be documented (S036) and its JSON body must match that
status's schema (S037). The pytest controller generates the schema in a
subprocess while xdist workers start, so it never goes stale.

Findings are keyed like the API guidelines findings (endpoint file,
class and method, status) and recorded in
tests/apidocs/openapi-response-baseline.json by
`make api-response-baseline`, in the exceptions.json entry shape.

CI runs it in report mode: findings that aren't baselined become warning
annotations and every shard uploads its report. Strict mode, which fails
the test, is opt-in.

Refs #131073

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot force-pushed the byk/poc/openapi-response-check branch from b02d5c9 to b31581d Compare November 17, 2026 21:06
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 17, 2026
@sentry-junior
sentry-junior Bot changed the base branch from akhilpindiprolu/eng-9065-read-the-report-card-from to master November 17, 2026 21:06
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

No findings on the latest commit.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Type Coverage Diff

Metric Before After Delta
Coverage 95.64% 96.05% 🟢 +0.41%
Typed 141,752 143,498 🟢 +1746
Untyped 6,458 5,894 🟢 -564
🔍 21 new type safety issues introduced

any-typed symbols (4 new)

File Line Detail
static/app/utils/url/qs.tsx 171 values (var)
static/app/utils/url/qs.tsx 173 item (var)
static/app/views/performance/tracingEmptyState.tsx 163 docParams (var)
static/app/views/performance/tracingEmptyState.tsx 228 docs (var(binding))

Non-null assertions (!) (2 new)

File Line Detail
static/app/components/seer/outOfCredits/messages.tsx 138 states[0]!
static/app/utils/url/qs.tsx 149 parsed[key]!

Type assertions (as) (15 new)

File Line Detail
static/app/components/events/autofix/useExplorerAutofix.tsx 356 `as
| null
| undefined` — `e as | {responseJSON?: {code?: unknown}; status?: number} | null | undefined` |

| static/app/components/seer/outOfCredits/__stories__/seerCreditCheckStub.tsx | 27 | as never — queryFn as never |
| static/app/utils/replays/breadcrumbTypes.tsx | 32 | as BreadcrumbType[] — Object.keys(BREADCRUMB_TYPE_LABELS) as BreadcrumbType[] |
| static/app/utils/url/qs.tsx | 140 | as string[] — [ ...(Array.isArray(existing) ? existing : [existing]), value, ] as string[] |
| static/app/views/seerWorkflows/automations/detail/index.snapshots.tsx | 70 | as ReturnType<typeof useFetchConfigs> — { data: undefined, isPending: false, isError: false, refetch: jest.fn(), ...res… |
| static/app/views/seerWorkflows/automations/index.snapshots.tsx | 103 | as ReturnType<typeof useFetchConfigs> — { data: undefined, isPending: false, isLoadingError: false, refetch: jest.fn(),… |
| static/app/views/seerWorkflows/automations/index.snapshots.tsx | 112 | as ReturnType<typeof useMonitorsById> — {data: MONITORS} as ReturnType<typeof useMonitorsById> |
| static/app/views/seerWorkflows/automations/runs/runsTable.snapshots.tsx | 27 | as SeerAutomationRun — { id: '1', configId: '1', configName: null, strategy: 'breached_metric_investig… |
| static/app/views/seerWorkflows/automations/runs/runsTable.snapshots.tsx | 43 | as Execution — { id: '1', seerRunId: null, dateAdded: minutesAgo(125), dateUpdated: minutesAgo… |
| static/app/views/seerWorkflows/automations/runs/runsTable.snapshots.tsx | 153 | as SeerAutomationRun['trigger'] — {type: 'manual_backfill'} as unknown as SeerAutomationRun['trigger'] |
| static/app/views/seerWorkflows/automations/runs/runsTable.snapshots.tsx | 153 | as unknown — {type: 'manual_backfill'} as unknown |
| static/app/views/seerWorkflows/automations/runs/runsTable.snapshots.tsx | 189 | as Execution['outputs'] — [ {type: 'report', id: '12', title: 'Weekly report'}, ] as unknown as Execution… |
| static/app/views/seerWorkflows/automations/runs/runsTable.snapshots.tsx | 189 | as unknown — [ {type: 'report', id: '12', title: 'Weekly report'}, ] as unknown |
| static/app/views/seerWorkflows/automations/snapshotTestUtils.tsx | 115 | as keyof typeof lightTheme.container — breakpoint as keyof typeof lightTheme.container |
| static/gsApp/views/subscriptionPage/seerWallet/autoTopUpModal.tsx | 499 | as PaymentRequiredResponse | undefined — error.responseJSON as PaymentRequiredResponse | undefined |

This is informational only and does not block the PR.

@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 17, 2026 21:58
@sentry-junior
sentry-junior Bot requested review from a team as code owners November 17, 2026 21:58

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b31581d. Configure here.

@github-actions github-actions Bot removed the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 17, 2026
A request through an alias route, such as /organizations/{org}/groups/{id}/ or
/issues/{id}/ without the organization, matched no schema path and was skipped.
When the request path matches no template, map the resolved route to its schema
path with the enumerator and _canonical_issue_path the schema build uses.

Refs #131073

Co-Authored-By: BYK <[email protected]>
@sentry-junior

sentry-junior Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Ported the route-alias mapping from the closed #131098 in be2aca8.

Until now, a request through an alias route found no schema path and was skipped without a report. That covers /organizations/{org}/groups/{id}/, the org-less /issues/{id}/ and /groups/{id}/, and the other paths the schema build canonicalizes. Now, when SchemaIndex.find matches no template, SchemaIndex.find_route maps resolver_match.route to its documented path. It uses CustomEndpointEnumerator.get_path_from_regex plus _canonical_issue_path, the same functions the schema build uses, and caches the result per route. The direct template match is unchanged, and the fallback only runs for DRF views that find didn't match.

One behavior change: resolver_match is now evaluated for every request, not only the ones that match a template. A resolve() costs about 50–70 µs here.

I added regression tests to test_openapi_responses.py. A groups alias, /api/0/groups/{id}/ and /api/0/issues/{id}/ each get checked against the documented issues operation and report their undocumented 402. Before the change, all three were skipped. A route the schema doesn't document is still skipped.

Overhead measured on #131098, which used the same per-operation validator caching: on a 452-test endpoint slice run serially, the check took about 0.9 ms per checked response (0.51–0.53 s in total for 567 responses, with the schema load). That is roughly 0.35% of the run, and smaller than the run-to-run noise in wall time.

@BYK
BYK merged commit d4b2649 into master Nov 20, 2026
106 checks passed
@BYK
BYK deleted the byk/poc/openapi-response-check branch November 20, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant