Skip to content

fix: respect nullable property in more places - #268

Open
deder-mw wants to merge 4 commits into
masterfrom
fix/respect-nullable-property
Open

deder-mw wants to merge 4 commits into
masterfrom
fix/respect-nullable-property

Conversation

@deder-mw

@deder-mw deder-mw commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

nullable: true was only turned into | null for component schemas (Components.Schemas). Schemas defined inline in an operation – request bodies, responses, parameters – kept their nullable flag, and the generated type silently dropped it.

The API relies on this, e.g. PATCH /v2/stacks/{stackId} documents x-update-schedule as "Set to null to remove the schedule", which the client could not express so far.

Changes

  • populateNullableTypes is now also applied to path items (parameters, request bodies, responses) and to components.parameters, components.requestBodies and components.responses.
  • The wrapped branch no longer keeps nullable: true. This makes the rewrite idempotent: visiting a schema twice no longer stacks another | null.
  • description and deprecated move onto the anyOf wrapper, so the generated JSDoc (including @deprecated) survives.
  • The per-media-type loop is shared via populateNullableTypesForContent.

Effect on the generated client

Regenerated locally against the committed specs (v2 and v3-next); not part of this PR, it lands with the next "update generated client" run. The diff consists only of added | null, no JSDoc is lost. All 18 inline nullable occurrences in the v2 spec are covered, except those in deprecated operations, which the generator skips anyway. Examples:

  • PATCH /v2/stacks/{stackId}: updateSchedule, x-update-schedule
  • PATCH /v2/contributors/{contributorId} and .../extensions/{extensionId}: descriptions, webhookUrls, …
  • PATCH /v2/mail-addresses/{mailAddressId}/autoresponder: autoResponder
  • PATCH /v2/{projects,servers}/{id}/storage-space-statistics: notificationThresholdInBytes
  • GET /v2/page-insights response: metrics[].score

Consumers that pass these values now have to handle null in response types (score), request types only get wider.

Testing

  • populateNullableTypes.test.ts updated for the stripped flag, new tests for the request body, response and path item helpers and for the JSDoc annotations.
  • yarn test:unit (generator), tsc --noEmit, lint: green.

🤖 Generated with Claude Code

deder-mw and others added 4 commits October 16, 2026 09:49
populateNullableTypes now drops `nullable: true` from the schema it wraps
into `anyOf: [schema, { type: "null" }]`. The tests added in #306 pinned
the old behaviour, including the documented compounding when a schema is
visited twice. With the flag gone the function is idempotent, so that
test now asserts exactly that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The request body and response helpers each carried the same loop over
`content`, and components/Response.ts inlined it a third time, including
a fallback branch the preceding `invariant` already rules out. All three
now go through populateNullableTypesForContent.

populateNullableTypesForPathItem no longer accepts a Reference Object:
Path.fromDoc only ever passes a PathItemObject, so that branch was
unreachable.

Adds tests for the request body, response and path item helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wrapping a nullable schema into `anyOf: [schema, { type: "null" }]` left
`description` and `deprecated` on the inner branch. JSDoc is generated
from the wrapper the property points to, so both were dropped. With
inline request bodies now being rewritten as well, this removed the
`@deprecated` tag and the description from `updateSchedule` and
`x-update-schedule` on PATCH /v2/stacks/{stackId}.

Both annotations now move onto the wrapper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mfal
mfal force-pushed the fix/respect-nullable-property branch from af5920a to c963065 Compare October 16, 2026 07:53
@mfal
mfal enabled auto-merge (squash) October 16, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants