(node: Record<string, unknown>)
| 992 | } |
| 993 | |
| 994 | function applyNullable(node: Record<string, unknown>): Record<string, unknown> { |
| 995 | // enum widening |
| 996 | if (Array.isArray(node.enum)) { |
| 997 | return widenType({ |
| 998 | ...node, |
| 999 | enum: node.enum.includes(null) ? node.enum : [...node.enum, null] |
| 1000 | }) |
| 1001 | } |
| 1002 | |
| 1003 | // type widening |
| 1004 | if (node.type !== undefined) return widenType(node) |
| 1005 | |
| 1006 | // const === null |
| 1007 | if (node.const === null) return node |
| 1008 | |
| 1009 | // fallback |
| 1010 | return { anyOf: [node, { type: "null" }] } |
| 1011 | } |
| 1012 | |
| 1013 | function widenType(node: Record<string, unknown>): Record<string, unknown> { |
| 1014 | const t = node.type |
no test coverage detected