next-openapi-gen 0.5.3 → 0.5.4
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.
|
@@ -109,7 +109,7 @@ export class RouteProcessor {
|
|
|
109
109
|
const routePath = this.getRoutePath(filePath);
|
|
110
110
|
const rootPath = capitalize(routePath.split("/")[1]);
|
|
111
111
|
const operationId = getOperationId(routePath, method);
|
|
112
|
-
const { tag, summary, description, auth, isOpenApi } = dataTypes;
|
|
112
|
+
const { tag, summary, description, auth, isOpenApi, deprecated, bodyDescription, responseDescription, } = dataTypes;
|
|
113
113
|
if (this.config.includeOpenApiRoutes && !isOpenApi) {
|
|
114
114
|
// If flag is enabled and there is no @openapi tag, then skip path
|
|
115
115
|
return;
|
|
@@ -125,6 +125,9 @@ export class RouteProcessor {
|
|
|
125
125
|
tags: [tag || rootPath],
|
|
126
126
|
parameters: [],
|
|
127
127
|
};
|
|
128
|
+
if (deprecated) {
|
|
129
|
+
definition.deprecated = true;
|
|
130
|
+
}
|
|
128
131
|
// Add auth
|
|
129
132
|
if (auth) {
|
|
130
133
|
definition.security = [
|
|
@@ -157,12 +160,11 @@ export class RouteProcessor {
|
|
|
157
160
|
}
|
|
158
161
|
// Add request body
|
|
159
162
|
if (MUTATION_HTTP_METHODS.includes(method.toUpperCase())) {
|
|
160
|
-
definition.requestBody =
|
|
161
|
-
this.schemaProcessor.createRequestBodySchema(body);
|
|
163
|
+
definition.requestBody = this.schemaProcessor.createRequestBodySchema(body, bodyDescription);
|
|
162
164
|
}
|
|
163
165
|
// Add responses
|
|
164
166
|
definition.responses = responses
|
|
165
|
-
? this.schemaProcessor.createResponseSchema(responses)
|
|
167
|
+
? this.schemaProcessor.createResponseSchema(responses, responseDescription)
|
|
166
168
|
: {};
|
|
167
169
|
this.swaggerPaths[routePath][method] = definition;
|
|
168
170
|
}
|
|
@@ -555,19 +555,23 @@ export class SchemaProcessor {
|
|
|
555
555
|
}
|
|
556
556
|
return queryParams;
|
|
557
557
|
}
|
|
558
|
-
createRequestBodySchema(body) {
|
|
559
|
-
|
|
558
|
+
createRequestBodySchema(body, description) {
|
|
559
|
+
const schema = {
|
|
560
560
|
content: {
|
|
561
561
|
"application/json": {
|
|
562
562
|
schema: body,
|
|
563
563
|
},
|
|
564
564
|
},
|
|
565
565
|
};
|
|
566
|
+
if (description) {
|
|
567
|
+
schema.description = description;
|
|
568
|
+
}
|
|
569
|
+
return schema;
|
|
566
570
|
}
|
|
567
|
-
createResponseSchema(responses) {
|
|
571
|
+
createResponseSchema(responses, description) {
|
|
568
572
|
return {
|
|
569
573
|
200: {
|
|
570
|
-
description: "Successful response",
|
|
574
|
+
description: description || "Successful response",
|
|
571
575
|
content: {
|
|
572
576
|
"application/json": {
|
|
573
577
|
schema: responses,
|
package/dist/lib/utils.js
CHANGED
|
@@ -25,10 +25,30 @@ export function extractJSDocComments(path) {
|
|
|
25
25
|
let responseType = "";
|
|
26
26
|
let auth = "";
|
|
27
27
|
let isOpenApi = false;
|
|
28
|
+
let deprecated = false;
|
|
29
|
+
let bodyDescription = "";
|
|
30
|
+
let responseDescription = "";
|
|
28
31
|
if (comments) {
|
|
29
32
|
comments.forEach((comment) => {
|
|
30
33
|
const commentValue = cleanComment(comment.value);
|
|
31
34
|
isOpenApi = commentValue.includes("@openapi");
|
|
35
|
+
if (commentValue.includes("@deprecated")) {
|
|
36
|
+
deprecated = true;
|
|
37
|
+
}
|
|
38
|
+
if (commentValue.includes("@bodyDescription")) {
|
|
39
|
+
const regex = /@bodyDescription\s*(.*)/;
|
|
40
|
+
const match = commentValue.match(regex);
|
|
41
|
+
if (match && match[1]) {
|
|
42
|
+
bodyDescription = match[1].trim();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (commentValue.includes("@responseDescription")) {
|
|
46
|
+
const regex = /@responseDescription\s*(.*)/;
|
|
47
|
+
const match = commentValue.match(regex);
|
|
48
|
+
if (match && match[1]) {
|
|
49
|
+
responseDescription = match[1].trim();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
32
52
|
if (!summary) {
|
|
33
53
|
summary = commentValue.split("\n")[0];
|
|
34
54
|
}
|
|
@@ -82,6 +102,9 @@ export function extractJSDocComments(path) {
|
|
|
82
102
|
bodyType,
|
|
83
103
|
responseType,
|
|
84
104
|
isOpenApi,
|
|
105
|
+
deprecated,
|
|
106
|
+
bodyDescription,
|
|
107
|
+
responseDescription,
|
|
85
108
|
};
|
|
86
109
|
}
|
|
87
110
|
export function extractTypeFromComment(commentValue, tag) {
|
|
@@ -877,6 +877,9 @@ export class ZodSchemaConverter {
|
|
|
877
877
|
schema.description = node.arguments[0].value;
|
|
878
878
|
}
|
|
879
879
|
break;
|
|
880
|
+
case "deprecated":
|
|
881
|
+
schema.deprecated = true;
|
|
882
|
+
break;
|
|
880
883
|
case "min":
|
|
881
884
|
if (node.arguments.length > 0 &&
|
|
882
885
|
t.isNumericLiteral(node.arguments[0])) {
|
package/package.json
CHANGED