Skip to content

gRPC HTTP body mapping works incorrectly #325

Description

@chebykinn

Hi, I've noticed some inconsistency with grpc http transcoding.

Here's how to reproduce it:

  1. Take example proto schema from google doc (https://cloud.google.com/endpoints/docs/grpc/transcoding#map_a_create_method)
    Full schema:
syntax = "proto3";

package shelf;

import "github.com/metaverse/truss/deftree/googlethirdparty/annotations.proto";

service Shelfs {

  // Creates a new shelf in the bookstore.
  rpc CreateShelf(CreateShelfRequest) returns (Shelf) {
    // Client example:
    //   curl -d '{"theme":"Music"}' http://DOMAIN_NAME/v1/shelves
    option (google.api.http) = {
      post: "/v1/shelves"
      body: "shelf"
    };
  }
}

// Request message for CreateShelf method.
message CreateShelfRequest {
  // The shelf resource to create.
  Shelf shelf = 1;
}

// A shelf resource.
message Shelf {
  // A unique shelf id.
  int64 id = 1;
  // A theme of the shelf (fiction, poetry, etc).
  string theme = 2;
}
  1. Generate and run server
  2. Add debug printing of Shelf field to CreateShelf:
func (s shelfsService) CreateShelf(ctx context.Context, in *pb.CreateShelfRequest) (*pb.Shelf, error) {
	fmt.Printf("in: %v\n", in.Shelf)
	var resp pb.Shelf
	return &resp, nil
}
  1. Make curl request as suggested in the example: curl -d '{"theme":"Music"}' 'http://localhost:5050/v1/shelves'
    The server does not set the Shelf field:
2021/02/07 00:16:57 transport gRPC addr :5040
2021/02/07 00:16:57 transport debug addr :5060
2021/02/07 00:16:57 transport HTTP addr :5050
in: <nil>

If you wrap the body with the shelf object, like curl -d '{"shelf": {"theme":"Music"}}' 'http://localhost:5050/v1/shelves'
the field will be correctly set to theme:"Music"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions