这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

The @hey-api/transformers plugin crashes with "Maximum call stack size exceeded" when processing schemas with self-referential $refs (e.g., tree structures where nodes contain arrays of themselves).

Root Cause

In processSchemaType(), symbol registration happened after recursive schema processing:

if (!plugin.getSymbol(selector)) {
  const refSchema = plugin.context.resolveIrRef(schema.$ref);
  const nodes = schemaResponseTransformerNodes({ plugin, schema: refSchema }); // Recurses before symbol exists
  const symbol = plugin.registerSymbol({ name, selector }); // Too late - already infinite loop
  // ...
}

For self-referential schemas, subsequent encounters of the same $ref during recursion couldn't find the symbol, causing re-entry.

Fix

Register symbol before processing schema:

if (!plugin.getSymbol(selector)) {
  const symbol = plugin.registerSymbol({ name, selector }); // Register first
  const refSchema = plugin.context.resolveIrRef(schema.$ref);
  const nodes = schemaResponseTransformerNodes({ plugin, schema: refSchema }); // Safe - symbol exists
  // ...
}

Changes

  • Core fix: packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts - Move symbol registration before recursive call
  • Test coverage: Add recursive schema test cases for OpenAPI 3.0.x and 3.1.x
  • Snapshot updates: Function declarations now appear in top-down dependency order (parent → child) instead of bottom-up

Fixes #2848

Original prompt

This section details on the original issue you should resolve

<issue_title>Crash Report</issue_title>
<issue_description>Hey ;)

Since: 0.86.3 (0.86.2 ok)
Shema: swagger.json
Config: https://github.com/crpg2/crpg/blob/master/src/WebUI/openapi-ts.config.ts
Plugin: @hey-api/transformers
Event: operation
Arguments:

[
  {
    "_path": [
      "paths",
      "/Battles",
      "get"
    ],
    "pointer": "#/paths/~1Battles/get",
    "tags": {},
    "method": "get",
    "operation": {
      "id": "getBattles",
      "method": "get",
      "path": "/Battles",
      "summary": "Get strategus battles.",
      "tags": [
        "Battles"
      ],
      "parameters": {
        "query": {
          "region": {
            "allowReserved": false,
            "explode": true,
            "location": "query",
            "name": "region",
            "schema": {
              "$ref": "#/components/schemas/Region"
            },
            "style": "form",
            "required": true
          },
          "phase[]": {
            "allowReserved": false,
            "explode": true,
            "location": "query",
            "name": "phase[]",
            "schema": {
              "type": "array",
              "items": [
                {
                  "$ref": "#/components/schemas/BattlePhase"
                }
              ]
            },
            "style": "form"
          }
        }
      },
      "responses": {
        "200": {
          "mediaType": "application/json",
          "schema": {
            "description": "OK",
            "$ref": "#/components/schemas/BattleDetailedViewModelIListResult"
          }
        }
      },
      "security": [
        {
          "type": "http",
          "scheme": "bearer",
          "bearerFormat": "JWT"
        }
      ]
    },
    "path": "/Battles",
    "type": "operation"
  }
]

Error: Maximum call stack size exceeded

Stack Trace:

RangeError: Maximum call stack size exceeded
    at A (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:1:19224)
    at Object.Nt [as propertyAccessExpression] (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:2:1596)
    at Tu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:10230)
    at wu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:8715)
    at Tu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:8970)
    at Tu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:10284)
    at wu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:8715)
    at Tu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:8970)
    at Tu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:10284)
    at wu (file:///workspaces/crpg/src/WebUI/node_modules/@hey-api/openapi-ts/dist/getSpec-CdBgV-sm.js:23:8715)

link: #2848</issue_description>

Comments on the Issue (you are @copilot in this section)

@mrlubos Thanks! Should be the same issue as https://github.com//issues/2848

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Oct 26, 2025
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Oct 26, 2025

🦋 Changeset detected

Latest commit: 81f91a9

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

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts 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

@vercel
Copy link

vercel bot commented Oct 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Oct 26, 2025 11:59pm

…hemas

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash issue when retrieving battles from API Fix infinite recursion in @hey-api/transformers for self-referential schemas Oct 26, 2025
Copilot finished work on behalf of mrlubos October 26, 2025 23:18
Copilot AI requested a review from mrlubos October 26, 2025 23:18
@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.59%. Comparing base (76dfd46) to head (81f91a9).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...api-ts/src/plugins/@hey-api/transformers/plugin.ts 0.00% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2855   +/-   ##
=======================================
  Coverage   30.59%   30.59%           
=======================================
  Files         488      488           
  Lines       39938    39938           
  Branches     2442     2442           
=======================================
  Hits        12219    12219           
  Misses      27685    27685           
  Partials       34       34           
Flag Coverage Δ
unittests 30.59% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 26, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2855
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2855
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2855
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2855

commit: 81f91a9

@mrlubos mrlubos marked this pull request as ready for review October 26, 2025 23:59
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Oct 26, 2025
@mrlubos mrlubos merged commit f2eff9c into main Oct 27, 2025
16 of 17 checks passed
@mrlubos mrlubos deleted the copilot/fix-crash-report-battles branch October 27, 2025 00:16
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash Report Crash Report

2 participants