|
1 | 1 | import type { OpenAPIV3 } from "openapi-types";
|
2 | 2 | import { OperationBuilder, type DocumentBuilder } from "openapi-decorators/builders";
|
3 | 3 | import type { AdonisRoute } from "../types";
|
4 |
| -import { loadController } from "./loadController"; |
5 |
| -import { getApiTags } from "openapi-decorators"; |
6 |
| -import { loadApiTags } from "openapi-decorators/loaders"; |
| 4 | +import { loadApiOperation, loadController } from "openapi-decorators/loaders"; |
7 | 5 | import { normalizeRoutePattern } from "../utils/normalizeRoutePattern";
|
8 | 6 |
|
9 | 7 | export async function loadRoute(document: DocumentBuilder, route: AdonisRoute) {
|
10 | 8 | if (typeof route.handler !== "object" || !Array.isArray(route.handler.reference)) {
|
11 | 9 | return;
|
12 | 10 | }
|
13 | 11 |
|
14 |
| - const importer = route.handler.reference[0] as Function; |
| 12 | + const importer = route.handler.reference[0] as () => Promise<{ default: any }>; |
15 | 13 | const propertyKey = route.handler.reference[1] as string;
|
16 | 14 |
|
17 | 15 | const target = (await importer().then((t: any) => t.default)) as any;
|
18 | 16 |
|
19 |
| - const operation = new OperationBuilder(); |
20 |
| - |
21 |
| - const apiTags = getApiTags(target); |
22 |
| - if (apiTags) { |
23 |
| - loadApiTags(operation, apiTags); |
24 |
| - } |
25 |
| - |
26 |
| - loadController(document, operation, target.prototype, propertyKey); |
27 |
| - |
28 | 17 | for (const method of route.methods) {
|
29 | 18 | if (method === "HEAD") {
|
30 | 19 | continue;
|
31 | 20 | }
|
32 | 21 |
|
33 |
| - document.setOperation( |
34 |
| - method.toLowerCase() as OpenAPIV3.HttpMethods, |
35 |
| - normalizeRoutePattern(route.pattern), |
36 |
| - operation.build(), |
37 |
| - ); |
| 22 | + const operation = new OperationBuilder(); |
| 23 | + |
| 24 | + loadApiOperation(operation, { |
| 25 | + method: method.toLowerCase() as `${OpenAPIV3.HttpMethods}`, |
| 26 | + pattern: normalizeRoutePattern(route.pattern), |
| 27 | + }); |
| 28 | + |
| 29 | + loadController(document, operation, target.prototype, propertyKey); |
| 30 | + |
| 31 | + document.addOperation(operation); |
38 | 32 | }
|
39 | 33 | }
|
0 commit comments