Skip to content

Stop self-referencing nullable OpenAPI schemas from recursing when expanded - #4665

Merged
peterwhite merged 3 commits into
mainfrom
peter/rnd-13222-openapi-nullable-recursion
Oct 7, 2026
Merged

peterwhite merged 3 commits into
mainfrom
peter/rnd-13222-openapi-nullable-recursion

Conversation

@peterwhite

@peterwhite peterwhite commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes OpenAPI schemas that refer to themselves through a nullable array, like AND: anyOf [array of FilterClause, null]. When expanded, they rendered forever and the server ran out of memory.

The renderer stops at a circular schema by checking whether it has seen that exact object before. normalizeNullableUnion made a new copy every time, so the check never matched. It now returns the same object for the same schema.

This only showed up with expanded sections, which means PDF export or specs that set x-expandAllModelSections.

Before the fix, rendering the schema used up a 4 GB heap in about 33 seconds. After, it takes 16 ms. A new test fails without the fix.

Rendered HTML is identical before and after for 787 operations across 11 specs that already worked.

The PDF export that was crashing now renders on this PR's preview: https://gitbook-v2-rhy0ixflo-gitbook.vercel.app/~space/iXVX3JFbIboip1Xtg1I6/~gitbook/pdf?back=false&only=yes&page=1ZWW21YhiWZACs4HynTk

Part of RND-13222.

How to reproduce

  1. Add a spec with a self-referencing nullable schema to a space:

    FilterClause:
      type: object
      properties:
        AND:
          anyOf:
            - type: array
              items:
                $ref: '#/components/schemas/FilterClause'
            - type: 'null'
  2. Add an OpenAPI block for an operation that uses FilterClause.

  3. Export that page as PDF.

On main, the export runs out of memory and every page stays on "Loading...". On this branch, it renders.

Context

Problem: PDF exports that include these schemas run out of memory, and every page stays on "Loading...".

Outcome: The PDF export works.

Changelog

  • [Fix] PDF exports no longer crash on OpenAPI specs with self-referencing nullable schemas.

@changeset-bot

changeset-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 858f586

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@gitbook/react-openapi Patch
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linear-code

linear-code Bot commented Oct 6, 2026

Copy link
Copy Markdown

RND-13222

@peterwhite
peterwhite requested a review from nolannbiron October 6, 2026 14:57
@peterwhite
peterwhite marked this pull request as ready for review October 6, 2026 14:58
@argos-ci

argos-ci Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2-cloudflare (Inspect) 👍 Approved by Peter White 6 changed, 3 ignored Oct 6, 2026, 4:59 PM
customers-v2-vercel (Inspect) 👍 Approved by Peter White 12 changed, 2 ignored Oct 6, 2026, 4:57 PM
v2-cloudflare (Inspect) ✅ No changes detected 6 ignored Oct 6, 2026, 5:00 PM
v2-vercel (Inspect) 👍 Approved by Peter White 8 changed, 1 ignored Oct 6, 2026, 4:59 PM

@peterwhite
peterwhite merged commit 5c4a808 into main Oct 7, 2026
19 of 20 checks passed
@peterwhite
peterwhite deleted the peter/rnd-13222-openapi-nullable-recursion branch October 7, 2026 09:38

This branch was successfully deployed

2 active deployments
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