Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
533 changes: 518 additions & 15 deletions canonical_test.go

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions docs/mfjs-walle-vs-draft-2020-12.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This document summarizes how the **walle** validator handles each keyword in **J
| --- | --- |
| `$id` | ✅ **Root only**; value must be a string. |
| `$schema` | ❌ |
| `$ref` | ✅ **In-document references only**; remote / URL / cross-file references are disallowed; infinite recursion must be avoided. |
| `$ref` | ✅ **In-document references only**; remote / URL / cross-file references are disallowed; infinite recursion must be avoided (the test is whether a finite instance exists); siblings of `$ref` apply as a logical AND, per 2020-12. |
| `$comment` | ❌ |
| `$defs` | ✅ **Root only**; **definition names must not contain `/`**. |
| `$anchor` | ❌ |
Expand All @@ -36,13 +36,13 @@ This document summarizes how the **walle** validator handles each keyword in **J
| Keyword | walle |
| --- | --- |
| `allOf` | ❌ |
| `anyOf` | ✅ Branch count **may be capped**; `type` must **not** appear beside `anyOf` / `$ref` at the same level—declare `type` **inside** each branch. |
| `anyOf` | ✅ Branch count **may be capped**; constraints such as `type` may sit beside it—they apply as a logical AND, and `Canonical` distributes them into every branch. |
| `oneOf` | ❌ |
| `if` | ❌ |
| `then` | ❌ |
| `else` | ❌ |
| `not` | ❌ |
| `properties` | ✅ When `type` is `object`: **keys must not** be `$defs`, `$ref`, `anyOf`, `required`, or `additionalProperties`; **no duplicate keys**; every name in `required` must appear in `properties`. |
| `properties` | ✅ When `type` is `object`: **keys must not** be `$defs`, `$ref`, `anyOf`, `required`, or `additionalProperties`; **no duplicate keys**. A name in `required` that `properties` does not declare is accepted by lite and pruned by `Canonical`. |
| `additionalProperties` | ✅ Value must be a **boolean** or an **object**; if omitted, **defaults to true**. |
| `patternProperties` | ❌ |
| `dependentSchemas` | ❌ |
Expand Down Expand Up @@ -134,9 +134,11 @@ This document summarizes how the **walle** validator handles each keyword in **J
| Topic | walle |
| --- | --- |
| Empty object subschema `{}` | **ANY** is expressed only when the **entire root** is `{}` or when **`additionalProperties`** is `{}`. A `{}` **inside** `properties` is **not** treated as ANY. |
| `type` alongside `anyOf` / `$ref` | **Disallowed**; put `type` **inside** the `anyOf` branch or the `$ref` target. |
| `type` alongside `anyOf` | **Allowed**—2020-12 applies it as a logical AND. lite accepts it and `Canonical` pushes it into every branch, dropping the branches it contradicts; if that leaves no branch, the subschema degrades to `{}`. |
| `type` alongside `$ref` | **Allowed**—2020-12 applies it as a logical AND. lite accepts it and ultra folds it into the target. An empty intersection with the target's `type` admits no instance: lite still accepts it but `Canonical` degrades that subschema to `{}`, and strict and above reject it. |
| Keywords allowed on `object` | **`type`**, **`properties`**, **`required`**, **`additionalProperties`**, **`anyOf`**, **`$ref`**, plus annotations such as **`description`** / **`title`** where rules allow. |
| Siblings of `anyOf` / `$ref` | Besides **`description`** / **`title`**, the **root** may also include **`$defs`** / **`$id`**. |
| Siblings of `anyOf` | Constraint keywords are allowed, and the **root** may also include **`$defs`** / **`$id`**. `Canonical` distributes the constraints into every branch and leaves **`description`** / **`title`** where they are. |
| Siblings of `$ref` | Constraint keywords are **allowed**. lite accepts them; ultra inlines the definition and keeps the stricter value for each shared keyword—see [validation-principles.md](./validation-principles.md). |
| Nesting and size | For example, **total `properties` keys across objects** and **nesting depth** **may be limited**—see **[walle.md](./walle.md)**. |
| Numeric and enum literals | Integers **decimal only**; floating-point **no scientific notation**; further bounds as in **walle.md**. |

Expand Down
10 changes: 6 additions & 4 deletions docs/mfjs-walle-vs-draft-2020-12.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
| Keyword | walle |
| --- | --- |
| `allOf` | ❌ |
| `anyOf` | ✅ 分支数量可能有限制;与 `type` / `$ref` **不得同级**(`type` 须在分支内) |
| `anyOf` | ✅ 分支数量可能有限制;同级可带 `type` 等约束(按 AND 生效),`Canonical` 会把它们分发进每个分支 |
| `oneOf` | ❌ |
| `if` | ❌ |
| `then` | ❌ |
| `else` | ❌ |
| `not` | ❌ |
| `properties` | ✅ `type: object` 时;**key 不可** 为 `$defs`、`$ref`、`anyOf`、`required`、`additionalProperties`;**不可重复**;`required` 中每项须在 `properties` 中声明 |
| `properties` | ✅ `type: object` 时;**key 不可** 为 `$defs`、`$ref`、`anyOf`、`required`、`additionalProperties`;**不可重复**;`required` 中未在 `properties` 声明的项 lite 放行,`Canonical` 会把它剔除 |
| `additionalProperties` | ✅ 值为 **boolean 或 object**;未指定时 **默认 true** |
| `patternProperties` | ❌ |
| `dependentSchemas` | ❌ |
Expand Down Expand Up @@ -134,9 +134,11 @@
| 主题 | walle |
| --- | --- |
| 空 object subschema `{}` | 仅 **整份 root 为 `{}`** 或 **`additionalProperties` 值为 `{}`** 表示 **ANY**;**`properties` 内 `{}` 不自动视为 ANY** |
| `type` 与 `anyOf` / `$ref` 同级 | **禁止**;`type` 须在 `anyOf` / `$ref` 目标内部 |
| `type` 与 `anyOf` 同级 | **允许**(2020-12 按 AND 生效);lite 放行,`Canonical` 把 `type` 分发进每个分支,与父层矛盾的分支丢弃、全部丢弃则该子 schema 退化为 `{}` |
| `type` 与 `$ref` 同级 | **允许**(2020-12 按 AND 生效);lite 放行,ultra 折叠进引用目标;与目标 `type` 交集为空时属恒假,lite 仍放行但 Canonical 把该子 schema 退化为 `{}`,strict 及以上拒绝 |
| `object` 上允许的 keyword | **仅** `type`、`properties`、`required`、`additionalProperties`、`anyOf`、`$ref`(及注解规则中的 `description` / `title` 等) |
| `anyOf` / `$ref` 同级其它 keyword | 除 `description` / `title` 外,**root** 可额外有 `$defs` / `$id` |
| `anyOf` 同级其它 keyword | 允许约束关键字,**root** 可额外有 `$defs` / `$id`;`Canonical` 把约束分发进各分支,`description` / `title` 留在原处 |
| `$ref` 同级其它 keyword | **允许**约束关键字;lite 放行,ultra 内联展开并对同名关键字取更严的一侧,详见 [validation-principles.zh.md](./validation-principles.zh.md) |
| 嵌套与规模 | 如 **全 schema 中 object properties 数量可能有限制(累计)**、**嵌套层数可能有限制**(以 [walle.zh.md](./walle.zh.md) 为准) |
| 数值与枚举字面量 | 整数 **十进制**;浮点 **无科学计数法**;等 |

Expand Down
Loading
Loading