Skip to content

Commit b7dd4d7

Browse files
authored
Merge pull request #398 from AdoKevin/namespace_in_types
fix: 修复引用类型返回值在 types.ts中也包含了 namespace 的问题
1 parent 7d29ba4 commit b7dd4d7

12 files changed

+28
-19
lines changed

.changeset/tender-pianos-jump.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: 修复引用类型返回值在 types.ts中也包含了 namespace 的问题

src/generator/serviceGenarator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ export default class ServiceGenerator {
641641
const params =
642642
this.getParamsTP(newApi.parameters, newApi.path) || {};
643643
const body = this.getBodyTP(
644+
newApi.requestBody as RequestBodyObject,
645+
this.config.namespace
646+
);
647+
const bodyWithoutNamespace = this.getBodyTP(
644648
newApi.requestBody as RequestBodyObject
645649
);
646650
const response = this.getResponseTP(newApi.responses);
@@ -665,7 +669,7 @@ export default class ServiceGenerator {
665669
const bodyName = upperFirst(`${functionName}Body`);
666670
this.interfaceTPConfigs.push({
667671
typeName: bodyName,
668-
type: body?.type,
672+
type: bodyWithoutNamespace?.type,
669673
isEnum: false,
670674
props: [],
671675
});
@@ -931,7 +935,7 @@ export default class ServiceGenerator {
931935
return resolveTypeName(`${namespace}${typeName ?? data.operationId}Params`);
932936
}
933937

934-
private getBodyTP(requestBody: RequestBodyObject) {
938+
private getBodyTP(requestBody: RequestBodyObject, namespace?: string) {
935939
const reqBody = this.resolveRefObject(requestBody);
936940

937941
if (isEmpty(reqBody)) {
@@ -958,7 +962,7 @@ export default class ServiceGenerator {
958962
const bodySchema = {
959963
mediaType,
960964
required,
961-
type: this.getType(schema, this.config.namespace),
965+
type: this.getType(schema, namespace),
962966
isAnonymous: false,
963967
};
964968

test/__snapshots__/common/小驼峰命名文件和请求函数.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export type User = {
366366
userStatus?: number;
367367
};
368368

369-
export type UserCreateWithListUsingPostBody = API.User[];
369+
export type UserCreateWithListUsingPostBody = User[];
370370

371371
export type userLoginUsingGetParams = {
372372
/** The user name for login */

test/__snapshots__/common/支持 null 类型作为默认值.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export type User = {
366366
userStatus: number | null;
367367
};
368368

369-
export type UserCreateWithListUsingPostBody = API.User[];
369+
export type UserCreateWithListUsingPostBody = User[];
370370

371371
export type userLoginUsingGetParams = {
372372
/** The user name for login */

test/__snapshots__/common/正常命名文件和请求函数.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ export type User = {
497497
userStatus?: number;
498498
};
499499

500-
export type UserCreateWithListUsingPostBody = API.User[];
500+
export type UserCreateWithListUsingPostBody = User[];
501501

502502
export type userLoginUsingGetParams = {
503503
/** The user name for login */

test/__snapshots__/common/测试将中文 tag 名称翻译成英文 tag 名称.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export type User = {
344344
userStatus?: number;
345345
};
346346

347-
export type UserCreateWithListUsingPostBody = API.User[];
347+
export type UserCreateWithListUsingPostBody = User[];
348348

349349
export type userLoginUsingGetParams = {
350350
/** The user name for login */

test/__snapshots__/common/测试生成 JSON Schemas.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,7 +4841,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = {
48414841
datasetID: string;
48424842
};
48434843

4844-
export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[];
4844+
export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[];
48454845

48464846
export type v1ApiAppAppIdDatasetsUsingPostParams = {
48474847
/** 应用id */
@@ -5233,7 +5233,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = {
52335233
};
52345234

52355235
export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody =
5236-
API.AppDatasets[];
5236+
AppDatasets[];
52375237

52385238
export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = {
52395239
/** 空间ID */

test/__snapshots__/common/测试生成 react-query 的 vue 模式.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,7 +4276,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = {
42764276
datasetID: string;
42774277
};
42784278

4279-
export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[];
4279+
export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[];
42804280

42814281
export type v1ApiAppAppIdDatasetsUsingPostParams = {
42824282
/** 应用id */
@@ -4668,7 +4668,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = {
46684668
};
46694669

46704670
export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody =
4671-
API.AppDatasets[];
4671+
AppDatasets[];
46724672

46734673
export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = {
46744674
/** 空间ID */

test/__snapshots__/common/测试生成 react-query.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,7 +4276,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = {
42764276
datasetID: string;
42774277
};
42784278

4279-
export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[];
4279+
export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[];
42804280

42814281
export type v1ApiAppAppIdDatasetsUsingPostParams = {
42824282
/** 应用id */
@@ -4668,7 +4668,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = {
46684668
};
46694669

46704670
export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody =
4671-
API.AppDatasets[];
4671+
AppDatasets[];
46724672

46734673
export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = {
46744674
/** 空间ID */

test/__snapshots__/common/测试解析 swagger.yaml_openapi.yaml.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ export type User = {
395395
userStatus?: number;
396396
};
397397

398-
export type UserCreateWithArrayUsingPostBody = API.User[];
398+
export type UserCreateWithArrayUsingPostBody = User[];
399399

400-
export type UserCreateWithListUsingPostBody = API.User[];
400+
export type UserCreateWithListUsingPostBody = User[];
401401

402402
export type userLoginUsingGetParams = {
403403
/** The user name for login */

0 commit comments

Comments
 (0)