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

Function IsCompatible

codegen/transformer.go:120–153  ·  view source on GitHub ↗

IsCompatible returns an error if a and b are not both objects, both arrays, both maps, both unions or one union and one object. actx and bctx are used to build the error message if any.

(a, b expr.DataType, actx, bctx string)

Source from the content-addressed store, hash-verified

118// both maps, both unions or one union and one object. actx and bctx are used
119// to build the error message if any.
120func IsCompatible(a, b expr.DataType, actx, bctx string) error {
121 switch {
122 case expr.IsObject(a):
123 if !expr.IsObject(b) && !expr.IsUnion(b) {
124 return fmt.Errorf("%s is an object but %s type is %s", actx, bctx, b.Name())
125 }
126 case expr.IsArray(a):
127 if !expr.IsArray(b) {
128 return fmt.Errorf("%s is an array but %s type is %s", actx, bctx, b.Name())
129 }
130 case expr.IsMap(a):
131 if !expr.IsMap(b) {
132 return fmt.Errorf("%s is a hash but %s type is %s", actx, bctx, b.Name())
133 }
134 case expr.IsUnion(a):
135 if !expr.IsUnion(b) && !expr.IsObject(b) {
136 return fmt.Errorf("%s is a union but %s type is %s", actx, bctx, b.Name())
137 }
138 default:
139 aUT, isAUT := a.(expr.UserType)
140 bUT, isBUT := b.(expr.UserType)
141 switch {
142 case isAUT && isBUT:
143 return IsCompatible(aUT.Attribute().Type, bUT.Attribute().Type, actx, bctx)
144 case isAUT:
145 return IsCompatible(aUT.Attribute().Type, b, actx, bctx)
146 case isBUT:
147 return IsCompatible(a, bUT.Attribute().Type, actx, bctx)
148 case a.Kind() != b.Kind():
149 return fmt.Errorf("%s is a %s but %s type is %s", actx, a.Name(), bctx, b.Name())
150 }
151 }
152 return nil
153}
154
155// AppendHelpers takes care of only appending helper functions from newH that
156// are not already in oldH.

Callers 14

transformAttributeFunction · 0.92
transformObjectFunction · 0.92
transformArrayFunction · 0.92
transformMapFunction · 0.92
transformUnionToProtoFunction · 0.92
transformUnionFromProtoFunction · 0.92
collectHelpersFunction · 0.92
transformAttributeFunction · 0.85
transformPrimitiveFunction · 0.85
transformObjectFunction · 0.85
transformArrayFunction · 0.85

Calls 7

IsObjectFunction · 0.92
IsUnionFunction · 0.92
IsArrayFunction · 0.92
IsMapFunction · 0.92
NameMethod · 0.65
AttributeMethod · 0.65
KindMethod · 0.65

Tested by

no test coverage detected