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

未关闭 适合新手
#3,232 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
nodejs, typescript

调研方向

从 src/lib/transform.ts 中的 isNullable 开始,追踪跟随 $ref 以及递归处理 allOf、anyOf 和 oneOf 时 seenRefs 的处理方式。检查 toStrictJsonSchema 的现有测试,并为每种分支类型中的循环引用添加测试覆盖。完成标准是这些情况都能返回布尔值,且不会导致栈溢出。

由索引模型根据 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 分钟
30 天内合并 PR
110

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-node 的其他 Issue

查看 openai/openai-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。