aip-dev / google.aip.dev

API Improvement Proposals. https://aip.dev/
Other
1.08k stars 495 forks source link

[AIP-144] Creation with complex resource associations (Or custom request AddAuthorRequest) #1390

Open yji-github opened 2 months ago

yji-github commented 2 months ago

According to AIP-124 and AIP-144: we expect add association for book author like:

// From AIP-124
message BookAuthor {
  // The resource pattern for BookAuthor indicates that Book is the
  // canonical parent.
  option (google.api.resource) = {
    type: "library.googleapis.com/BookAuthor"
    pattern: "publishers/{publisher}/books/{book}/authors/{book_author}"
  };

  // The resource name for the book-author association.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // The resource name for the author.
  string author = 2 [(google.api.resource_reference) = {
    type: "library.googleapis.com/Author"
  }];

  // Other fields...
}
// From AIP-144
rpc AddAuthor(AddAuthorRequest) returns (Book) {
  option (google.api.http) = {
    post: "/v1/{book=publishers/*/books/*}:addAuthor"
    body: "*"
  };
}

message AddAuthorRequest {
  // The name of the book to add an author to.
  string book = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference).type = "library.googleapis.com/Book"
  ];

  string author = 2 [(google.api.field_behavior) = REQUIRED];
}

I have two questions:

  1. it seems not quite clear how to include message BookAuthor as in AddAuthorRequest. Should it be like

    message AddAuthorRequest {
    // The name of the book to add an author to.
    string book = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference).type = "library.googleapis.com/Book"
    ];
    
    string author = 2 [(google.api.field_behavior) = REQUIRED];
    
    BookAuthor book_author = 3 [(google.api.field_behavior) = REQUIRED]; // newly added
    }
  2. If there is no id for book_author, should this pattern be

    • pattern: "publishers/{publisher}/books/{book}/authors/{book_author}", or
    • pattern: "publishers/{publisher}/books/{book}/authors/{author}"