@@ -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 }
0 commit comments