Google Cloud Endpoints (ESP) gRPC transcoding to camel case

8/28/2019

I have deployed a gRPC server using Google Cloud Endpoints / ESP, following the instructions here:

https://cloud.google.com/endpoints/docs/grpc/get-started-kubernetes-engine

In my proto file, my fields are named in snake_case, following the Protocol Buffers naming conventions (https://developers.google.com/protocol-buffers/docs/style#message-and-field-names), as below:

message MyMessage {
  string my_field = 1;
}

When deploying to Cloud Endpoints, the field names are converted to camelCase. So if I call the API using the HTTP endpoint, the JSON response looks like this:

{
  "myField":"field value"
}

If I call the service using a GRPC client (Node.js), the response object is returned in the original format:

{
  "my_field":"field value"
}

The field names are also converted to camel case in the Cloud Endpoints Developer Portal documentation.

I'd prefer to use snake case for both GRPC and HTTP clients as I'm replacing an existing API. If I can prevent the field names from being converted, I can basically just switch the backend over to the new service without any changes to the client side.

Is there a way to force ESP to use the camel case field names when transcoding to HTTP/JSON?

-- glv19
google-cloud-endpoints
google-cloud-platform
google-kubernetes-engine
grpc
kubernetes

2 Answers

8/30/2019

Unfortunately, there is not an easy way for that. I just filed an enhancement issue for this feature request.

We will try to allocate resource to get it in.

-- Wayne Zhang
Source: StackOverflow

2/11/2020

I'm deploy my grpc application in to k8s with ESP, with the config below it will transcoding the protobuf response to snake case instead of camel case

- name: esp
    image: gcr.io/endpoints-release/endpoints-runtime:1
    imagePullPolicy: Always
    args: [
      "--http_port=9000",
      "--backend=grpc://127.0.0.1:8080",
      "--service=xxxxxx",
      "--version=xxxxxx",
      "--transcoding_preserve_proto_field_names",
      "--transcoding_always_print_primitive_fields"
    ]
    ports:
    - name: http
      containerPort: 9000
-- Ivan Li
Source: StackOverflow