next-openapi-gen 0.9.3 → 0.9.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.
- package/dist/lib/route-processor.js +62 -40
- package/dist/lib/utils.js +11 -2
- package/package.json +1 -1
|
@@ -24,43 +24,57 @@ export class RouteProcessor {
|
|
|
24
24
|
const responses = {};
|
|
25
25
|
// 1. Add success response
|
|
26
26
|
const successCode = dataTypes.successCode || this.getDefaultSuccessCode(method);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
responseType: baseType,
|
|
40
|
-
});
|
|
41
|
-
// Build schema reference
|
|
42
|
-
if (arrayDepth === 0) {
|
|
43
|
-
// Not an array
|
|
44
|
-
schema = { $ref: `#/components/schemas/${baseType}` };
|
|
27
|
+
// Handle 204 No Content responses without a schema
|
|
28
|
+
if (successCode === "204" && !dataTypes.responseType) {
|
|
29
|
+
responses[successCode] = {
|
|
30
|
+
description: dataTypes.responseDescription || "No Content",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (dataTypes.responseType) {
|
|
34
|
+
// 204 No Content should not have a content section per HTTP/OpenAPI spec
|
|
35
|
+
if (successCode === "204") {
|
|
36
|
+
responses[successCode] = {
|
|
37
|
+
description: dataTypes.responseDescription || "No Content",
|
|
38
|
+
};
|
|
45
39
|
}
|
|
46
40
|
else {
|
|
47
|
-
//
|
|
48
|
-
schema
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
// Handle array notation (e.g., "Type[]", "Type[][]", "Generic<T>[]")
|
|
42
|
+
let schema;
|
|
43
|
+
let baseType = dataTypes.responseType;
|
|
44
|
+
let arrayDepth = 0;
|
|
45
|
+
// Count and remove array brackets
|
|
46
|
+
while (baseType.endsWith('[]')) {
|
|
47
|
+
arrayDepth++;
|
|
48
|
+
baseType = baseType.slice(0, -2);
|
|
54
49
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
// Ensure the base schema is defined in components/schemas
|
|
51
|
+
this.schemaProcessor.getSchemaContent({
|
|
52
|
+
responseType: baseType,
|
|
53
|
+
});
|
|
54
|
+
// Build schema reference
|
|
55
|
+
if (arrayDepth === 0) {
|
|
56
|
+
// Not an array
|
|
57
|
+
schema = { $ref: `#/components/schemas/${baseType}` };
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Build nested array schema
|
|
61
|
+
schema = { $ref: `#/components/schemas/${baseType}` };
|
|
62
|
+
for (let i = 0; i < arrayDepth; i++) {
|
|
63
|
+
schema = {
|
|
64
|
+
type: "array",
|
|
65
|
+
items: schema,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
responses[successCode] = {
|
|
70
|
+
description: dataTypes.responseDescription || "Successful response",
|
|
71
|
+
content: {
|
|
72
|
+
"application/json": {
|
|
73
|
+
schema: schema,
|
|
74
|
+
},
|
|
61
75
|
},
|
|
62
|
-
}
|
|
63
|
-
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
64
78
|
}
|
|
65
79
|
// 2. Add responses from ResponseSet
|
|
66
80
|
const responseSetName = dataTypes.responseSet || this.config.defaultResponseSet;
|
|
@@ -88,14 +102,22 @@ export class RouteProcessor {
|
|
|
88
102
|
const [code, ref] = responseRef.split(":");
|
|
89
103
|
if (ref) {
|
|
90
104
|
// Custom schema: "409:ConflictResponse"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"
|
|
95
|
-
|
|
105
|
+
// 204 No Content should not have a content section per HTTP/OpenAPI spec
|
|
106
|
+
if (code === "204") {
|
|
107
|
+
responses[code] = {
|
|
108
|
+
description: this.getDefaultErrorDescription(code) || "No Content",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
responses[code] = {
|
|
113
|
+
description: this.getDefaultErrorDescription(code) || `HTTP ${code} response`,
|
|
114
|
+
content: {
|
|
115
|
+
"application/json": {
|
|
116
|
+
schema: { $ref: `#/components/schemas/${ref}` },
|
|
117
|
+
},
|
|
96
118
|
},
|
|
97
|
-
}
|
|
98
|
-
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
99
121
|
}
|
|
100
122
|
else {
|
|
101
123
|
// Only code: "409" - use $ref fro components/responses
|
package/dist/lib/utils.js
CHANGED
|
@@ -138,8 +138,17 @@ export function extractJSDocComments(path) {
|
|
|
138
138
|
const responseMatch = commentValue.match(/@response\s+(?:(\d+):)?([^@\n\r]+)(?:\s+(.*))?/);
|
|
139
139
|
if (responseMatch) {
|
|
140
140
|
const [, code, type] = responseMatch;
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
const trimmedType = type?.trim();
|
|
142
|
+
// Check if the type is just a status code (e.g., "@response 204")
|
|
143
|
+
if (!code && trimmedType && /^\d{3}$/.test(trimmedType)) {
|
|
144
|
+
// Type is actually a status code without a schema
|
|
145
|
+
successCode = trimmedType;
|
|
146
|
+
responseType = undefined;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
successCode = code || "";
|
|
150
|
+
responseType = trimmedType;
|
|
151
|
+
}
|
|
143
152
|
}
|
|
144
153
|
else {
|
|
145
154
|
responseType = extractTypeFromComment(commentValue, "@response");
|
package/package.json
CHANGED