(value: unknown)
| 24 | } |
| 25 | |
| 26 | function normalize(value: unknown): unknown { |
| 27 | if (Array.isArray(value)) return value.map(normalize) |
| 28 | if (!isRecord(value)) return value |
| 29 | |
| 30 | const schema = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, normalize(item)])) |
| 31 | |
| 32 | if (Array.isArray(schema.anyOf)) { |
| 33 | const anyOf = schema.anyOf.filter((item) => !isRecord(item) || item.type !== "null") |
| 34 | if (anyOf.length !== schema.anyOf.length) { |
| 35 | const { anyOf: _, ...rest } = schema |
| 36 | if (anyOf.length === 1 && isRecord(anyOf[0])) return normalize({ ...anyOf[0], ...rest }) |
| 37 | return { ...rest, anyOf } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if (Array.isArray(schema.allOf) && schema.allOf.length === 1 && isRecord(schema.allOf[0])) { |
| 42 | const { allOf: _, ...rest } = schema |
| 43 | return normalize({ ...schema.allOf[0], ...rest }) |
| 44 | } |
| 45 | |
| 46 | if (schema.type === "integer" && schema.maximum === undefined) { |
| 47 | return { ...schema, maximum: Number.MAX_SAFE_INTEGER } |
| 48 | } |
| 49 | |
| 50 | return schema |
| 51 | } |
| 52 | |
| 53 | function restoreModelRefs(value: unknown, key?: string): unknown { |
| 54 | if (Array.isArray(value)) return value.map((item) => restoreModelRefs(item)) |
no test coverage detected