metaverse / truss

Truss helps you build go-kit microservices without having to worry about writing or maintaining boilerplate code.
Other
736 stars 144 forks source link

Formatting error when generating a rpc with http option and google.protobuf.Timestamp in request struct #328

Closed almartino closed 3 years ago

almartino commented 3 years ago

As from title I'm getting an error when I'm trying to generate this proto:

syntax = "proto3";

package proto;

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

service Patient {

  rpc FindByID (PatientByIDRequest) returns (PatientResponse) {
    option (google.api.http) = {
      get: "/patient/{ID}"
    };
  }

  rpc CreatePatient (CreatePatientReq) returns (PatientResponse) {
    option (google.api.http) = {
      post: "/patient"
    };
  }
}

message PatientByIDRequest {
  // Identifier is the string to search a consultation by id
  string ID = 1;
}

message PatientResponse {
  string ID = 1 ;
  string ClinicianID = 2;
  string Name = 3;
  string Surname = 4;
  string Alias = 5;
  string Email = 6;
  Sex Sex = 7;
  google.protobuf.Timestamp BirthDate = 8;
}

message CreatePatientReq {
  Sex Sex = 1;
  string Alias = 2;
  string Name = 3;
  string Surname = 4;
  string Email = 5;
  google.protobuf.Timestamp BirthDate = 6;
}

enum Sex {
  MALE = 0;
  FEMALE = 1;
  UNSPECIFIED = 2;
}

the command output says:

WARN[0000] Code formatting error, generated service will not build, outputting unformatted code error="257:1: expected statement, found '%'"

And in the http transport, for the generated function func DecodeHTTPCreatePatientZeroRequest I get this line:

%!(EXTRA string=BirthDateCreatePatient, string=BirthDateCreatePatientStr)

Executed command:

truss proto/patient.proto --svcout ./patient

Generated file

transport_http.go.generated.txt

Notes

If I remove BirthDate from CreatePatientReq the generation is done correctly and the problem is clearly on rpc CreatePatient (CreatePatientReq) part.

zaquestion commented 3 years ago

@almartino Hi I think you're hitting this because truss doesn't realize it needs to put your create fields in the body, updating your create rpc to (below) should address

  rpc CreatePatient (CreatePatientReq) returns (PatientResponse) {
    option (google.api.http) = {
      post: "/patient"
      body: "*"
    };
  }
almartino commented 3 years ago

@almartino Hi I think you're hitting this because truss doesn't realize it needs to put your create fields in the body, updating your create rpc to (below) should address

  rpc CreatePatient (CreatePatientReq) returns (PatientResponse) {
    option (google.api.http) = {
      post: "/patient"
      body: "*"
    };
  }

Hi @zaquestion thanks for the reply, unfortunately I don't use anymore truss, so I'm not able to verify your suggestion.