@@ -859,7 +859,7 @@ func buildRequestConvertData(request, payload *expr.AttributeExpr, md []*Metadat
859
859
// server side
860
860
var data * InitData
861
861
{
862
- data = buildInitData (request , payload , "message" , "v" , svcCtx , false , svr , sd )
862
+ data = buildInitData (request , payload , "message" , "v" , svcCtx , false , svr , false , sd )
863
863
data .Name = fmt .Sprintf ("New%sPayload" , codegen .Goify (e .Name (), true ))
864
864
data .Description = fmt .Sprintf ("%s builds the payload of the %q endpoint of the %q service from the gRPC request type." , data .Name , e .Name (), svc .Name )
865
865
for _ , m := range md {
@@ -895,7 +895,7 @@ func buildRequestConvertData(request, payload *expr.AttributeExpr, md []*Metadat
895
895
data * InitData
896
896
)
897
897
{
898
- data = buildInitData (payload , request , "payload" , "message" , svcCtx , true , svr , sd )
898
+ data = buildInitData (payload , request , "payload" , "message" , svcCtx , true , svr , false , sd )
899
899
data .Description = fmt .Sprintf ("%s builds the gRPC request type from the payload of the %q endpoint of the %q service." , data .Name , e .Name (), svc .Name )
900
900
}
901
901
return & ConvertData {
@@ -929,7 +929,7 @@ func buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *code
929
929
930
930
var data * InitData
931
931
{
932
- data = buildInitData (result , response , "result" , "message" , svcCtx , true , svr , sd )
932
+ data = buildInitData (result , response , "result" , "message" , svcCtx , true , svr , false , sd )
933
933
data .Description = fmt .Sprintf ("%s builds the gRPC response type from the result of the %q endpoint of the %q service." , data .Name , e .Name (), svc .Name )
934
934
}
935
935
return & ConvertData {
@@ -945,7 +945,7 @@ func buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *code
945
945
946
946
var data * InitData
947
947
{
948
- data = buildInitData (response , result , "message" , "result" , svcCtx , false , svr , sd )
948
+ data = buildInitData (response , result , "message" , "result" , svcCtx , false , svr , false , sd )
949
949
data .Name = fmt .Sprintf ("New%sResult" , codegen .Goify (e .Name (), true ))
950
950
data .Description = fmt .Sprintf ("%s builds the result type of the %q endpoint of the %q service from the gRPC response type." , data .Name , e .Name (), svc .Name )
951
951
for _ , m := range hdrs {
@@ -1000,7 +1000,7 @@ func buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *code
1000
1000
// svcCtx is the attribute context for service type
1001
1001
// proto if true indicates the target type is a protocol buffer type
1002
1002
// svr if true indicates the code is generated for conversion server side
1003
- func buildInitData (source , target * expr.AttributeExpr , sourceVar , targetVar string , svcCtx * codegen.AttributeContext , proto , svr bool , sd * ServiceData ) * InitData {
1003
+ func buildInitData (source , target * expr.AttributeExpr , sourceVar , targetVar string , svcCtx * codegen.AttributeContext , proto , svr , usesrc bool , sd * ServiceData ) * InitData {
1004
1004
var (
1005
1005
name string
1006
1006
isStruct bool
@@ -1024,6 +1024,9 @@ func buildInitData(source, target *expr.AttributeExpr, sourceVar, targetVar stri
1024
1024
name += "Proto"
1025
1025
}
1026
1026
isStruct = expr .IsObject (target .Type ) || expr .IsUnion (target .Type )
1027
+ if _ , ok := source .Type .(expr.UserType ); ok && usesrc {
1028
+ name += protoBufGoTypeName (source , sd .Scope )
1029
+ }
1027
1030
n := protoBufGoTypeName (target , sd .Scope )
1028
1031
if ! isStruct {
1029
1032
// If target is array, map, or primitive the name will be suffixed with
@@ -1103,7 +1106,7 @@ func buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd
1103
1106
1104
1107
var data * InitData
1105
1108
{
1106
- data = buildInitData (ge .ErrorExpr .AttributeExpr , ge .Response .Message , "er" , "message" , svcCtx , true , svr , sd )
1109
+ data = buildInitData (ge .ErrorExpr .AttributeExpr , ge .Response .Message , "er" , "message" , svcCtx , true , svr , false , sd )
1107
1110
data .Name = fmt .Sprintf ("New%s%sError" , codegen .Goify (e .Name (), true ), codegen .Goify (ge .Name , true ))
1108
1111
data .Description = fmt .Sprintf ("%s builds the gRPC error response type from the error of the %q endpoint of the %q service." , data .Name , e .Name (), svc .Name )
1109
1112
}
@@ -1120,7 +1123,7 @@ func buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd
1120
1123
1121
1124
var data * InitData
1122
1125
{
1123
- data = buildInitData (ge .Response .Message , ge .ErrorExpr .AttributeExpr , "message" , "er" , svcCtx , false , svr , sd )
1126
+ data = buildInitData (ge .Response .Message , ge .ErrorExpr .AttributeExpr , "message" , "er" , svcCtx , false , svr , false , sd )
1124
1127
data .Name = fmt .Sprintf ("New%s%sError" , codegen .Goify (e .Name (), true ), codegen .Goify (ge .Name , true ))
1125
1128
data .Description = fmt .Sprintf ("%s builds the error type of the %q endpoint of the %q service from the gRPC error response type." , data .Name , e .Name (), svc .Name )
1126
1129
}
@@ -1139,19 +1142,19 @@ func buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd
1139
1142
// svr param indicates that the stream data is built for the server.
1140
1143
func buildStreamData (e * expr.GRPCEndpointExpr , sd * ServiceData , svr bool ) * StreamData {
1141
1144
var (
1142
- varn string
1143
- intName string
1144
- svcInt string
1145
- sendName string
1146
- sendDesc string
1147
- sendRef string
1148
- sendType * ConvertData
1149
- recvName string
1150
- recvDesc string
1151
- recvRef string
1152
- recvType * ConvertData
1153
- mustClose bool
1154
- typ string
1145
+ varn string
1146
+ intName string
1147
+ svcInt string
1148
+ sendName string
1149
+ sendDesc string
1150
+ sendRef string
1151
+ sendConvert * ConvertData
1152
+ recvName string
1153
+ recvDesc string
1154
+ recvRef string
1155
+ recvConvert * ConvertData
1156
+ mustClose bool
1157
+ typ string
1155
1158
1156
1159
svc = sd .Service
1157
1160
ed = sd .Endpoint (e .Name ())
@@ -1172,23 +1175,23 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea
1172
1175
if e .MethodExpr .Result .Type != expr .Empty {
1173
1176
sendName = md .ServerStream .SendName
1174
1177
sendRef = ed .ResultRef
1175
- sendType = & ConvertData {
1178
+ sendConvert = & ConvertData {
1176
1179
SrcName : resCtx .Scope .Name (result , resCtx .Pkg (result ), resCtx .Pointer , resCtx .UseDefault ),
1177
1180
SrcRef : resCtx .Scope .Ref (result , resCtx .Pkg (result )),
1178
1181
TgtName : protoBufGoFullTypeName (e .Response .Message , sd .PkgName , sd .Scope ),
1179
1182
TgtRef : protoBufGoFullTypeRef (e .Response .Message , sd .PkgName , sd .Scope ),
1180
- Init : buildInitData (result , e .Response .Message , resVar , "v" , resCtx , true , svr , sd ),
1183
+ Init : buildInitData (result , e .Response .Message , resVar , "v" , resCtx , true , svr , true , sd ),
1181
1184
}
1182
1185
}
1183
1186
if e .MethodExpr .StreamingPayload .Type != expr .Empty {
1184
1187
recvName = md .ServerStream .RecvName
1185
1188
recvRef = svcCtx .Scope .Ref (e .MethodExpr .StreamingPayload , svcCtx .Pkg (e .MethodExpr .StreamingPayload ))
1186
- recvType = & ConvertData {
1189
+ recvConvert = & ConvertData {
1187
1190
SrcName : protoBufGoFullTypeName (e .StreamingRequest , sd .PkgName , sd .Scope ),
1188
1191
SrcRef : protoBufGoFullTypeRef (e .StreamingRequest , sd .PkgName , sd .Scope ),
1189
1192
TgtName : svcCtx .Scope .Name (e .MethodExpr .StreamingPayload , svcCtx .Pkg (e .MethodExpr .StreamingPayload ), svcCtx .Pointer , svcCtx .UseDefault ),
1190
1193
TgtRef : recvRef ,
1191
- Init : buildInitData (e .StreamingRequest , e .MethodExpr .StreamingPayload , "v" , "spayload" , svcCtx , false , svr , sd ),
1194
+ Init : buildInitData (e .StreamingRequest , e .MethodExpr .StreamingPayload , "v" , "spayload" , svcCtx , false , svr , true , sd ),
1192
1195
Validation : addValidation (e .StreamingRequest , "stream" , sd , true ),
1193
1196
}
1194
1197
}
@@ -1201,33 +1204,33 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea
1201
1204
if e .MethodExpr .StreamingPayload .Type != expr .Empty {
1202
1205
sendName = md .ClientStream .SendName
1203
1206
sendRef = svcCtx .Scope .Ref (e .MethodExpr .StreamingPayload , svcCtx .Pkg (e .MethodExpr .StreamingPayload ))
1204
- sendType = & ConvertData {
1207
+ sendConvert = & ConvertData {
1205
1208
SrcName : svcCtx .Scope .Name (e .MethodExpr .StreamingPayload , svcCtx .Pkg (e .MethodExpr .StreamingPayload ), svcCtx .Pointer , svcCtx .UseDefault ),
1206
1209
SrcRef : sendRef ,
1207
1210
TgtName : protoBufGoFullTypeName (e .StreamingRequest , sd .PkgName , sd .Scope ),
1208
1211
TgtRef : protoBufGoFullTypeRef (e .StreamingRequest , sd .PkgName , sd .Scope ),
1209
- Init : buildInitData (e .MethodExpr .StreamingPayload , e .StreamingRequest , "spayload" , "v" , svcCtx , true , svr , sd ),
1212
+ Init : buildInitData (e .MethodExpr .StreamingPayload , e .StreamingRequest , "spayload" , "v" , svcCtx , true , svr , true , sd ),
1210
1213
}
1211
1214
}
1212
1215
if e .MethodExpr .Result .Type != expr .Empty {
1213
1216
recvName = md .ClientStream .RecvName
1214
1217
recvRef = ed .ResultRef
1215
- recvType = & ConvertData {
1218
+ recvConvert = & ConvertData {
1216
1219
SrcName : protoBufGoFullTypeName (e .Response .Message , sd .PkgName , sd .Scope ),
1217
1220
SrcRef : protoBufGoFullTypeRef (e .Response .Message , sd .PkgName , sd .Scope ),
1218
1221
TgtName : resCtx .Scope .Name (result , resCtx .Pkg (result ), resCtx .Pointer , resCtx .UseDefault ),
1219
1222
TgtRef : resCtx .Scope .Ref (result , resCtx .Pkg (result )),
1220
- Init : buildInitData (e .Response .Message , result , "v" , resVar , resCtx , false , svr , sd ),
1223
+ Init : buildInitData (e .Response .Message , result , "v" , resVar , resCtx , false , svr , true , sd ),
1221
1224
Validation : addValidation (e .Response .Message , "stream" , sd , false ),
1222
1225
}
1223
1226
}
1224
1227
mustClose = md .ClientStream .MustClose
1225
1228
}
1226
- if sendType != nil {
1227
- sendDesc = fmt .Sprintf ("%s streams instances of %q to the %q endpoint gRPC stream." , sendName , sendType .TgtName , md .Name )
1229
+ if sendConvert != nil {
1230
+ sendDesc = fmt .Sprintf ("%s streams instances of %q to the %q endpoint gRPC stream." , sendName , sendConvert .TgtName , md .Name )
1228
1231
}
1229
- if recvType != nil {
1230
- recvDesc = fmt .Sprintf ("%s reads instances of %q from the %q endpoint gRPC stream." , recvName , recvType .SrcName , md .Name )
1232
+ if recvConvert != nil {
1233
+ recvDesc = fmt .Sprintf ("%s reads instances of %q from the %q endpoint gRPC stream." , recvName , recvConvert .SrcName , md .Name )
1231
1234
}
1232
1235
}
1233
1236
return & StreamData {
@@ -1239,11 +1242,11 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea
1239
1242
SendName : sendName ,
1240
1243
SendDesc : sendDesc ,
1241
1244
SendRef : sendRef ,
1242
- SendConvert : sendType ,
1245
+ SendConvert : sendConvert ,
1243
1246
RecvName : recvName ,
1244
1247
RecvDesc : recvDesc ,
1245
1248
RecvRef : recvRef ,
1246
- RecvConvert : recvType ,
1249
+ RecvConvert : recvConvert ,
1247
1250
MustClose : mustClose ,
1248
1251
}
1249
1252
}
0 commit comments