Skip to content

Commit 59ffa65

Browse files
committed
fix: 修正生成模板中的可选URI格式
1 parent 8795bfb commit 59ffa65

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/lib/generate-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class ${className}<T extends object = object> extends BaseOpenapiClient<T
104104
} else if (optionalUris.length === 0) {
105105
opts = `[opts: ${optType}]`;
106106
} else {
107-
opts = `K extends '${optionalUris.join(' | ')}' ? [opts?: ${optType}] : [opts: ${optType}]`;
107+
opts = `K extends '${optionalUris.join("' | '")}' ? [opts?: ${optType}] : [opts: ${optType}]`;
108108
}
109109
110110
return `${method}<K extends keyof ${className}_${method}_paths>(

test/lib/generate-template.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const prettierOptions: prettier.Options = {
1919

2020
const formatDocs = (content: string) => prettier.format(content, prettierOptions);
2121

22-
test('完整的类型提示', async () => {
22+
test('完整的文件内容', async () => {
2323
const docs = getBasicDocument({
2424
'/users': {
2525
get: {
@@ -456,14 +456,26 @@ describe('类', () => {
456456
responseTypes: [],
457457
tags: [],
458458
},
459+
{
460+
uri: '/c',
461+
method: 'get',
462+
key: 'cc',
463+
query: { optional: true, types: [] },
464+
params: { optional: true, types: [] },
465+
body: { optional: true, types: [] },
466+
response: { types: [] },
467+
contentTypes: [],
468+
responseTypes: [],
469+
tags: [],
470+
},
459471
],
460472
});
461473
const content = generateMethodModeClass('Client', metas);
462474
await expect(formatDocs(content)).resolves.toMatchInlineSnapshot(`
463475
"export class Client<T extends object = object> extends BaseOpenapiClient<T> {
464476
get<K extends keyof Client_get_paths>(
465477
uri: K,
466-
...rest: K extends '/b'
478+
...rest: K extends '/b' | '/c'
467479
? [opts?: Client_get_paths[K]['request'] & BaseOpenapiClient.UserInputOpts<T>]
468480
: [opts: Client_get_paths[K]['request'] & BaseOpenapiClient.UserInputOpts<T>]
469481
): Promise<Client_get_paths[K]['response']> {

0 commit comments

Comments
 (0)