document-api-endpoint
Document & Type a Sentry API Endpoint
Add or fix OpenAPI docs for a Sentry endpoint with drf-spectacular. Full reference is at https://develop.sentry.dev/backend/api/public/, the most useful section to you will be https://develop.sentry.dev/backend/api/public/#5-method-decorator. This skill captures the non-obvious lessons on top of it. Most of the work is making the declared schema match what the endpoint actually returns. Before documenting, identify which endpoint class serves the route and what it does; the MCP tool that calls it is usually the fastest way to confirm its behavior. Promoting a PRIVATE/EXPERIMENTAL endpoint to PUBLIC is one application (see below).
Workflow
- Class-level
@extend_schema(tags=[...])— use the closest existingOPENAPI_TAGSentry. - Method-level
@extend_schema(operation_id=..., parameters=[...], responses={...}, examples=...). - Reuse
src/sentry/apidocs/parameters.pyandexamples/*.py; ensureowner = ApiOwner.<TEAM>is set. - If a legacy
api-docs/paths/**/*.jsoncovers the path, remove it (see lesson 4). - Validate, then verify against the live endpoint (lesson 1).
Lessons
1. Carefully compare what the code does vs declared types
Ideally, hit the live endpoint with a real token and diff the keys and types against your TypedDict. Serializers are sometimes inaccurate. Look out for counts coming back as floats instead of integers, IDs declared int emitted as strings, nested types declaring the wrong number of fields. Correct the declared type to match runtime.
curl -s -H "Authorization: Bearer $TOKEN" "https://us.sentry.io/api/0/<endpoint>" | jq 'keys'