Repository navigation
feat(apidocs): Report test responses that don't match the OpenAPI schema - #131098
Open
sentry-junior[bot] wants to merge 2 commits into
Open
sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
APITestCase.get_response now checks each response from a PUBLIC method against tests/apidocs/openapi-derefed.json: the status must be documented in the operation's responses, and a JSON body must match the schema documented for that status. Mismatches are reported after the run and written to .artifacts/api-response-schema.json. Nothing fails yet: known mismatches are in tests/apidocs/response-schema-baseline.txt, and SENTRY_API_RESPONSE_SCHEMA=strict fails only on new ones. Refs #131073 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1e61f13. Configure here.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

First, report-only step for #131073. Nothing compared what a public endpoint returns with what its schema says, so an undocumented 402/409 like the one fixed in #131067 went unnoticed.
APITestCase.get_response, and with itget_success_responseandget_error_response, now compares each response from aPUBLICmethod withtests/apidocs/openapi-derefed.json. The resolved route maps to its schema path through the enumerator the schema build uses, so aliases such asgroups/issuesresolve to the documented path. It reports two kinds of mismatch:responses. Undocumented 5xx statuses are ignored.RESPONSE_NOT_FOUND, only has its status compared.Each process loads the schema once with
orjson, without building anopenapi_coreSpec, and caches one validator per operation and status. xdist workers send their findings to the controller, which prints a summary and writes.artifacts/api-response-schema.json. Without a readable schema it prints one line and skips the comparison. Public operations missing from the schema are counted, since that usually means the schema is stale.SENTRY_API_RESPONSE_SCHEMAsets the mode:report(default) only summarizes,strictfails a test on a mismatch that isn't intests/apidocs/response-schema-baseline.txt,updateadds new mismatches to that baseline, andoffdisables it. Nothing fails by default. "Responses seen in tests" insrc/sentry/apidocs/README.mddescribes it.Rollout: report-only (this PR) → build the schema in backend CI and complete the baseline →
strictin CI as a ratchet → prune the baseline as endpoints are fixed.Open questions:
openapi-derefed.jsonyet. Should it build the schema before the backend tests, or download it as an artifact?get_responseto the test client, so that tests callingself.clientdirectly are compared too?PUBLIC_EXPERIMENTALoperations are published but not compared yet. Include them?Refs #131073
via @BYK.
--
View Session [Sentry]