Skip to content

Commit 6ac45d9

Browse files
committed
fix: address Copilot review round 28 — the boolean schema form in a null-admitting union
`anyOfAdmitsNull` sent every non-object member to `toBranch` and refused it, so `{ const: null, anyOf: [true] }` read as non-nullable — a required field seeded and rendered read-only as `null` and reported missing forever. `true` is the unconstrained schema and admits every value, `null` among them; `false` admits none and still does not. Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent c8c5442 commit 6ac45d9

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎clients/web/src/test/core/nullableUnion.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,12 @@ describe("admitsNull", () => {
768768
);
769769
});
770770

771+
it("reads the boolean schema form", () => {
772+
// `true` is the unconstrained schema; `false` admits nothing at all.
773+
expect(admitsNull({ const: null, anyOf: [true] })).toBe(true);
774+
expect(admitsNull({ const: null, anyOf: [false] })).toBe(false);
775+
});
776+
771777
it("does not override a sibling that rejects null", () => {
772778
// `const` is conjunctive with its siblings, not an override: both of
773779
// these reject every value, so claiming nullability would let the

‎core/json/nullableUnion.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ function anyOfAdmitsNull(schema: NullableUnionSchema): boolean {
454454
const branches = schema.anyOf;
455455
if (!Array.isArray(branches)) return false;
456456
return branches.some((entry) => {
457+
// JSON Schema's boolean form: `true` is the unconstrained schema and admits
458+
// every value, `null` among them, while `false` admits none.
459+
if (typeof entry === "boolean") return entry;
457460
const branch = toBranch(entry);
458461
if (branch === null) return false;
459462
const branchSchema = branch as NullableUnionSchema;

0 commit comments

Comments
 (0)