googleapis / api-linter

A linter for APIs defined in protocol buffers.
https://linter.aip.dev/
Apache License 2.0
582 stars 142 forks source link

AIP-121 Linter does not verify uniformness of resource across methods #1374

Closed apodznoev closed 1 month ago

apodznoev commented 5 months ago

Hello!

As of AIP-121 definition for resource-oriented design,

If the request to or the response from a standard method (or a custom method in the same service) is the resource or contains the resource, the resource schema for that resource across all methods must be the same.

However, having a mixed service defined like:

service BookService {
    rpc CreateBook(CreateBookRequest) returns (Book);

    rpc GetBook(GetBookRequest) returns (Book);

    rpc ListBooks(ListBooksRequest) returns (ListBooksResponse){
        option (google.api.method_signature) = "parent";
    }

    rpc CreateFoo(CreateFooRequest) returns (Foo);

    rpc GetFoo(GetFooRequest) returns (Foo);

    rpc ListFoos(ListFoosRequest) returns (ListFoosResponse){
        option (google.api.method_signature) = "parent";
    }
}

will be totally valid yielding no issues from AIP linter in regards to AIP-121 rules.

Expectation would be, that AIP reject such a service as violating same-resource schema.

I attached the full service definition which didn't produce any warning from AIP linter as of version v1.65.1. book_service.txt

noahdietz commented 1 month ago

Thanks for the issue!

If I'm understanding what you are suggesting, your example proto should be non-compliant b.c a single proto service contains RPCs for two different resources? If I'm tracking...

...then the proto you shared isn't actually a problem - AIP-121 isn't opinionated about RPCs being defined in Resource-specific proto services. That is to say, one proto service can contain more than one resource, and the methods for them.

noahdietz commented 1 month ago

I'm going to close this, but if I'm misunderstanding, please say as much and we can reopen.