Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Address update_mask Limitations in AIP-134 with Dedicated Update Objects or New Field Behaviors #1481

Open
woshizhicainiaoluguo opened this issue Feb 21, 2025 · 0 comments

Comments

@woshizhicainiaoluguo
Copy link

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

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant