Skip to content

Commit f1b7474

Browse files
Merge pull request #321 from openapi-ui/main
feat: support response type comments
2 parents 6559ae7 + a406fc3 commit f1b7474

File tree

7 files changed

+208
-67
lines changed

7 files changed

+208
-67
lines changed

.changeset/five-sloths-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
perf: perf empty tags behavior, related bug #300

.changeset/stale-cycles-win.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': minor
3+
---
4+
5+
feat: support response type comments

pnpm-lock.yaml

Lines changed: 54 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generator/util.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export function getDefaultType(
254254
return `{ ${keys(schemaObject.properties)
255255
.map((key) => {
256256
let required = false;
257+
const property = (schemaObject.properties?.[key] || {}) as SchemaObject;
257258
258259
if (isBoolean(schemaObject.required) && schemaObject.required) {
259260
required = true;
@@ -266,20 +267,20 @@ export function getDefaultType(
266267
required = true;
267268
}
268269
269-
if (
270-
'required' in (schemaObject.properties[key] || {}) &&
271-
(schemaObject.properties[key] as SchemaObject)?.required
272-
) {
270+
if (property.required) {
273271
required = true;
274272
}
273+
275274
/**
276275
* 将类型属性变为字符串,兼容错误格式如:
277276
* 3d_tile(数字开头)等错误命名,
278277
* 在后面进行格式化的时候会将正确的字符串转换为正常形式,
279278
* 错误的继续保留字符串。
280279
* */
281-
return `'${key}'${required ? '' : '?'}: ${getDefaultType(
282-
schemaObject.properties?.[key],
280+
return `
281+
${property.description ? `/** ${property.description} */` : ''}
282+
'${key}'${required ? '' : '?'}: ${getDefaultType(
283+
property,
283284
namespace
284285
)}; `;
285286
})
@@ -293,11 +294,19 @@ export function getDefaultFileTag(
293294
operationObject: OperationObject,
294295
apiPath: string
295296
): string[] {
296-
return operationObject['x-swagger-router-controller']
297-
? [operationObject['x-swagger-router-controller'] as string]
298-
: operationObject.tags || [operationObject.operationId] || [
299-
apiPath.replace('/', '').split('/')[1],
300-
];
297+
let lastTags: string[] = [];
298+
299+
if (operationObject['x-swagger-router-controller']) {
300+
lastTags = [operationObject['x-swagger-router-controller'] as string];
301+
} else if (!isEmpty(operationObject.tags)) {
302+
lastTags = operationObject.tags;
303+
} else if (operationObject.operationId) {
304+
lastTags = [operationObject.operationId];
305+
} else {
306+
lastTags = [apiPath.replace('/', '').split('/')[1]];
307+
}
308+
309+
return lastTags;
301310
}
302311

303312
function findDuplicateTypeNames(arr: string[]) {

0 commit comments

Comments
 (0)