feat: P2 JSON Schema support — allOf, if/then/else, patternProperties, prefixItems (#82) #87

Merged
xingyue merged 1 commits from feat/82-schema-p2 into main 2026-06-01 02:15:35 +00:00
Owner

What

#82 Phase 2:扩展 JSON Schema 支持,新增 10 个关键字,其中 4 个需要 collectRefs() 适配。

Changes

新增关键字

分类 关键字 collectRefs
组合 allOf 遍历所有子 schema
条件 if, then, else 遍历条件子 schema
对象 patternProperties regex 匹配 key → 遍历
数组 prefixItems 元组逐项遍历
数值 multipleOf — 叶子
对象 minProperties, maxProperties — 叶子
元数据 default — 叶子

改动文件

  • schema.ts — 白名单 +10, isValidSchema() 递归验证, collectRefs() 遍历扩展
  • bootstrap.ts — meta-schema 新增对应 property 定义
  • schema.test.ts — 13 个新测试
  • schema-validation.test.ts — 更新 meta-schema 结构断言
  • cli-json-cas/src/index.ts — fix lint (unused var)

collectRefs 改动要点

  • allOf: 所有子 schema 对同一 value 提取 refs
  • if/then/else: 条件子 schema 对同一 value 提取 refs
  • patternProperties: regex 匹配 key,对命中的 value 提取 refs
  • prefixItems: 元组逐位提取 refs,items 仅作用于 prefixItems 之后的元素

Test

510 pass, 0 fail, build + lint clean

Ref

Refs #82

## What #82 Phase 2:扩展 JSON Schema 支持,新增 10 个关键字,其中 4 个需要 `collectRefs()` 适配。 ## Changes ### 新增关键字 | 分类 | 关键字 | collectRefs | |------|--------|:-----------:| | 组合 | `allOf` | ✅ 遍历所有子 schema | | 条件 | `if`, `then`, `else` | ✅ 遍历条件子 schema | | 对象 | `patternProperties` | ✅ regex 匹配 key → 遍历 | | 数组 | `prefixItems` | ✅ 元组逐项遍历 | | 数值 | `multipleOf` | — 叶子 | | 对象 | `minProperties`, `maxProperties` | — 叶子 | | 元数据 | `default` | — 叶子 | ### 改动文件 - `schema.ts` — 白名单 +10, `isValidSchema()` 递归验证, `collectRefs()` 遍历扩展 - `bootstrap.ts` — meta-schema 新增对应 property 定义 - `schema.test.ts` — 13 个新测试 - `schema-validation.test.ts` — 更新 meta-schema 结构断言 - `cli-json-cas/src/index.ts` — fix lint (unused var) ### collectRefs 改动要点 - `allOf`: 所有子 schema 对同一 value 提取 refs - `if/then/else`: 条件子 schema 对同一 value 提取 refs - `patternProperties`: regex 匹配 key,对命中的 value 提取 refs - `prefixItems`: 元组逐位提取 refs,`items` 仅作用于 prefixItems 之后的元素 ## Test 510 pass, 0 fail, build + lint clean ## Ref Refs #82
xiaoju added 1 commit 2026-06-01 02:10:56 +00:00
Add 10 new schema keywords:

Combinators/conditionals (with collectRefs support):
- allOf: array of sub-schemas, all must match
- if/then/else: conditional validation
- patternProperties: regex-keyed property schemas
- prefixItems: tuple validation (per-position schemas)

Leaf constraints:
- multipleOf, minProperties, maxProperties, default

Updated: ALLOWED_SCHEMA_KEYS, isValidSchema(), collectRefs(),
meta-schema (bootstrap.ts), and schema-validation tests.

13 new tests: schema acceptance, validation, rejection,
and collectRefs traversal for allOf/patternProperties/prefixItems.

510 tests, 0 fail.

Refs #82
xingyue merged commit 58f57b0dd8 into main 2026-06-01 02:15:35 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/json-cas#87