diff --git a/clients/web/src/test/core/nullableUnion.test.ts b/clients/web/src/test/core/nullableUnion.test.ts index c1054c83..24592e24 100644 --- a/clients/web/src/test/core/nullableUnion.test.ts +++ b/clients/web/src/test/core/nullableUnion.test.ts @@ -768,6 +768,12 @@ describe("admitsNull", () => { ); }); + it("reads the boolean schema form", () => { + // `true` is the unconstrained schema; `false` admits nothing at all. + expect(admitsNull({ const: null, anyOf: [true] })).toBe(true); + expect(admitsNull({ const: null, anyOf: [false] })).toBe(false); + }); + it("does not override a sibling that rejects null", () => { // `const` is conjunctive with its siblings, not an override: both of // these reject every value, so claiming nullability would let the diff --git a/core/json/nullableUnion.ts b/core/json/nullableUnion.ts index 3217b0f1..fd6761dc 100644 --- a/core/json/nullableUnion.ts +++ b/core/json/nullableUnion.ts @@ -454,6 +454,9 @@ function anyOfAdmitsNull(schema: NullableUnionSchema): boolean { const branches = schema.anyOf; if (!Array.isArray(branches)) return false; return branches.some((entry) => { + // JSON Schema's boolean form: `true` is the unconstrained schema and admits + // every value, `null` among them, while `false` admits none. + if (typeof entry === "boolean") return entry; const branch = toBranch(entry); if (branch === null) return false; const branchSchema = branch as NullableUnionSchema;