UNPKG

@nestjs/swagger

Version:

OpenAPI for NestJS: generate the API document from controllers and decorators, serve Swagger UI, and derive request types with mapped types.

33 lines (32 loc) • 1.22 kB
function getOperations(pathItem) { const operations = Object.values(pathItem ?? {}).filter((value) => !!value && typeof value === 'object' && 'responses' in value); return [ ...operations, ...Object.values(pathItem?.additionalOperations ?? {}) ]; } export function removeDanglingLinks(document) { const operations = [ ...Object.values(document.paths ?? {}), ...Object.values(document.webhooks ?? {}) ].flatMap((pathItem) => getOperations(pathItem)); const operationIds = new Set(operations.map((operation) => operation.operationId)); for (const operation of operations) { for (const response of Object.values(operation.responses ?? {})) { const { links } = response; if (!links) { continue; } for (const [name, link] of Object.entries(links)) { if ('operationId' in link && link.operationId && !operationIds.has(link.operationId)) { delete links[name]; } } if (Object.keys(links).length === 0) { delete response.links; } } } }