(js: JsonSchema.JsonSchema)
| 465 | } |
| 466 | |
| 467 | const compose = (js: JsonSchema.JsonSchema): JsonSchema.JsonSchema => { |
| 468 | // Sibling choices must both hold. |
| 469 | const members = [ |
| 470 | ...(Array.isArray(js.allOf) ? js.allOf : []), |
| 471 | ...(Array.isArray(js.anyOf) ? [{ anyOf: js.anyOf }] : []), |
| 472 | ...(Array.isArray(js.oneOf) ? [{ oneOf: js.oneOf }] : []) |
| 473 | ] |
| 474 | const hasOwn = js.properties !== undefined || js.required !== undefined |
| 475 | const constraints = members.filter((member) => |
| 476 | !Predicate.isObject(member) || !Object.keys(member).every(isAnnotation) |
| 477 | ) |
| 478 | // Annotation-only members do not require expanding references; the importer attaches their metadata. |
| 479 | if ((hasOwn ? 1 : 0) + constraints.length < 2) return js |
| 480 | const { allOf: _allOf, anyOf: _anyOf, oneOf: _oneOf, ...rest } = js |
| 481 | if (!isPlainObject(rest)) return js |
| 482 | const own = pick(rest, (key) => objectKeys.has(key)) |
| 483 | let part: Part = { _tag: "Object", schema: own } |
| 484 | for (const member of members) { |
| 485 | const next = toPart(member) |
| 486 | const merged: Part | undefined = next === undefined ? undefined : mergeParts(part, next) |
| 487 | if (merged === undefined) return js |
| 488 | part = merged |
| 489 | } |
| 490 | const annotations = pick(rest, isAnnotation) |
| 491 | return part._tag === "Object" |
| 492 | ? { ...annotations, ...part.schema } |
| 493 | : { ...annotations, [part.mode]: part.branches } |
| 494 | } |
| 495 | |
| 496 | const dropRedundantObjectType = (js: JsonSchema.JsonSchema): JsonSchema.JsonSchema => { |
| 497 | if (js.type !== "object") return js |
no test coverage detected