| 303 | } |
| 304 | |
| 305 | func (a *AttributeExpr) validatePkgPath(pkgPath string, t DataType) *eval.ValidationErrors { |
| 306 | verr := new(eval.ValidationErrors) |
| 307 | if ar := AsArray(t); ar != nil { |
| 308 | verr.Merge(a.validatePkgPath(pkgPath, ar.ElemType.Type)) |
| 309 | } |
| 310 | if mp := AsMap(t); mp != nil { |
| 311 | verr.Merge(a.validatePkgPath(pkgPath, mp.KeyType.Type)) |
| 312 | verr.Merge(a.validatePkgPath(pkgPath, mp.ElemType.Type)) |
| 313 | } |
| 314 | if u := AsUnion(t); u != nil { |
| 315 | for _, nat := range u.Values { |
| 316 | if nat == nil || nat.Attribute == nil { |
| 317 | continue |
| 318 | } |
| 319 | verr.Merge(a.validatePkgPath(pkgPath, nat.Attribute.Type)) |
| 320 | } |
| 321 | } |
| 322 | if ut, ok := t.(UserType); pkgPath != "" && ok { |
| 323 | // This check ensures we error if a sub-type has a different custom package type set |
| 324 | // or if two user types have different custom packages but share a sub-type (field that's a user type) |
| 325 | if ut.Attribute().Meta != nil && |
| 326 | ut.Attribute().Meta["struct:pkg:path"] != nil && |
| 327 | ut.Attribute().Meta["struct:pkg:path"][0] != pkgPath { |
| 328 | verr.Add(a, "type \"%s\" has conflicting packages %s and %s", ut.Name(), ut.Attribute().Meta["struct:pkg:path"][0], pkgPath) |
| 329 | } |
| 330 | ut.Attribute().AddMeta("struct:pkg:path", pkgPath) |
| 331 | } |
| 332 | if len(verr.Errors) > 0 { |
| 333 | return verr |
| 334 | } |
| 335 | return nil |
| 336 | } |
| 337 | |
| 338 | // Finalize merges base and reference type attributes and finalizes the Type |
| 339 | // attribute. |