Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`Bundle` names a path item component after the escaped JSON Pointer token (`~1users`), so its `$ref` doesn't resolve

已关闭
#289 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #290 来自 @TristanSpeakEasy —— 已合并

评估

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

调研方向

Start in openapi/bundle.go at extractSimpleNameFromReference, which the issue identifies as returning the escaped final JSON Pointer token unchanged; trace how that name is used to create the path item component and its $ref. Reproduce with the supplied /paths/~1users example, then check that the resulting component name is valid and the reference resolves. Confirm the bundled document passes openapi spec validate and openapi spec inline.

由索引模型根据 Issue 内容生成。

描述

Summary

When a path item is referenced by JSON Pointer into another OpenAPI document (./paths/users.yaml#/paths/~1users), openapi.Bundle (and openapi spec bundle) uses the last pointer token as written, ~1users, as the component name. The bundled document gets components.pathItems.~1users and $ref: '#/components/pathItems/~1users'. Per RFC 6901 that ref names the key /users, which doesn't exist, and ~1users isn't a valid component name either (OAS 3.1 Components keys must match ^[a-zA-Z0-9\.\-_]+$). The bundle fails openapi spec validate, though the input passes.

Reproduction

openapi.yaml:

openapi: 3.1.0
info: {title: t, version: "1"}
paths:
  /users:
    $ref: ./paths/users.yaml#/paths/~1users

paths/users.yaml:

openapi: 3.1.0
info: {title: users, version: "1"}
paths:
  /users:
    get:
      responses:
        "200":
          description: ok
$ openapi spec bundle openapi.yaml bundled.yaml
Processing OpenAPI document: openapi.yaml
✅ Successfully bundled all external references into components section
📄 Document written to: bundled.yaml
$ cat bundled.yaml
openapi: 3.1.0
info: {title: t, version: "1"}
paths:
  /users:
    $ref: '#/components/pathItems/~1users'
components:
  pathItems:
    ~1users:
      get:
        responses:
          "200":
            description: ok
$ openapi spec validate bundled.yaml
Validating OpenAPI document: bundled.yaml
❌ OpenAPI document is invalid - 1 errors:

1. [5:11] error validation-invalid-syntax reference.$ref is invalid: invalid reference: component name "/users" must match pattern ^[a-zA-Z0-9.\-_]+$
Validation completed in 1ms
Error: openAPI document validation failed

openapi spec inline bundled.yaml fails the same way: failed to resolve reference #/components/pathItems/~1users: not found -- key /users not found in sequencedmap.Map. A path with a parameter gives ~1users~1{id}. --naming counter gives the same name.

Expected result

A valid component name and a $ref that resolves to it, as for a whole-file ref: $ref: ./paths/users.yaml (a file holding only the path item) bundles to components.pathItems.users, and the bundle validates.

Actual result

components.pathItems.~1users and a $ref that points at /users. The command reports success.

Version

v1.26.1 (main, 9f2ba11) and v1.26.0. CLI from go install github.com/speakeasy-api/openapi/cmd/openapi@latest (v0.0.0-20261029045548-9f2ba118224c); openapi.Bundle called directly gives the same output.

Cause

extractSimpleNameFromReference (openapi/bundle.go:1288) replaces characters outside [a-zA-Z0-9_] in file names, but for a fragment returns the last pointer token unchanged: not unescaped (~1, ~0) and not sanitized.

主要语言
Go
星标
276
派生
21
平均合并
1 天 6 小时
30 天内合并 PR
23

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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