(
schema: JSONSchema7 | null | undefined,
definitions: DefinitionCollections | undefined
)
| 1104 | } |
| 1105 | |
| 1106 | export function resolveObjectSchema( |
| 1107 | schema: JSONSchema7 | null | undefined, |
| 1108 | definitions: DefinitionCollections | undefined |
| 1109 | ): JSONSchema7 | undefined { |
| 1110 | const resolved = resolveSchema(schema, definitions) ?? schema ?? undefined; |
| 1111 | if (!resolved) return undefined; |
| 1112 | const resolvedHasObjectShape = hasObjectShape(resolved); |
| 1113 | |
| 1114 | if (resolved.allOf) { |
| 1115 | const objectSchemas: JSONSchema7[] = []; |
| 1116 | if (resolvedHasObjectShape) { |
| 1117 | objectSchemas.push(resolved); |
| 1118 | } |
| 1119 | |
| 1120 | for (const item of resolved.allOf) { |
| 1121 | if (typeof item !== "object") continue; |
| 1122 | const objectSchema = resolveObjectSchema(item as JSONSchema7, definitions); |
| 1123 | if (!objectSchema) continue; |
| 1124 | objectSchemas.push(objectSchema); |
| 1125 | } |
| 1126 | |
| 1127 | return mergeObjectSchemas(objectSchemas) ?? resolved; |
| 1128 | } |
| 1129 | |
| 1130 | const singleBranch = (resolved.anyOf ?? resolved.oneOf) |
| 1131 | ?.filter((item): item is JSONSchema7 => { |
| 1132 | if (!item || typeof item !== "object") return false; |
| 1133 | const s = item as JSONSchema7; |
| 1134 | // Filter out null types and `{ not: {} }` (Zod's representation of "nothing" in optional anyOf) |
| 1135 | if (s.type === "null") return false; |
| 1136 | if (isEmptyNotSchema(s)) return false; |
| 1137 | return true; |
| 1138 | }); |
| 1139 | if (singleBranch && singleBranch.length === 1) { |
| 1140 | const objectSchema = resolveObjectSchema(singleBranch[0], definitions); |
| 1141 | if (!objectSchema) return resolved; |
| 1142 | if (resolvedHasObjectShape) { |
| 1143 | return mergeObjectSchemas([resolved, objectSchema]) ?? objectSchema; |
| 1144 | } |
| 1145 | return objectSchema; |
| 1146 | } |
| 1147 | |
| 1148 | if (resolvedHasObjectShape) return resolved; |
| 1149 | |
| 1150 | return resolved; |
| 1151 | } |
| 1152 | |
| 1153 | export function getSessionEventVariantSchemas( |
| 1154 | schema: JSONSchema7, |
no test coverage detected
searching dependent graphs…