(bodies: ResponseBodies, defaultDescription: () => string)
| 386 | const method = endpoint.method.toLowerCase() as OpenAPISpecMethodName |
| 387 | |
| 388 | function processResponseBodies(bodies: ResponseBodies, defaultDescription: () => string) { |
| 389 | for (const [status, { content, descriptions, headers, streamContent }] of bodies) { |
| 390 | const description = descriptions.size > 0 ? Array.from(descriptions).join(" | ") : defaultDescription() |
| 391 | InternalRecord.assignProperty(op.responses, status, { |
| 392 | description |
| 393 | }) |
| 394 | for (const schema of headers) { |
| 395 | const ast = SchemaAST.getLastEncoding(schema.ast) |
| 396 | if (SchemaAST.isObjects(ast)) { |
| 397 | for (const ps of ast.propertySignatures) { |
| 398 | const name = String(ps.name).toLowerCase() |
| 399 | if (name === "content-type") continue |
| 400 | op.responses[status].headers ??= {} |
| 401 | InternalRecord.assignProperty(op.responses[status].headers, name, { |
| 402 | schema: {}, |
| 403 | required: !SchemaAST.isOptional(ps.type) |
| 404 | }) |
| 405 | pathOps.push({ |
| 406 | _tag: "parameter", |
| 407 | ast: ps.type, |
| 408 | path: ["paths", path, method, "responses", String(status), "headers", name, "schema"] |
| 409 | }) |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | if (content !== undefined) { |
| 414 | content.forEach((map, encoding) => { |
| 415 | map.forEach((schemas, contentType) => { |
| 416 | const asts = Array.from(schemas, SchemaAST.getAST) |
| 417 | const ast = asts.length === 1 ? asts[0] : new SchemaAST.Union(asts, "anyOf") |
| 418 | |
| 419 | pathOps.push({ |
| 420 | _tag: "schema", |
| 421 | ast: toEncodingAST(ast, encoding), |
| 422 | path: ["paths", path, method, "responses", String(status), "content", contentType, "schema"] |
| 423 | }) |
| 424 | op.responses[status].content ??= {} |
| 425 | InternalRecord.assignProperty(op.responses[status].content, contentType, { |
| 426 | schema: {} |
| 427 | }) |
| 428 | }) |
| 429 | }) |
| 430 | } |
| 431 | if (streamContent !== undefined) { |
| 432 | streamContent.forEach((stream, contentType) => { |
| 433 | op.responses[status].content ??= {} |
| 434 | if (HttpApiSchema.isStreamSse(stream)) { |
| 435 | pathOps.push({ |
| 436 | _tag: "schema", |
| 437 | ast: SchemaAST.getAST(stream.events), |
| 438 | path: ["paths", path, method, "responses", String(status), "content", contentType, "schema"] |
| 439 | }) |
| 440 | pathOps.push({ |
| 441 | _tag: "schema", |
| 442 | ast: SchemaAST.getAST(Schema.toCodecJson(Schema.Cause(stream.error, Schema.Defect()))), |
| 443 | path: [ |
| 444 | "paths", |
| 445 | path, |
no test coverage detected