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>
This commit is contained in:
parent
c8c5442dcf
commit
6ac45d9b26
2 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue