Populating FieldMask in PATCH Request

686 views
Skip to first unread message

free...@google.com

unread,
Aug 21, 2020, 10:36:37 AM8/21/20
to Google Cloud Endpoints
We have a HTTP-PATCH-annotated RPC method:

rpc Baz(Bar) returns (Qux) {
  option (google.api.http) = {
    patch: "/v1/{foo.name=foos/*}"
    body: "foo"
  };
  option (google.api.method_signature) = "foo,update_mask";
}

message Bar {
  Foo foo = 1 [(google.api.field_behavior) = REQUIRED];
  google.protobuf.FieldMask update_mask = 2;
}

message Foo {
  string name = 1;
}

The PATCH body accepts a Foo message, rather than Bar, in accordance to this Google API style guide https://google.aip.dev/134#guidance.

The following payload is seemingly dropped/ignored because the method expects a Foo, rather than a Bar message (which contains foo):

curl -X PATCH http://adsapiv1-stg.wazestg.com/v1/foos/1234?key=$API_KEY -data '{"updateMask": "title", "foo": {"name": "my first foo message"}}'

The following payload is sent to our backend, but our question is: how do we pass in the updateMask field? Should endpoints be auto-populating the update_mask field somehow? 

curl -X PATCH http://adsapiv1-stg.wazestg.com/v1/foos/1234?key=$API_KEY -data '{"foo": {"name": "my first foo message"}}'

We are attempting changing the body to * instead of foo, as a workaround, but how do we make sense of the Google API style guidance?  

rpc Baz(Bar) returns (Qux) {
  option (google.api.http) = {
    patch: "/v1/{foo.name=foos/*}"
    body: "*"
  };
  option (google.api.method_signature) = "foo,update_mask";
}

Thank you,

Tuan


Jilin Xia

unread,
Aug 21, 2020, 12:36:54 PM8/21/20
to free...@google.com, Google Cloud Endpoints
Hi, Tuan:

    1,  Could you please check what you get for the first call?  Trying to get more details, maybe add "curl -v", or set flag --enable_debug  for the endpoints
It doesn't make sense that the payload is dropped/ignored. If JSON input doesn't match the protobuf, an Invalid Arg error should be returned.

         By the way, I think your call should be:
   
  curl -X PATCH http://adsapiv1-stg.wazestg.com/v1/foos/1234?key=$API_KEY -data '{"updateMask": "foo.name", "foo": {"name": "my first foo message"}}'

       since you are updating the name of the foo. There is no 'title' field in the request body.

    2,  Cloud Endpoints doesn't auto generate field masks right now. You have to construct it by yourself.

Regards
Jilin

--
You received this message because you are subscribed to the Google Groups "Google Cloud Endpoints" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-endpoints/d51a3ad4-4d65-4b03-a9d2-662c415614f7n%40googlegroups.com.


--

Jilin Xia

jili...@google.com

Senior Software Engineer


Reply all
Reply to author
Forward
0 new messages