(schema: JSONSchema7)
| 418 | * Returns undefined if the schema is not a nullable wrapper. |
| 419 | */ |
| 420 | export function getNullableInner(schema: JSONSchema7): JSONSchema7 | undefined { |
| 421 | if (!schema.anyOf || !Array.isArray(schema.anyOf) || schema.anyOf.length !== 2) return undefined; |
| 422 | const [a, b] = schema.anyOf; |
| 423 | if (isNullLike(a) && !isNullLike(b)) return b as JSONSchema7; |
| 424 | if (isNullLike(b) && !isNullLike(a)) return a as JSONSchema7; |
| 425 | return undefined; |
| 426 | } |
| 427 | |
| 428 | function isNullLike(s: unknown): boolean { |
| 429 | if (!s || typeof s !== "object") return false; |
no test coverage detected
searching dependent graphs…