(schema: unknown)
| 268 | } |
| 269 | |
| 270 | function sampleFromSchema(schema: unknown): unknown { |
| 271 | if (!isRecord(schema)) |
| 272 | return '' |
| 273 | if (schema.example !== undefined) |
| 274 | return schema.example |
| 275 | if (schema.default !== undefined) |
| 276 | return schema.default |
| 277 | if (Array.isArray(schema.enum) && schema.enum.length > 0) |
| 278 | return schema.enum[0] |
| 279 | |
| 280 | if (schema.type === 'object' || isRecord(schema.properties)) { |
| 281 | const result: Record<string, unknown> = {} |
| 282 | if (isRecord(schema.properties)) { |
| 283 | for (const [key, property] of Object.entries(schema.properties)) { |
| 284 | result[key] = sampleFromSchema(property) |
| 285 | } |
| 286 | } |
| 287 | return result |
| 288 | } |
| 289 | |
| 290 | if (schema.type === 'array') { |
| 291 | return [sampleFromSchema(schema.items)] |
| 292 | } |
| 293 | |
| 294 | if (schema.type === 'integer' || schema.type === 'number') |
| 295 | return 0 |
| 296 | if (schema.type === 'boolean') |
| 297 | return false |
| 298 | return '' |
| 299 | } |
| 300 | |
| 301 | function parseRequestBody( |
| 302 | rawBody: unknown, |
no test coverage detected