MCPcopy Create free account
hub / github.com/goadesign/goa / validatePkgPath

Method validatePkgPath

expr/attribute.go:305–336  ·  view source on GitHub ↗
(pkgPath string, t DataType)

Source from the content-addressed store, hash-verified

303}
304
305func (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.

Callers 1

ValidateMethod · 0.95

Calls 8

AsArrayFunction · 0.85
AsMapFunction · 0.85
AsUnionFunction · 0.85
AddMethod · 0.80
AttributeMethod · 0.65
NameMethod · 0.65
AddMetaMethod · 0.65
MergeMethod · 0.45

Tested by

no test coverage detected