next-openapi-gen 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/route-processor.js +12 -2
- package/dist/lib/utils.js +17 -0
- package/dist/openapi-template.js +11 -2
- package/package.json +1 -1
|
@@ -65,7 +65,7 @@ export class RouteProcessor {
|
|
|
65
65
|
const routePath = this.getRoutePath(filePath);
|
|
66
66
|
const rootPath = capitalize(routePath.split("/")[1]);
|
|
67
67
|
const operationId = getOperationId(routePath, method);
|
|
68
|
-
const { summary, description, isOpenApi } = dataTypes;
|
|
68
|
+
const { summary, description, auth, isOpenApi } = dataTypes;
|
|
69
69
|
if (this.config.includeOpenApiRoutes && !isOpenApi) {
|
|
70
70
|
// If flag is enabled and there is no @openapi tag, then skip path
|
|
71
71
|
return;
|
|
@@ -79,8 +79,18 @@ export class RouteProcessor {
|
|
|
79
79
|
summary: summary,
|
|
80
80
|
description: description,
|
|
81
81
|
tags: [rootPath],
|
|
82
|
-
parameters: params,
|
|
83
82
|
};
|
|
83
|
+
// Add auth
|
|
84
|
+
if (auth) {
|
|
85
|
+
definition.security = [
|
|
86
|
+
{
|
|
87
|
+
[auth]: [],
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
if (params) {
|
|
92
|
+
definition.parameters = params;
|
|
93
|
+
}
|
|
84
94
|
// Add request body
|
|
85
95
|
if (MUTATION_HTTP_METHODS.includes(method.toUpperCase())) {
|
|
86
96
|
definition.requestBody =
|
package/dist/lib/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ export function extractJSDocComments(path) {
|
|
|
8
8
|
let paramsType = "";
|
|
9
9
|
let bodyType = "";
|
|
10
10
|
let responseType = "";
|
|
11
|
+
let auth = "";
|
|
11
12
|
let isOpenApi = false;
|
|
12
13
|
if (comments) {
|
|
13
14
|
comments.forEach((comment) => {
|
|
@@ -17,6 +18,21 @@ export function extractJSDocComments(path) {
|
|
|
17
18
|
const summaryIndex = isOpenApi ? 1 : 0;
|
|
18
19
|
summary = commentValue.split("\n")[summaryIndex];
|
|
19
20
|
}
|
|
21
|
+
if (commentValue.includes("@auth")) {
|
|
22
|
+
const regex = /@auth:\s*(.*)/;
|
|
23
|
+
const value = commentValue.match(regex)[1].trim();
|
|
24
|
+
switch (value) {
|
|
25
|
+
case "bearer":
|
|
26
|
+
auth = "BearerAuth";
|
|
27
|
+
break;
|
|
28
|
+
case "basic":
|
|
29
|
+
auth = "BasicAuth";
|
|
30
|
+
break;
|
|
31
|
+
case "apikey":
|
|
32
|
+
auth = "ApiKeyAuth";
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
20
36
|
if (commentValue.includes("@desc")) {
|
|
21
37
|
const regex = /@desc:\s*(.*)/;
|
|
22
38
|
description = commentValue.match(regex)[1].trim();
|
|
@@ -33,6 +49,7 @@ export function extractJSDocComments(path) {
|
|
|
33
49
|
});
|
|
34
50
|
}
|
|
35
51
|
return {
|
|
52
|
+
auth,
|
|
36
53
|
summary,
|
|
37
54
|
description,
|
|
38
55
|
paramsType,
|
package/dist/openapi-template.js
CHANGED
|
@@ -7,14 +7,23 @@ export default {
|
|
|
7
7
|
},
|
|
8
8
|
servers: [
|
|
9
9
|
{
|
|
10
|
-
url: "http://localhost:3000",
|
|
10
|
+
url: "http://localhost:3000/api",
|
|
11
11
|
description: "Local development server",
|
|
12
12
|
},
|
|
13
13
|
],
|
|
14
|
+
components: {
|
|
15
|
+
securitySchemes: {
|
|
16
|
+
BearerAuth: {
|
|
17
|
+
type: "http",
|
|
18
|
+
scheme: "bearer",
|
|
19
|
+
bearerFormat: "JWT",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
14
23
|
apiDir: "./src/app/api",
|
|
15
24
|
schemaDir: "./src",
|
|
16
25
|
docsUrl: "api-docs",
|
|
17
26
|
ui: "swagger",
|
|
18
27
|
outputFile: "swagger.json",
|
|
19
|
-
includeOpenApiRoutes:
|
|
28
|
+
includeOpenApiRoutes: false,
|
|
20
29
|
};
|