@@ -26,18 +26,23 @@ func TestGoTypeDef(t *testing.T) {
26
26
{"IntField" , & expr.AttributeExpr {Type : expr .Int , DefaultValue : 1 }},
27
27
{"StringField" , & expr.AttributeExpr {Type : expr .String , DefaultValue : "foo" }},
28
28
}}
29
- ut = & expr.UserTypeExpr {AttributeExpr : & expr.AttributeExpr {Type : expr .Boolean }, TypeName : "UserType" }
30
- rt = & expr.ResultTypeExpr {UserTypeExpr : & expr.UserTypeExpr {AttributeExpr : & expr.AttributeExpr {Type : expr .Boolean }, TypeName : "ResultType" }, Identifier : "application/vnd.goa.example" , Views : nil }
31
- userType = & expr.AttributeExpr {Type : ut }
32
- resultType = & expr.AttributeExpr {Type : rt }
33
- mixedObj = & expr.AttributeExpr {
29
+ ut = & expr.UserTypeExpr {AttributeExpr : & expr.AttributeExpr {Type : expr .Boolean }, TypeName : "UserType" }
30
+ rt = & expr.ResultTypeExpr {UserTypeExpr : & expr.UserTypeExpr {AttributeExpr : & expr.AttributeExpr {Type : expr .Boolean }, TypeName : "ResultType" }, Identifier : "application/vnd.goa.example" , Views : nil }
31
+ userType = & expr.AttributeExpr {Type : ut }
32
+ resultType = & expr.AttributeExpr {Type : rt }
33
+ stringMetaType = expr.MetaExpr {"struct:field:type" : []string {"string" }}
34
+ jsonWithImportMetaType = expr.MetaExpr {"struct:field:type" : []string {"json.RawMessage" , "encoding/json" }}
35
+ jsonWithRenameMetaType = expr.MetaExpr {"struct:field:type" : []string {"jason.RawMessage" , "encoding/json" , "jason" }}
36
+ mixedObj = & expr.AttributeExpr {
34
37
Type : & expr.Object {
35
38
{"IntField" , & expr.AttributeExpr {Type : expr .Int }},
36
39
{"ArrayField" , simpleArray },
37
40
{"MapField" , simpleMap },
38
41
{"UserTypeField" , userType },
42
+ {"MetaTypeField" , & expr.AttributeExpr {Type : expr .Int , Meta : jsonWithImportMetaType }},
43
+ {"QualifiedMetaTypeField" , & expr.AttributeExpr {Type : expr .Int , Meta : jsonWithRenameMetaType }},
39
44
},
40
- Validation : & expr.ValidationExpr {Required : []string {"IntField" , "ArrayField" , "MapField" , "UserTypeField" }}}
45
+ Validation : & expr.ValidationExpr {Required : []string {"IntField" , "ArrayField" , "MapField" , "UserTypeField" , "MetaTypeField" , "QualifiedMetaTypeField" }}}
41
46
)
42
47
cases := map [string ]struct {
43
48
att * expr.AttributeExpr
@@ -66,8 +71,12 @@ func TestGoTypeDef(t *testing.T) {
66
71
"Object" : {requiredObj , false , true , "struct {\n \t IntField int\n \t StringField string\n }" },
67
72
"ObjDefault" : {defaultObj , false , true , "struct {\n \t IntField int\n \t StringField string\n }" },
68
73
"ObjDefaultNoDef" : {defaultObj , false , false , "struct {\n \t IntField *int\n \t StringField *string\n }" },
69
- "ObjMixed" : {mixedObj , false , true , "struct {\n \t IntField int\n \t ArrayField []bool\n \t MapField map[int]string\n \t UserTypeField UserType\n }" },
70
- "ObjMixedPointer" : {mixedObj , true , true , "struct {\n \t IntField *int\n \t ArrayField []bool\n \t MapField map[int]string\n \t UserTypeField *UserType\n }" },
74
+ "ObjMixed" : {mixedObj , false , true , "struct {\n \t IntField int\n \t ArrayField []bool\n \t MapField map[int]string\n \t UserTypeField UserType\n \t MetaTypeField json.RawMessage\n \t QualifiedMetaTypeField jason.RawMessage\n }" },
75
+ "ObjMixedPointer" : {mixedObj , true , true , "struct {\n \t IntField *int\n \t ArrayField []bool\n \t MapField map[int]string\n \t UserTypeField *UserType\n \t MetaTypeField *json.RawMessage\n \t QualifiedMetaTypeField *jason.RawMessage\n }" },
76
+
77
+ "MetaTypeSameAsDesign" : {& expr.AttributeExpr {Type : expr .String , Meta : stringMetaType }, false , true , "string" },
78
+ "MetaTypeOverrideDesign" : {& expr.AttributeExpr {Type : expr .String , Meta : jsonWithImportMetaType }, false , true , "json.RawMessage" },
79
+ "MetaTypeOverrideDesignWithQualifiedImport" : {& expr.AttributeExpr {Type : expr .String , Meta : jsonWithRenameMetaType }, false , true , "jason.RawMessage" },
71
80
}
72
81
73
82
for k , tc := range cases {
0 commit comments