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

Function hashAttribute

http/codegen/openapi/v3/types.go:406–471  ·  view source on GitHub ↗
(att *expr.AttributeExpr, h hash.Hash64, seen map[string]*uint64)

Source from the content-addressed store, hash-verified

404}
405
406func hashAttribute(att *expr.AttributeExpr, h hash.Hash64, seen map[string]*uint64) *uint64 {
407 t := att.Type
408 if h, ok := seen[t.Hash()]; ok {
409 return h
410 }
411 var res *uint64
412 {
413 var tmp uint64
414 res = &tmp
415 }
416 seen[t.Hash()] = res
417
418 hv := hashValidation(att.Validation, h)
419 switch t.Kind() {
420 case expr.ObjectKind:
421 o := expr.AsObject(t)
422 for _, m := range *o {
423 if !openapi.MustGenerate(m.Attribute.Meta) {
424 continue
425 }
426 kh := hashString(m.Name, h)
427 vh := hashAttribute(m.Attribute, h, seen)
428 *res ^= orderedHash(kh, *vh, h)
429 }
430 if hv != 0 {
431 *res = orderedHash(*res, hv, h)
432 }
433
434 case expr.ArrayKind:
435 kh := hashString("[]", h)
436 vh := hashAttribute(expr.AsArray(t).ElemType, h, seen)
437 *res = orderedHash(kh, *vh, h)
438 if hv != 0 {
439 *res = orderedHash(*res, hv, h)
440 }
441
442 case expr.MapKind:
443 m := expr.AsMap(t)
444 kh := hashAttribute(m.KeyType, h, seen)
445 vh := hashAttribute(m.ElemType, h, seen)
446 *res = orderedHash(*kh, *vh, h)
447 if hv != 0 {
448 *res = orderedHash(*res, hv, h)
449 }
450
451 case expr.UserTypeKind:
452 *res = *hashAttribute(t.(expr.UserType).Attribute(), h, seen)
453
454 case expr.ResultTypeKind:
455 // The identifier specified in the design for result types should drive
456 // the computation of the hash.
457 rt := t.(*expr.ResultTypeExpr)
458 *res = hashString(rt.Identifier, h)
459 if view, ok := rt.Meta.Last(expr.ViewMetaKey); ok {
460 *res = orderedHash(*res, hashString(view, h), h)
461 }
462
463 default: // Primitives or Any

Callers 1

hashAttributeMethod · 0.85

Calls 12

AsObjectFunction · 0.92
MustGenerateFunction · 0.92
AsArrayFunction · 0.92
AsMapFunction · 0.92
hashValidationFunction · 0.85
hashStringFunction · 0.85
orderedHashFunction · 0.85
LastMethod · 0.80
HashMethod · 0.65
KindMethod · 0.65
AttributeMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected