Skip to content

Generated HttpJson unit tests would fail if the request contains a field name that is a Java keyword  #1652

@blakeli0

Description

@blakeli0

Given the RPC definition

  rpc UpdateCase(UpdateCaseRequest) returns (Case) {
    option (google.api.http) = {
      patch: "/v2beta/{case.name=projects/*/cases/*}"
      body: "case"
    };
    option (google.api.method_signature) = "case,update_mask";
  }

resource definition

message Case {
  option (google.api.resource) = {
    type: "cloudsupport.googleapis.com/Case"
    pattern: "projects/{project}/cases/{case}"
  };
}

and request definition

message UpdateCaseRequest {
  Case case = 1 [(google.api.field_behavior) = REQUIRED];
  google.protobuf.FieldMask update_mask = 2;
}

The generated unit tests would fail because UpdateCaseRequest contains a field with name case which is a Java keyword.

Root cause: We append a _ to the field name in generated client code, so the field name is now case_, then when we try to match it with case.name in the resource definition in generated unit tests, it would fail because we are unable to find a field with name case.
Potential fix: Unescape the field name when generating unit tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions