-
Notifications
You must be signed in to change notification settings - Fork 624
Description
Describe the problem you are trying to solve.
In the current proto specification, AIP-203 defines several google.api.field_behavior
options, including required, optional
, and output_only
.
According to AIP-133 and AIP-134, the same object (e.g., Book book) should be used for both create and update requests, with the update_mask specifying the fields to be updated in the update interface.
Then, since the update_mask uses a string format that cannot be associated with the Book object, this makes it impossible to use update_mask to indicate specific object properties.
This inevitably leads to situations where certain properties are required fields in the create API but remain required in the update API, while not actually being updatable object properties in the update_mask.
Describe the solution you'd like
It is recommended to design new specifications for the AIP-134 documentation, such as defining a new BookUpdate object to replace the Book object. Alternatively, new behaviors like "required in update" could be defined refer to protocolbuffers/protobuf#20410
Proto Detail
syntax = "proto3";
package book;
import "google/protobuf/field_mask.proto";
import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
service BookService {
rpc CreateBook(CreateBookRequest) returns (Book) {
option (google.api.http) = {
post: "/v1/test/books/{id}"
body: "book"
};
}
rpc UpdateBook(UpdateBookRequest) returns (Book) {
option (google.api.http) = {
patch: "/v1/test/books/{id}"
body: "book"
};
option (google.api.method_signature) = "book,update_mask";
}
}
message CreateBookRequest {
string id = 1 [(google.api.field_behavior) = REQUIRED];
// The book to create.
Book book = 2 [(google.api.field_behavior) = REQUIRED];
}
message UpdateBookRequest {
string id = 1 [(google.api.field_behavior) = REQUIRED];
Book book = 2 [(google.api.field_behavior) = REQUIRED];
// The list of fields to update.
google.protobuf.FieldMask update_mask = 3[(google.api.field_behavior) = REQUIRED];
}
message Book {
string name = 1 [(google.api.field_behavior) = REQUIRED];
string title = 2;
string author = 3;
int32 rating = 4;
}
Result