(spec: Record<string, unknown>)
| 60 | * Resolves all $refs inline and extracts only the fields needed for search. |
| 61 | */ |
| 62 | export function processSpec(spec: Record<string, unknown>): { |
| 63 | paths: Record<string, Record<string, unknown>> |
| 64 | } { |
| 65 | const rawPaths = (spec.paths || {}) as Record<string, Record<string, OperationObject>> |
| 66 | const paths: Record<string, Record<string, unknown>> = {} |
| 67 | |
| 68 | for (const [path, pathItem] of Object.entries(rawPaths)) { |
| 69 | if (!pathItem) continue |
| 70 | paths[path] = {} |
| 71 | |
| 72 | for (const method of HTTP_METHODS) { |
| 73 | const op = pathItem[method] |
| 74 | if (op) { |
| 75 | const product = extractProduct(path) |
| 76 | const tags = op.tags ? [...op.tags] : [] |
| 77 | if (product && !tags.some((t) => t.toLowerCase() === product.toLowerCase())) { |
| 78 | tags.unshift(product) |
| 79 | } |
| 80 | paths[path][method] = { |
| 81 | summary: op.summary, |
| 82 | description: op.description, |
| 83 | tags, |
| 84 | parameters: resolveRefs(op.parameters, spec), |
| 85 | requestBody: resolveRefs(op.requestBody, spec), |
| 86 | responses: resolveRefs(op.responses, spec) |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return { paths } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Extract sorted product list from the spec paths. |
no test coverage detected