(schema: T)
| 270 | * keep just `type: "boolean"`. Other codegen runs on the original schema. |
| 271 | */ |
| 272 | export function stripBooleanLiterals<T>(schema: T): T { |
| 273 | if (typeof schema !== "object" || schema === null) return schema; |
| 274 | if (Array.isArray(schema)) { |
| 275 | return schema.map((item) => stripBooleanLiterals(item)) as unknown as T; |
| 276 | } |
| 277 | const result: Record<string, unknown> = {}; |
| 278 | const src = schema as unknown as Record<string, unknown>; |
| 279 | const isBooleanType = src.type === "boolean"; |
| 280 | for (const [key, value] of Object.entries(src)) { |
| 281 | if (isBooleanType && key === "const" && typeof value === "boolean") continue; |
| 282 | if ( |
| 283 | isBooleanType && |
| 284 | key === "enum" && |
| 285 | Array.isArray(value) && |
| 286 | value.every((v) => typeof v === "boolean") |
| 287 | ) { |
| 288 | continue; |
| 289 | } |
| 290 | result[key] = stripBooleanLiterals(value); |
| 291 | } |
| 292 | return result as T; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Normalize schema defects where a required property with a `$ref` to an object type |
no outgoing calls
no test coverage detected
searching dependent graphs…