pettert
pettert

Reputation: 31

GRPC Repeated field does not transcode to an array as body parameter in REST API

I´m having little luck trying to send a PUT request with JSON containing an array of objects to my GRPC Server using REST. Using GRPC however it accepts an array just like expected. This is what I have defined in my proto file:

message UpdateRequest {
    repeated Data data = 1;
    int32 Id = 2;
}

message UpdateResponse {
}

message Data {
    int32 id = 1;
    string name = 2;

}

rpc Update(UpdateRequest) returns (UpdateResponse) {
    option (google.api.http) = {
       put: "/v1/data/{Id}"
       body: "*"
     };
}

This deploys successfully to GCP Endpoints but according to the GCP enpointsportal the request body is supposed to only contain a single object like:

{
    "data": {
       
    }
}

instead of an array of objects like expected:

    {
    "data": [
       {},
       {}
    ]
}

I´ve tried with replacing the "*" in the body with "data"

    rpc Update(UpdateRequest) returns (UpdateResponse) {
    option (google.api.http) = {
       put: "/v1/data/{Id}"
       body: "data"
     };
}

This also compiles, but fails when trying to deploy to GCP endpoints with the following message:

kind: ERROR message: "http: body field path 'data' must be a non-repeated message."

Any suggestions as to how I should go about solving this would be greatly appreciated.

Update: Heres the contents of my .yaml file.

type: google.api.Service
config_version: 3

name: xxx.xxx-xxx.dev

title: xxxx
apis:
  - name: x.x
  - name: x.y


backend:
  rules:
    - selector: "*"
      address: grpcs://xxx-xxx-app-xxxx-lz.a.run.app

Upvotes: 3

Views: 1745

Answers (2)

fratle
fratle

Reputation: 64

This is a known issue, according to GCP support. Here is the google issuetracker link: https://issuetracker.google.com/issues/178486575

Upvotes: 2

pettert
pettert

Reputation: 31

There seems that this is a bug in GCP endpoints portal. I´m now successfully sending update requests with arrays containing object through CURL and my frontend application, although this does not work through endpoints.

Upvotes: 0

Related Questions