Skip to content

Commit 0e92114

Browse files
authored
Merge pull request #3667 from goadesign/fix/interceptor_pkg_path
Properly handle interceptor types in custom packages
2 parents f3646e1 + 83af86e commit 0e92114

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

codegen/service/interceptors_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,34 @@ func TestCollectAttributes(t *testing.T) {
181181
},
182182
want: []*AttributeData{nil},
183183
},
184+
{
185+
name: "user-type-with-package",
186+
attrNames: &expr.AttributeExpr{
187+
Type: &expr.Object{
188+
{Name: "user", Attribute: &expr.AttributeExpr{Type: expr.String}},
189+
},
190+
},
191+
parent: &expr.AttributeExpr{
192+
Type: &expr.Object{
193+
{Name: "user", Attribute: &expr.AttributeExpr{
194+
Type: &expr.UserTypeExpr{
195+
AttributeExpr: &expr.AttributeExpr{
196+
Type: &expr.Object{
197+
{Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}},
198+
},
199+
Meta: map[string][]string{
200+
"struct:pkg:path": {"goa.design/goa/example/user"},
201+
},
202+
},
203+
TypeName: "User",
204+
},
205+
}},
206+
},
207+
},
208+
want: []*AttributeData{
209+
{Name: "User", TypeRef: "*user.User", Pointer: false},
210+
},
211+
},
184212
}
185213

186214
for _, tc := range cases {

codegen/service/service_data.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,13 @@ func collectAttributes(attrNames, parent *expr.AttributeExpr, scope *codegen.Nam
14761476
if parentAttr == nil {
14771477
continue
14781478
}
1479+
var pkg string
1480+
if loc := codegen.UserTypeLocation(parentAttr.Type); loc != nil {
1481+
pkg = loc.PackageName()
1482+
}
14791483
data[i] = &AttributeData{
14801484
Name: codegen.Goify(nat.Name, true),
1481-
TypeRef: scope.GoTypeRef(parentAttr),
1485+
TypeRef: scope.GoFullTypeRef(parentAttr, pkg),
14821486
Pointer: parent.IsPrimitivePointer(nat.Name, true),
14831487
}
14841488
}

0 commit comments

Comments
 (0)