({ endpoint, group, mergedAnnotations, middleware })
| 367 | spec.tags.push(tag) |
| 368 | }, |
| 369 | onEndpoint({ endpoint, group, mergedAnnotations, middleware }) { |
| 370 | if (Context.get(mergedAnnotations, Exclude)) { |
| 371 | return |
| 372 | } |
| 373 | let op: OpenAPISpecOperation = { |
| 374 | tags: [Context.getOrElse(group.annotations, Title, () => group.identifier)], |
| 375 | operationId: Context.getOrElse( |
| 376 | endpoint.annotations, |
| 377 | Identifier, |
| 378 | () => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}` |
| 379 | ), |
| 380 | parameters: [], |
| 381 | security: [], |
| 382 | responses: {} |
| 383 | } |
| 384 | |
| 385 | const path = endpoint.path.replace(/:(\w+)\??/g, "{$1}") |
| 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: {} |
nothing calls this directly
no test coverage detected