Skip to content

Commit b342a5e

Browse files
rookie-luochaodependabot[bot]AdoKevin
authored
chore: merge main to release (#400)
* build(deps): bump bing-translate-api from 4.0.2 to 4.1.0 Bumps [bing-translate-api](https://github.com/plainheart/bing-translate-api) from 4.0.2 to 4.1.0. - [Release notes](https://github.com/plainheart/bing-translate-api/releases) - [Commits](plainheart/bing-translate-api@v4.0.2...v4.1.0) --- updated-dependencies: - dependency-name: bing-translate-api dependency-version: 4.1.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps-dev): bump @tanstack/react-query from 5.80.10 to 5.82.0 Bumps [@tanstack/react-query](https://github.com/TanStack/query/tree/HEAD/packages/react-query) from 5.80.10 to 5.82.0. - [Release notes](https://github.com/TanStack/query/releases) - [Commits](https://github.com/TanStack/query/commits/v5.82.0/packages/react-query) --- updated-dependencies: - dependency-name: "@tanstack/react-query" dependency-version: 5.82.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Merge pull request #398 from AdoKevin/namespace_in_types fix: 修复引用类型返回值在 types.ts中也包含了 namespace 的问题 * chore: clean code --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kevin Law <kevinlaw1024@gmail.com>
2 parents bc53080 + 6d3a55a commit b342a5e

13 files changed

+57
-61
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 的问题

pnpm-lock.yaml

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

src/generator/serviceGenarator.ts

Lines changed: 10 additions & 8 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,14 +962,12 @@ 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

965-
// 具名 body 场景
966-
if (isReferenceObject(schema)) {
967-
bodySchema.type = `${bodySchema.type}`;
968-
} else {
969+
// 匿名 body 场景
970+
if (!isReferenceObject(schema)) {
969971
bodySchema.isAnonymous = true;
970972
}
971973

@@ -1066,7 +1068,7 @@ export default class ServiceGenerator {
10661068
DEFAULT_SCHEMA) as SchemaObject;
10671069
}
10681070

1069-
responseSchema.type = `${this.getType(schema, this.config.namespace)}`;
1071+
responseSchema.type = this.getType(schema, this.config.namespace);
10701072

10711073
return responseSchema;
10721074
}

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 */

0 commit comments

Comments
 (0)