toStrictJsonSchema: RangeError: Maximum call stack size exceeded on cyclic $ref inside anyOf/allOf/oneOf

オープン 初心者向け
#3,232 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
nodejs, typescript

調査の方向性

src/lib/transform.ts の isNullable から始め、$ref をたどるときや allOf、anyOf、oneOf を再帰的に処理するときに、seenRefs がどのように扱われるかを追ってください。toStrictJsonSchema の既存のテストを確認し、各ブランチ型の内部にある循環参照を網羅するテストを追加してください。これらのケースがスタックオーバーフローを起こさずに boolean を返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

Confirm this is a Node library issue and not an underlying OpenAI API issue
  • This is an issue with the Node library
Describe the bug

When toStrictJsonSchema() checks whether an optional object property is nullable via isNullable(), a cyclic $ref nested inside anyOf, allOf, or oneOf causes RangeError: Maximum call stack size exceeded instead of returning true or false.

Root cause:
In src/lib/transform.ts (isNullable), seenRefs is tracked when following $ref, but seenRefs is omitted when recursing into allOf, anyOf, and oneOf branches (isNullable(variant, root)). Passing seenRefs to those recursive calls (isNullable(variant, root, seenRefs)) lets cyclic branches terminate conservatively (false) without overflowing the call stack.

To Reproduce
  1. Call toStrictJsonSchema() (or zodResponseFormat() / standardSchemaResponseFormat()) with an optional property whose schema references a cyclic $ref inside anyOf, allOf, or oneOf.
  2. Observe RangeError: Maximum call stack size exceeded at isNullable in src/lib/transform.ts.
Code snippets
import { toStrictJsonSchema } from "openai/lib/transform";

toStrictJsonSchema({
  type: "object",
  $defs: {
    Node: {
      anyOf: [{ $ref: "#/$defs/Node" }, { type: "null" }],
    },
  },
  properties: {
    next: { $ref: "#/$defs/Node" },
  },
});
OS

macOS

Node version

v22.23.3

Library version

openai v7.69.0

主要言語
TypeScript
スター
11.3k
フォーク
1.6k
平均マージ
19時間 41分
マージ済み PR(30日)
110

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-node のほかの issue

openai/openai-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。