Repository navigation
feat(apidocs): Add S034 lint for undocumented inline 4xx responses - #131072
Merged
Merged
Conversation
Flag a 4xx Response that an @extend_schema(responses=...) method returns inline when that status isn't a key in responses=. Document the 4xx statuses the 43 existing violating methods already return, using the RESPONSE_* constants (adds RESPONSE_GONE for 410). No runtime behavior change. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
BYK
approved these changes
Nov 13, 2026
BYK
left a comment
Member
There was a problem hiding this comment.
Two follow-ups would close the gaps the rule leaves: tightening the mypy plugin so error bodies are checked against their TypedDict (handled separately), and a test-time check of responses against the generated schema (#131073).
Let's do these.
BYK
enabled auto-merge (squash)
November 13, 2026 15:39
…ented-4xx # Conflicts: # tools/flake8_plugin.py
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.
#131067 had to add the 402 and 409 responses that the Seer Autofix start endpoint already returned but its
@extend_schema(responses=...)never listed. Until then,@sentry/apityped those errors asunknown. This adds a flake8 rule, S034, that catches that kind of omission when the endpoint is written. Requested by @BYK after the review question on #131067.What S034 checks: a class method with
@extend_schema(responses={...})that writesreturn Response(..., status=...)with a 4xx status, either a literal or astatus.HTTP_4xx_*/HTTP_4xx_*name. If that status isn't a key inresponses=, the rule fires.(status, media_type)tuple keys and digit-string keys count as documented. Run on the pre-#131067 version ofgroup_ai_autofix.py, it flags all six of the 402/409 returns that PR documented.What it doesn't check, as the rule's docstring says, so passing doesn't mean every 4xx is documented:
return handle_ui_feedback(...);responses=values it can't read statically (a name, a**spread, a non-literal key). The method is skipped rather than guessed at.Two follow-ups would close the gaps the rule leaves: tightening the mypy plugin so error bodies are checked against their TypedDict (handled separately), and a test-time check of responses against the generated schema (#131073).
Existing violations: 95 inline returns in 43 methods across 30 files, all in
src/. getsentry has noextend_schemaendpoints. Every one returns a status its schema didn't list, so I documented each with the existingRESPONSE_*constant instead of baselining them: 400, 401, 403, 404, 409 and 429. This addsRESPONSE_GONEfor the one 410. Like S021–S023, the rule then runs with no baseline, andtests/*is exempt the same way. These are schema-only additions, with no runtime behavior change. Where a status has a known body shape, a typed response like the ones in #131067 can replace the generic constant later.The optional prod-vs-dev schema diff check fails by design here: the schema gains those response entries, and nothing is removed.
via @BYK.
--
View Session [Sentry]