Skip to content

build-schemas.ts 用 replace('Schema','') 剥后缀,前缀含 Schema 的 4 个 schema 名被截断($id / 文档页名 / import 全错) #4592

Closed

Description

@os-zhuang

现象

packages/spec/scripts/build-schemas.ts:200 把导出常量名转成 JSON Schema 名时用的是字符串 replace,不是后缀正则:

const schemaName = key.endsWith('Schema') ? key.replace('Schema', '') : key;

String.prototype.replace(string, …) 只替换第一处出现。常量名里 Schema 出现在前缀或中间时,被剥掉的就不是后缀,而是名字里面的那一段。目前受影响的 4 个:

导出常量 实际生成的 schema 名 正确的名字
SchemaModeSchema (src/data/datasource.zod.ts:440) data/ModeSchema data/SchemaMode
SchemaChangeSchema (src/system/deploy-bundle.zod.ts:46) system/ChangeSchema system/SchemaChange
SchemaLevelIsolationStrategySchema (src/system/tenant.zod.ts:376) system/LevelIsolationStrategySchema system/SchemaLevelIsolationStrategy
DocumentSchemaValidationSchema (src/data/driver-nosql.zod.ts:119) data/DocumentValidationSchema data/DocumentSchemaValidation

影响面

这个名字不是内部细节,它同时是三处对外表面:

  1. $id:https://schema.objectstack.io/v17/data/ModeSchema.json —— 一个并不存在的类型名,IDE 自动补全和外部引用都会拿到它;
  2. json-schema.manifest.json 的棘轮条目(已记录了这 4 个错名);
  3. content/docs/references/ 的页面小节标题与 import 示例 —— 在 build-docs.ts 用「剥掉 Schema 后缀」推导 import type 示例,类型别名不存在时生成的文档引用无法编译 #4570 的修复之后,这 4 个名字在真实导出面里查无此名,于是被从 import 行里剔除,并作为 4 条 no schema const export 记进 packages/spec/docs-import-surface.baseline.json。也就是说这 4 个 schema 现在有文档页、但页面给不出任何 import 示例。

建议

改成 key.replace(/Schema$/, ''),然后 gen:schema + gen:docs + gen:api-surface 重跑,并把 json-schema.manifest.json 里 4 条旧键换成新键(属于 #2978 说的「有意退役」范畴,要在 PR 里说明),同时把 docs-import-surface.baseline.json 里对应的 4 条 no schema const export 删掉(该 baseline 是只减不增的棘轮,修好后必须删行,否则 check:docs 会因为陈旧条目变红)。

发现于 #4570。

Activity

  1. added
    pm:queueReady for the PM dispatch loop
    pm:dispatchedDispatched to a dev agent by /pm-dispatch
    and removed
    pm:queueReady for the PM dispatch loop
    on Aug 2, 2026
  2. self-assigned this
    on Aug 2, 2026
  3. os-zhuang commented on Aug 2, 2026

    @os-zhuang
    ContributorAuthor

    🔒 CLAIM — pm-dispatch round 6
    branch: claude/issue-4592-schema-suffix-regex
    worktree: objectstack-issue-4592
    本轮由 PM 会话派发给 os-dev agent。若另有会话已在做此题,以本 issue 更早的 CLAIM 评论为准,后到者退出。


    Generated by Claude Code

  4. os-zhuang commented on Aug 2, 2026

    @os-zhuang
    ContributorAuthor

    PM 复核:ACCEPT ✅(PR #4625,已转正并挂自动合并,CI 绿后进队列)

    • 比 issue 范围多抓到一处:build-docs.ts:133 有同一 bug 的第二份拷贝;两处收敛为共享的 schemaNameFromExportKey(锚定 /Schema$/),生成器不可能再各自漂移,附 4 例前缀 Schema 的 pin 测试(回退成字符串 replace 即红);
    • manifest 4 条旧键按 gen:schema silently drops PageTabsProps since #2967 — references regen would delete real docs #2978 有意退役并在 PR 说明;authorable-surface 14 条为改名非退役(每个 key 在新名下存活),不涉及 tombstone/D2——判断正确;
    • docs-import-surface 棘轮 152 → 144(4 对缺口消失),走生成器自己的 --update-import-baseline;4 个参考页恢复真实 import 示例;
    • api-surface.json 零 diff(TS 导出面未变),无多余搅动;
    • spec 291 文件 7285 用例全绿,8 个生成物门禁全绿,typecheck 干净;changeset 携带 FROM→TO 映射方便外部引用方 grep。

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pm:dispatchedDispatched to a dev agent by /pm-dispatch

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions