Skip to content

fix(theme): prevent infinite recursion from self-referential discriminators - #1584

Merged
sserrata merged 1 commit into
mainfrom
fix/discriminator-recursion-crash
Jul 30, 2026
Merged

sserrata merged 1 commit into
mainfrom
fix/discriminator-recursion-crash

Conversation

@sserrata

Copy link
Copy Markdown
Member

Problem

OpenAPI operation pages froze and crashed the browser tab when a schema contained a oneOf whose branches each declare their own discriminator on the same property, with no explicit mapping. This surfaced on Palo Alto Networks' DLP Data Profiles API docs (pan.dev/dlp/api/), where every Data Profiles operation renders a schema shaped like:

ExpressionTreeNode:
  properties:
    rule_item:
      oneOf:
        - $ref: '#/components/schemas/DataPatternRuleItem'   # each variant declares
        - $ref: '#/components/schemas/DictionaryRuleItem'    # discriminator: detection_technique
        - ...

Root cause

getDiscriminator returns a nested branch's discriminator by reference. DiscriminatorNode then mutates that object's .mapping while inferring variants from the parent oneOf. Because a branch (e.g. DataPatternRuleItem) owns that same discriminator object, its inferred mapping ends up containing itself — so rendering the branch re-enters DiscriminatorNode with a self-referential mapping and recurses until the stack overflows:

SchemaNode(DataPatternRuleItem) → DiscriminatorNode(DataPatternRuleItem) → SchemaNode(DataPatternRuleItem) → …

Fix

Clone the borrowed discriminator before attaching it in SchemaNode, so the inferred .mapping stays local to the current node instead of poisoning the shared branch schema:

workingSchema.discriminator = { ...resolvedDiscriminator };

Testing

  • Added demo/examples/tests/recursiveDiscriminator.yaml reproducing the pattern, plus a create-rule entry in the schema-snapshot suite.
  • Verified against the real DLP DataProfiles spec: the traversal that previously overflowed the stack now completes in a bounded number of node visits.
  • demo production build succeeds and the previously-crashing pages render the full schema tree (request body, response schema, discriminator tabs) in the browser.
  • Existing normalize unit tests pass (30/30).

🤖 Generated with Claude Code

…nators

A schema whose `oneOf` branches each declare their own `discriminator` on
the same property (with no explicit mapping) crashed the browser tab.
`getDiscriminator` returns the discriminator of a nested branch by
reference, and `DiscriminatorNode` mutates its `.mapping` while inferring
variants from the parent `oneOf`. Because the branch owns that same
discriminator object, its mapping ends up containing itself, so rendering
the branch re-enters `DiscriminatorNode` with a self-referential mapping
and recurses until the stack overflows.

Clone the borrowed discriminator before attaching it so the inferred
mapping stays local to the node. Adds a `recursiveDiscriminator` example
spec that reproduces the pattern and a schema-snapshot entry.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Size Change: +7.23 kB (+0.31%)

Total Size: 2.35 MB

📦 View Changed
Filename Size Change
demo/.docusaurus/globalData.json 83 kB +990 B (+1.21%)
demo/.docusaurus/registry.js 120 kB +1.44 kB (+1.21%)
demo/.docusaurus/routes.js 114 kB +1.39 kB (+1.23%)
demo/.docusaurus/routesChunkNames.json 47.2 kB +576 B (+1.23%)
demo/build/assets/js/main.********.js 700 kB +2.55 kB (+0.37%)
demo/build/assets/js/runtime~main.********.js 27.1 kB +293 B (+1.09%)
ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 16.4 kB
demo/.docusaurus/i18n.json 372 B
demo/.docusaurus/site-metadata.json 1.58 kB
demo/build/assets/css/styles.********.css 173 kB
demo/build/index.html 99.4 kB
demo/build/petstore/add-pet/index.html 29.5 kB
demo/build/petstore/create-user/index.html 24.2 kB
demo/build/petstore/create-users-with-array-input/index.html 24.3 kB
demo/build/petstore/create-users-with-list-input/index.html 24.3 kB
demo/build/petstore/delete-order/index.html 24.1 kB
demo/build/petstore/delete-pet/index.html 24.3 kB
demo/build/petstore/delete-user/index.html 24.5 kB
demo/build/petstore/find-pets-by-status/index.html 25 kB
demo/build/petstore/find-pets-by-tags/index.html 25.7 kB
demo/build/petstore/get-inventory/index.html 23.4 kB
demo/build/petstore/get-order-by-id/index.html 24.4 kB
demo/build/petstore/get-pet-by-id/index.html 25.1 kB
demo/build/petstore/get-user-by-name/index.html 24.6 kB
demo/build/petstore/login-user/index.html 25.1 kB
demo/build/petstore/logout-user/index.html 23.9 kB
demo/build/petstore/new-pet/index.html 24.5 kB
demo/build/petstore/pet/index.html 22.8 kB
demo/build/petstore/place-order/index.html 23.6 kB
demo/build/petstore/schemas/apiresponse/index.html 24.9 kB
demo/build/petstore/schemas/cat/index.html 38.9 kB
demo/build/petstore/schemas/category/index.html 26 kB
demo/build/petstore/schemas/dog/index.html 39.2 kB
demo/build/petstore/schemas/honeybee/index.html 39.3 kB
demo/build/petstore/schemas/id/index.html 23.1 kB
demo/build/petstore/schemas/order/index.html 27.1 kB
demo/build/petstore/schemas/pet/index.html 38.9 kB
demo/build/petstore/schemas/tag/index.html 24.4 kB
demo/build/petstore/schemas/user/index.html 40.8 kB
demo/build/petstore/store/index.html 21.8 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 30.5 kB
demo/build/petstore/swagger-petstore-yaml/index.html 30.7 kB
demo/build/petstore/update-pet-with-form/index.html 24.5 kB
demo/build/petstore/update-pet/index.html 24.9 kB
demo/build/petstore/update-user/index.html 24.5 kB
demo/build/petstore/upload-file/index.html 24.4 kB
demo/build/petstore/user/index.html 22.4 kB

compressed-size-action

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 2771b82):

https://docusaurus-openapi-36b86--pr1584-x6bj4p6z.web.app

(expires Thu, 06 Aug 2026 20:00:02 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@github-actions

Copy link
Copy Markdown

📸 Visual Diff Report

Snapshot comparison against https://docusaurus-openapi.tryingpan.dev/

Total ✅ Match ❌ Diff ⏭ Skip
222 215 7 0
❌ 7 page(s) with visual regressions

/tests/const

Prod Preview Diff
prod screenshot for /tests/const preview screenshot for /tests/const pixel diff for /tests/const

/tests/deprecated-description

Prod Preview Diff
prod screenshot for /tests/deprecated-description preview screenshot for /tests/deprecated-description pixel diff for /tests/deprecated-description

/tests/license-identifier-demo-api

Prod Preview Diff
prod screenshot for /tests/license-identifier-demo-api preview screenshot for /tests/license-identifier-demo-api pixel diff for /tests/license-identifier-demo-api

/tests/license-rendered-via-spdx-identifier

Prod Preview Diff
prod screenshot for /tests/license-rendered-via-spdx-identifier preview screenshot for /tests/license-rendered-via-spdx-identifier pixel diff for /tests/license-rendered-via-spdx-identifier

/tests/license-rendered-via-url

Prod Preview Diff
prod screenshot for /tests/license-rendered-via-url preview screenshot for /tests/license-rendered-via-url pixel diff for /tests/license-rendered-via-url

/tests/license-url-demo-api

Prod Preview Diff
prod screenshot for /tests/license-url-demo-api preview screenshot for /tests/license-url-demo-api pixel diff for /tests/license-url-demo-api

/tests/recursive-filter-api

Prod Preview Diff
prod screenshot for /tests/recursive-filter-api preview screenshot for /tests/recursive-filter-api pixel diff for /tests/recursive-filter-api

Updated at 2026-07-30T20:07:06.736Z · run 30576977084

@sserrata
sserrata merged commit 9c31060 into main Jul 30, 2026
12 checks passed
@sserrata
sserrata deleted the fix/discriminator-recursion-crash branch July 30, 2026 20:08

This branch was previously deployed

1 inactive deployment
preview — 2771b823 Deployed Jul 30, 2026 by sserrata via Visual Diff #2303
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.

1 participant