@@ -66,14 +66,14 @@ func makeProtoBufMessage(att *expr.AttributeExpr, tname string, sd *ServiceData)
66
66
}
67
67
return att
68
68
case expr .IsPrimitive (att .Type ):
69
- wrapAttr (att , tname , sd )
69
+ wrapAttr (att , tname , true , sd )
70
70
return att
71
71
case isut :
72
72
if expr .IsArray (ut ) {
73
- wrapAttr (att , tname , sd )
73
+ wrapAttr (att , tname , false , sd )
74
74
}
75
75
case expr .IsArray (att .Type ) || expr .IsMap (att .Type ):
76
- wrapAttr (att , tname , sd )
76
+ wrapAttr (att , tname , false , sd )
77
77
case expr .IsObject (att .Type ) || expr .IsUnion (att .Type ):
78
78
att .Type = & expr.UserTypeExpr {
79
79
TypeName : tname ,
@@ -102,12 +102,12 @@ func makeProtoBufMessageR(att *expr.AttributeExpr, tname *string, sd *ServiceDat
102
102
switch {
103
103
case expr .IsArray (att .Type ):
104
104
wrapAttr (att , "ArrayOf" + tname +
105
- protoBufify (protoBufMessageDef (expr .AsArray (att .Type ).ElemType , sd ), true , true ), sd )
105
+ protoBufify (protoBufMessageDef (expr .AsArray (att .Type ).ElemType , sd ), true , true ), true , sd )
106
106
case expr .IsMap (att .Type ):
107
107
m := expr .AsMap (att .Type )
108
108
wrapAttr (att , tname + "MapOf" +
109
109
protoBufify (protoBufMessageDef (m .KeyType , sd ), true , true )+
110
- protoBufify (protoBufMessageDef (m .ElemType , sd ), true , true ), sd )
110
+ protoBufify (protoBufMessageDef (m .ElemType , sd ), true , true ), true , sd )
111
111
}
112
112
}
113
113
@@ -116,7 +116,7 @@ func makeProtoBufMessageR(att *expr.AttributeExpr, tname *string, sd *ServiceDat
116
116
return
117
117
case isut :
118
118
if expr .IsArray (ut ) {
119
- wrapAttr (ut .Attribute (), ut .Name (), sd )
119
+ wrapAttr (ut .Attribute (), ut .Name (), false , sd )
120
120
}
121
121
makeProtoBufMessageR (ut .Attribute (), tname , sd , seen )
122
122
case expr .IsArray (att .Type ):
@@ -140,9 +140,9 @@ func makeProtoBufMessageR(att *expr.AttributeExpr, tname *string, sd *ServiceDat
140
140
141
141
// wrapAttr makes the attribute type a user type by wrapping the given
142
142
// attribute into an attribute named "field".
143
- func wrapAttr (att * expr.AttributeExpr , tname string , sd * ServiceData ) {
143
+ func wrapAttr (att * expr.AttributeExpr , tname string , req bool , sd * ServiceData ) {
144
144
wrap := func (attr * expr.AttributeExpr ) * expr.AttributeExpr {
145
- return & expr.AttributeExpr {
145
+ res := & expr.AttributeExpr {
146
146
Type : & expr.Object {
147
147
& expr.NamedAttributeExpr {
148
148
Name : "field" ,
@@ -153,10 +153,13 @@ func wrapAttr(att *expr.AttributeExpr, tname string, sd *ServiceData) {
153
153
},
154
154
},
155
155
},
156
- Validation : & expr.ValidationExpr {
156
+ }
157
+ if req {
158
+ res .Validation = & expr.ValidationExpr {
157
159
Required : []string {"field" },
158
- },
160
+ }
159
161
}
162
+ return res
160
163
}
161
164
switch dt := att .Type .(type ) {
162
165
case expr.UserType :
0 commit comments