Skip to content

Commit 3d7dbb8

Browse files
fix: fix bug #536 (#538)
* fix: fix bug #536 * chore: clean code
1 parent 5ea21c6 commit 3d7dbb8

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.changeset/evil-houses-chew.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+
fix: fix bug #536

openapi-ts-request.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { type GenerateServiceProps } from './src/index';
2+
13
export default [
24
{
35
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
46
serversPath: './apis/app',
57
},
6-
];
8+
] as GenerateServiceProps[];

src/generator/serviceGenarator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,22 @@ export default class ServiceGenerator {
688688

689689
if (response?.isAnonymous) {
690690
const responseName = upperFirst(`${functionName}Response`);
691+
// 使用正则表达式移除 response?.type 中包含 this.config.namespace 的部分,isAnonymous模式不需要 this.config.namespace 前缀
692+
const cleanType = response?.type?.includes(
693+
`${this.config.namespace}.`
694+
)
695+
? response?.type?.replace(
696+
new RegExp(`${this.config.namespace}\\.`, 'g'),
697+
''
698+
)
699+
: response?.type || '';
691700
this.interfaceTPConfigs.push({
692701
typeName: responseName,
693-
type: response?.type,
702+
type: cleanType,
694703
isEnum: false,
695704
props: [],
696705
});
706+
697707
response.type = `${this.config.namespace}.${responseName}`;
698708
}
699709

0 commit comments

Comments
 (0)