MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / resolveFieldPath

Method resolveFieldPath

internal/descriptor/services.go:319–351  ·  view source on GitHub ↗

resolveFieldPath resolves "path" into a list of fieldDescriptor, starting from "msg".

(msg *Message, path string, isPathParam bool)

Source from the content-addressed store, hash-verified

317
318// resolveFieldPath resolves "path" into a list of fieldDescriptor, starting from "msg".
319func (r *Registry) resolveFieldPath(msg *Message, path string, isPathParam bool) ([]FieldPathComponent, error) {
320 if path == "" {
321 return nil, nil
322 }
323
324 root := msg
325 var result []FieldPathComponent
326 for i, c := range strings.Split(path, ".") {
327 if i > 0 {
328 f := result[i-1].Target
329 switch f.GetType() {
330 case descriptorpb.FieldDescriptorProto_TYPE_MESSAGE, descriptorpb.FieldDescriptorProto_TYPE_GROUP:
331 var err error
332 msg, err = r.LookupMsg(msg.FQMN(), f.GetTypeName())
333 if err != nil {
334 return nil, err
335 }
336 default:
337 return nil, fmt.Errorf("not an aggregate type: %s in %s", f.GetName(), path)
338 }
339 }
340
341 if grpclog.V(2) {
342 grpclog.Infof("Lookup %s in %s", c, msg.FQMN())
343 }
344 f := lookupField(msg, c)
345 if f == nil {
346 return nil, fmt.Errorf("no field %q found in %s", path, root.GetName())
347 }
348 result = append(result, FieldPathComponent{Name: c, Target: f})
349 }
350 return result, nil
351}

Callers 4

TestResolveFieldPathFunction · 0.95
newParamMethod · 0.95
newBodyMethod · 0.95
newResponseMethod · 0.95

Calls 5

LookupMsgMethod · 0.95
lookupFieldFunction · 0.85
GetTypeMethod · 0.45
FQMNMethod · 0.45
GetNameMethod · 0.45

Tested by 1

TestResolveFieldPathFunction · 0.76