This repository was archived by the owner on Nov 16, 2026. It is now read-only.
Repository navigation
feat(validators): Attach OpenAPI descriptions to Valibot and Zod schemas - #128
Merged
Merged
Conversation
Turn on the Hey API `metadata` option for both validator plugins, so field
schemas carry their OpenAPI description at runtime.
Valibot's plugin emits `v.metadata({ description })`, which
`v.getDescription()` does not read. A post-processing step rewrites it to
`v.description(...)`, and drops the description pipe from top-level schemas:
`v.pick`, `v.omit`, `v.partial` and `v.required` reject piped object schemas,
and the top-level description is already in the JSDoc comment. Zod's plugin
registers the description in `z.globalRegistry`, which `.description` and
`z.toJSONSchema()` read, so its output is used as is.
Co-Authored-By: BYK <[email protected]>
sentry-junior
Bot
requested review from
BYK,
MathurAditya724 and
betegon
as code owners
November 4, 2026 14:40
Hey API's validator plugins attach descriptions only to typed schemas, so an OpenAPI 3.0 nullable field, a union with null in the IR, lost its description. Copy it onto the field's non-null branch before the validator plugins run. Co-Authored-By: BYK <[email protected]>
BYK
approved these changes
Nov 4, 2026
BYK
approved these changes
Nov 4, 2026
2 tasks done
jackeddisciple
pushed a commit
to jackeddisciple/sentry
that referenced
this pull request
Nov 5, 2026
…getsentry#129963) TypedDict response fields can't carry a description into the OpenAPI spec today. `resolve_type_hint` reads TypedDict hints without extras, and only a nested TypedDict's class docstring ever shows up (there's a `TODO: figure out solution for field descriptions`). As a result, only **48 of 2,890 (1.7%)** top-level 2xx response properties in the public spec have a description. Request bodies and parameters are at 99.9%. ### Mechanism A new `ApiDescription` marker in `sentry.apidocs.descriptions`, used through `Annotated`: ```python class BaseTeamSerializerResponse(TypedDict): isMember: Annotated[bool, ApiDescription("Whether the requesting user is a member of the team")] ``` How it works: - In the TypedDict branch of `resolve_type_hint`, the hints are also read with `include_extras=True`. Each field's hint has `Required`/`NotRequired`/`ReadOnly` and `Annotated` unwrapped, and the property gets its `description` from the marker. - Field types still resolve from the stripped hints exactly as before, so `__required_keys__` and other `Annotated` metadata are unaffected. - A field description replaces a nested TypedDict's docstring for that property. What stays the same: - mypy only sees the inner type, so field types and runtime behavior don't change. - It works with `from __future__ import annotations` and with functional `TypedDict(...)` definitions. Tests are in `tests/sentry/apidocs/test_spectacular_ports.py`. That's where the existing `resolve_type_hint` tests live; `tests/apidocs/` holds endpoint doc tests. ### Fields These are the response fields the Sentry CLI documents by hand today. The wording is seeded from the CLI text and made API-neutral, e.g. "Whether you bookmarked it" became "Whether the requesting user bookmarked the project". | Owner | Files | Fields | |---|---|---| | `@getsentry/app-backend` | `api/serializers/models/{event,group,organization,project,team}.py`, `api/serializers/types.py` (releases) | 12 + 11 + 10 + 12 + 4 + 19 = 68 | | `@getsentry/replay` | `replays/post_process.py` (`ReplayDetailsResponse`) | 30 | | `@getsentry/alerts-monitors` | `workflow_engine/.../{workflow,detector}_serializer.py` | 4 | | no CODEOWNERS entry | `tagstore/types.py` | 2 | | `@getsentry/owners-api` | `apidocs/spectacular_ports.py`, `apidocs/descriptions.py`, tests | mechanism | ### Spec impact I compared `make build-api-docs` output from `master` with output from this branch: - `openapi-derefed.json` gains **970 `description` keys**. No existing value changes and nothing else differs. - One exception: the workflow action `priority` enum comes out in a different order, but that order changes from one build to the next, with or without this change. - 2xx response properties with a description: - top-level: 48/2,890 (1.7%) → **351/2,890 (12.1%)** - nested: 62/8,288 (0.7%) → **628/8,288 (7.6%)** - Operations with any described response property: 11 → **61**. - `validate-api-examples` and `build-investigation-api-docs` pass. ### Why This is for getsentry/toolkit#1853. The CLI's `--help` field tables and skill references wrap generated `@sentry/api` Valibot fields in hand-written descriptions that drift from the API. The CLI has 84 such descriptions on API fields; the spec described 4 of them before this change, and it describes all 84 with it. That lets the CLI drop its copies, and the public API docs gain field descriptions too. Paired with getsentry/sentry-api-schema#128, which emits these descriptions in the generated Valibot and Zod schemas. Once this merges and the spec syncs, `@sentry/api` publishes them and the toolkit can bump and remove its duplicates. ### Verification - `tests/sentry/apidocs/` (117 passed). - `tests/sentry/replays/test_post_process.py`, `tests/sentry/tagstore/test_types.py` and `tests/sentry/api/serializers/test_team.py` pass locally. - mypy (pre-push hook) and `prek` pass on the touched files. - The other serializer and `tests/apidocs` endpoint tests need Snuba, which I don't have locally, so I left those to CI. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A98eff8ed01bc8064aba01279b3ac82c3 --> -- [View Session in Sentry](https://sentry.sentry.io/explore/conversations/agent%3A98eff8ed01bc8064aba01279b3ac82c3/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <[email protected]>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The generated Valibot and Zod schemas drop every OpenAPI description, so consumers can't read field docs at runtime. The toolkit CLI hand-writes
pipe(field, description("…"))for its--helpfield tables and skill references, and those drift from the spec.This turns on Hey API's
metadataoption for both plugins.v.metadata({ description }), andv.getDescription()doesn't read that. A new step,scripts/describe-valibot-schemas.mjs, rewrites it tov.description(…). It also drops the description pipe from top-level schemas, becausev.pick/v.omit/v.partial/v.requiredreject piped object schemas. Their description is already in the JSDoc, and for responses it's mostly status text like "No Content". Every top-level export keeps its type head. The step fails closed on any metadata shape it doesn't expect.nullablefield lost its description in both plugins. Aplugin:handler:beforehook copies the field's description onto its one non-null branch.types.gen.tsdoesn't change..register(z.globalRegistry, { description })..descriptionandz.toJSONSchema()read that. The type is unchanged. This part is optional: drop thezodentry's options if we don't want Zod descriptions yet.export const vDeployResponse = v.object({ - id: v.string(), + id: v.pipe(v.string(), v.description('The ID of the deploy')), - name: v.nullable(v.string()), + name: v.nullable(v.pipe(v.string(), v.description('The optional name of the deploy'))),Coverage today
In
openapi-derefed.json, 48 of 2,879 top-level 2xx response properties have a description (1.7%), or 62 of 8,263 counting nested ones (0.8%), across 11 operations. Request body properties and parameters are 99.9% described at the top level. So for now this mostly surfaces request descriptions. Response coverage has to come from the serializers in getsentry/sentry. getsentry/sentry#129963 raises it to 351 of 2,890 (12.1%) at the top level and 628 of 8,288 (7.6%) nested. That covers every API field the Sentry CLI describes by hand.Size
dist/valibot.jsdist/zod.jsdist/valibot.gen.d.tsdist(gzip)vGetOrganizationResponseonly (min / gzip)The Valibot output has 2,376 descriptions. With the toolkit CLI's typecheck on this build,
tscmemory goes up about 2.5%, and check time stays within noise. The CLI's npm JS and the@sentry/mcp-serverbundle each grow about 2 KB.via @BYK.
--
View Session in Sentry