diff --git a/.changeset/tender-pianos-jump.md b/.changeset/tender-pianos-jump.md new file mode 100644 index 0000000..08fad8a --- /dev/null +++ b/.changeset/tender-pianos-jump.md @@ -0,0 +1,5 @@ +--- +'openapi-ts-request': patch +--- + +fix: 修复引用类型返回值在 types.ts中也包含了 namespace 的问题 diff --git a/src/generator/serviceGenarator.ts b/src/generator/serviceGenarator.ts index 9bbd417..d0a559f 100644 --- a/src/generator/serviceGenarator.ts +++ b/src/generator/serviceGenarator.ts @@ -641,6 +641,10 @@ export default class ServiceGenerator { const params = this.getParamsTP(newApi.parameters, newApi.path) || {}; const body = this.getBodyTP( + newApi.requestBody as RequestBodyObject, + this.config.namespace + ); + const bodyWithoutNamespace = this.getBodyTP( newApi.requestBody as RequestBodyObject ); const response = this.getResponseTP(newApi.responses); @@ -665,7 +669,7 @@ export default class ServiceGenerator { const bodyName = upperFirst(`${functionName}Body`); this.interfaceTPConfigs.push({ typeName: bodyName, - type: body?.type, + type: bodyWithoutNamespace?.type, isEnum: false, props: [], }); @@ -931,7 +935,7 @@ export default class ServiceGenerator { return resolveTypeName(`${namespace}${typeName ?? data.operationId}Params`); } - private getBodyTP(requestBody: RequestBodyObject) { + private getBodyTP(requestBody: RequestBodyObject, namespace?: string) { const reqBody = this.resolveRefObject(requestBody); if (isEmpty(reqBody)) { @@ -958,7 +962,7 @@ export default class ServiceGenerator { const bodySchema = { mediaType, required, - type: this.getType(schema, this.config.namespace), + type: this.getType(schema, namespace), isAnonymous: false, }; diff --git "a/test/__snapshots__/common/\345\260\217\351\251\274\345\263\260\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" "b/test/__snapshots__/common/\345\260\217\351\251\274\345\263\260\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" index 6d50459..2787af1 100644 --- "a/test/__snapshots__/common/\345\260\217\351\251\274\345\263\260\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" +++ "b/test/__snapshots__/common/\345\260\217\351\251\274\345\263\260\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" @@ -366,7 +366,7 @@ export type User = { userStatus?: number; }; -export type UserCreateWithListUsingPostBody = API.User[]; +export type UserCreateWithListUsingPostBody = User[]; export type userLoginUsingGetParams = { /** The user name for login */ diff --git "a/test/__snapshots__/common/\346\224\257\346\214\201 null \347\261\273\345\236\213\344\275\234\344\270\272\351\273\230\350\256\244\345\200\274.snap" "b/test/__snapshots__/common/\346\224\257\346\214\201 null \347\261\273\345\236\213\344\275\234\344\270\272\351\273\230\350\256\244\345\200\274.snap" index 28ae1f9..c6c847c 100644 --- "a/test/__snapshots__/common/\346\224\257\346\214\201 null \347\261\273\345\236\213\344\275\234\344\270\272\351\273\230\350\256\244\345\200\274.snap" +++ "b/test/__snapshots__/common/\346\224\257\346\214\201 null \347\261\273\345\236\213\344\275\234\344\270\272\351\273\230\350\256\244\345\200\274.snap" @@ -366,7 +366,7 @@ export type User = { userStatus: number | null; }; -export type UserCreateWithListUsingPostBody = API.User[]; +export type UserCreateWithListUsingPostBody = User[]; export type userLoginUsingGetParams = { /** The user name for login */ diff --git "a/test/__snapshots__/common/\346\255\243\345\270\270\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" "b/test/__snapshots__/common/\346\255\243\345\270\270\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" index a906e18..4887413 100644 --- "a/test/__snapshots__/common/\346\255\243\345\270\270\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" +++ "b/test/__snapshots__/common/\346\255\243\345\270\270\345\221\275\345\220\215\346\226\207\344\273\266\345\222\214\350\257\267\346\261\202\345\207\275\346\225\260.snap" @@ -497,7 +497,7 @@ export type User = { userStatus?: number; }; -export type UserCreateWithListUsingPostBody = API.User[]; +export type UserCreateWithListUsingPostBody = User[]; export type userLoginUsingGetParams = { /** The user name for login */ diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\345\260\206\344\270\255\346\226\207 tag \345\220\215\347\247\260\347\277\273\350\257\221\346\210\220\350\213\261\346\226\207 tag \345\220\215\347\247\260.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\345\260\206\344\270\255\346\226\207 tag \345\220\215\347\247\260\347\277\273\350\257\221\346\210\220\350\213\261\346\226\207 tag \345\220\215\347\247\260.snap" index 710fb45..6208dae 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\345\260\206\344\270\255\346\226\207 tag \345\220\215\347\247\260\347\277\273\350\257\221\346\210\220\350\213\261\346\226\207 tag \345\220\215\347\247\260.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\345\260\206\344\270\255\346\226\207 tag \345\220\215\347\247\260\347\277\273\350\257\221\346\210\220\350\213\261\346\226\207 tag \345\220\215\347\247\260.snap" @@ -344,7 +344,7 @@ export type User = { userStatus?: number; }; -export type UserCreateWithListUsingPostBody = API.User[]; +export type UserCreateWithListUsingPostBody = User[]; export type userLoginUsingGetParams = { /** The user name for login */ diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" index ee42cbe..9e6d9bb 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" @@ -4841,7 +4841,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = { datasetID: string; }; -export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[]; +export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[]; export type v1ApiAppAppIdDatasetsUsingPostParams = { /** 应用id */ @@ -5233,7 +5233,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = { }; export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody = - API.AppDatasets[]; + AppDatasets[]; export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = { /** 空间ID */ diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" index d9f464a..4855b35 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" @@ -4276,7 +4276,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = { datasetID: string; }; -export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[]; +export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[]; export type v1ApiAppAppIdDatasetsUsingPostParams = { /** 应用id */ @@ -4668,7 +4668,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = { }; export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody = - API.AppDatasets[]; + AppDatasets[]; export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = { /** 空间ID */ diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" index c600898..40ab198 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" @@ -4276,7 +4276,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = { datasetID: string; }; -export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[]; +export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[]; export type v1ApiAppAppIdDatasetsUsingPostParams = { /** 应用id */ @@ -4668,7 +4668,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = { }; export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody = - API.AppDatasets[]; + AppDatasets[]; export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = { /** 空间ID */ diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" index 312ae6a..fdbfaf6 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" @@ -395,9 +395,9 @@ export type User = { userStatus?: number; }; -export type UserCreateWithArrayUsingPostBody = API.User[]; +export type UserCreateWithArrayUsingPostBody = User[]; -export type UserCreateWithListUsingPostBody = API.User[]; +export type UserCreateWithListUsingPostBody = User[]; export type userLoginUsingGetParams = { /** The user name for login */ diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" index 1140c50..873d831 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" @@ -395,9 +395,9 @@ export type User = { userStatus?: number; }; -export type UserCreateWithArrayUsingPostBody = API.User[]; +export type UserCreateWithArrayUsingPostBody = User[]; -export type UserCreateWithListUsingPostBody = API.User[]; +export type UserCreateWithListUsingPostBody = User[]; export type userLoginUsingGetParams = { /** The user name for login */ diff --git "a/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" "b/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" index 7f9a6eb..44a0b42 100644 --- "a/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" +++ "b/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" @@ -4511,7 +4511,7 @@ export type v1ApiAppAppIdDatasetsUsingDeleteParams = { datasetID: string; }; -export type V1ApiAppAppIdDatasetsUsingPostBody = API.AppDatasets[]; +export type V1ApiAppAppIdDatasetsUsingPostBody = AppDatasets[]; export type v1ApiAppAppIdDatasetsUsingPostParams = { /** 应用id */ @@ -4903,7 +4903,7 @@ export type v2ApiWorkspacesRecommendedMessageIdDetailsUsingGetParams = { }; export type V2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostBody = - API.AppDatasets[]; + AppDatasets[]; export type v2ApiWorkspacesWorkspaceIdAppAppIdDatasetsJoinUsingPostParams = { /** 空间ID */