Create methods: Resource response message

This rule enforces that all Create RPCs have a response message of the resource, as mandated in AIP-133.

Details

This rule looks at any message matching beginning with Create, and complains if the name of the corresponding output message does not match the name of the RPC with the prefix Create removed.

It also permits a response of google.longrunning.Operation; in this case, it checks the response_type in the google.longrunning.operation_info annotation and ensures that it corresponds to the name of the RPC with the prefix Create removed.

Examples

Standard

Incorrect code for this rule:

// Incorrect.
// Should be `Book`.
rpc CreateBook(CreateBookRequest) returns (CreateBookResponse) {
  option (google.api.http) = {
    post: "/v1/{name=publishers/*}/books"
    body: "book"
  };
}

Correct code for this rule:

// Correct.
rpc CreateBook(CreateBookRequest) returns (Book) {
  option (google.api.http) = {
    post: "/v1/{name=publishers/*}/books"
    body: "book"
  };
}

Long-running operation

Incorrect code for this rule:

// Incorrect.
rpc CreateBook(CreateBookRequest) returns (google.longrunning.Operation) {
  option (google.api.http) = {
    post: "/v1/{book.name=publishers/*}/books"
    body: "book"
  };
  option (google.longrunning.operation_info) = {
    response_type: "CreateBookResponse"  // Should be "Book".
    metadata_type: "CreateBookMetadata"
  };
}

Correct code for this rule:

// Correct.
rpc CreateBook(CreateBookRequest) returns (google.longrunning.Operation) {
  option (google.api.http) = {
    post: "/v1/{book.name=publishers/*}/books"
    body: "book"
  };
  option (google.longrunning.operation_info) = {
    response_type: "Book"
    metadata_type: "CreateBookMetadata"
  };
}

Disabling

If you need to violate this rule, use a leading comment above the method. Remember to also include an aip.dev/not-precedent comment explaining why.

// (-- api-linter: core::0133::response-message-name=disabled
//     aip.dev/not-precedent: We need to do this because reasons. --)
rpc CreateBook(CreateBookRequest) returns (CreateBookResponse) {
  option (google.api.http) = {
    post: "/v1/{name=publishers/*}/books"
    body: "book"
  };
}

If you need to violate this rule for an entire file, place the comment at the top of the file.