api-linter icon indicating copy to clipboard operation
api-linter copied to clipboard

Verify that resource referenced in request field has pattern(s) present in google.api.http annotations

Open noahdietz opened this issue 3 years ago • 1 comments

When an RPC has a resource name in its request, the name is often used as part of the HTTP binding. For example:

service FooService {
  rpc GetFoo(GetFooRequest) returns (Foo) {
    option (google.api.http) = {
      get: "v1/{name=projects/*/foos/*}"
    };
  };
}

message GetFooRequest {
  // Format: projects/{project}/foos/{foo}
  string name = 1 [(google.api.resource_reference).type = "foo.googleapis.com/Foo"];
}

message Foo {
  option (google.api.resource) = {
    type: "foo.googleapis.com/Foo"
    pattern: "projects/{project}/foos/{foo}"
  };

  string name = 1;
}

Here, GetFooRequest.name field is used to populate a section of the HTTP Request path. That field references a resource definition that defines a resource name pattern. The linter should enforce that the expected pattern(s) present in the google.api.http path can be found in the google.api.resource annotation for the referenced resource.

noahdietz avatar May 13 '22 16:05 noahdietz

@acamadeo all yours!

noahdietz avatar Sep 14 '22 16:09 noahdietz

Fixed by #1045. Will be in the next release. Closing this as the other case of child_type references in the google.api.http annotation is covered by #1047. Thank you @acamadeo

noahdietz avatar Nov 30 '22 18:11 noahdietz