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

Method newParam

internal/descriptor/services.go:248–277  ·  view source on GitHub ↗
(meth *Method, path string)

Source from the content-addressed store, hash-verified

246}
247
248func (r *Registry) newParam(meth *Method, path string) (Parameter, error) {
249 msg := meth.RequestType
250 fields, err := r.resolveFieldPath(msg, path, true)
251 if err != nil {
252 return Parameter{}, err
253 }
254 l := len(fields)
255 if l == 0 {
256 return Parameter{}, fmt.Errorf("invalid field access list for %s", path)
257 }
258 target := fields[l-1].Target
259 switch target.GetType() {
260 case descriptorpb.FieldDescriptorProto_TYPE_MESSAGE, descriptorpb.FieldDescriptorProto_TYPE_GROUP:
261 if grpclog.V(2) {
262 grpclog.Infoln("found aggregate type:", target, target.TypeName)
263 }
264 if IsWellKnownType(*target.TypeName) {
265 if grpclog.V(2) {
266 grpclog.Infoln("found well known aggregate type:", target)
267 }
268 } else {
269 return Parameter{}, fmt.Errorf("%s.%s: %s is a protobuf message type. Protobuf message types cannot be used as path parameters, use a scalar value type (such as string) instead", meth.Service.GetName(), meth.GetName(), path)
270 }
271 }
272 return Parameter{
273 FieldPath: FieldPath(fields),
274 Method: meth,
275 Target: fields[l-1].Target,
276 }, nil
277}
278
279func (r *Registry) newBody(meth *Method, path string) (*Body, error) {
280 switch path {

Callers 1

newMethodMethod · 0.95

Calls 5

resolveFieldPathMethod · 0.95
IsWellKnownTypeFunction · 0.85
FieldPathTypeAlias · 0.85
GetTypeMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected