(schema: JSONSchema)
| 203 | } |
| 204 | |
| 205 | export function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & { type: 'array', items?: JSONSchema }] { |
| 206 | const schemas = expandUnionSchema(schema) |
| 207 | |
| 208 | if (schemas.length !== 2) { |
| 209 | return undefined |
| 210 | } |
| 211 | |
| 212 | const arraySchema = schemas.find( |
| 213 | s => typeof s === 'object' && s.type === 'array' && Object.keys(s).filter(k => LOGIC_KEYWORDS.includes(k)).every(k => k === 'type' || k === 'items'), |
| 214 | ) as JSONSchema & { type: 'array', items?: JSONSchema } |
| 215 | |
| 216 | if (arraySchema === undefined) { |
| 217 | return undefined |
| 218 | } |
| 219 | |
| 220 | const items1 = arraySchema.items |
| 221 | const items2 = schemas.find(s => s !== arraySchema) as JSONSchema |
| 222 | |
| 223 | if (stringifyJSON(items1) !== stringifyJSON(items2)) { |
| 224 | return undefined |
| 225 | } |
| 226 | |
| 227 | return [items2, arraySchema] |
| 228 | } |
| 229 | |
| 230 | const PRIMITIVE_SCHEMA_TYPES = new Set<string>([ |
| 231 | JSONSchemaTypeName.String, |
no test coverage detected