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

Impossible to adhere to AIP suggestions for AIP-136 when using google.api.HttpBody and have values in request path #1207

Open
achew22 opened this issue Jul 23, 2023 · 0 comments

Comments

@achew22
Copy link
Contributor

achew22 commented Jul 23, 2023

In AIP-136, and in the associated linter entry it is suggested that the following would not be allowed:

// Incorrect.
rpc CheckoutBook(CheckoutBookRequest) returns (CheckoutBookResponse) {
  option (google.api.http) = {
    post: "/v1/{name=publishers/*/books}:checkout"
    // `body: "*"` should be included.
  };
}

I believe the implied form of CheckoutBookRequest would be something like:

message CheckoutBookRequest {
  string name = 1;
  string some_other_field = 2;
  // even more fields
}

This seems reasonable in the general case. There is, however, an edge case in the somewhat bizarre event where you're using google.api.HttpBody to provide a webhook endpoint where you can't control the caller to send you structured data. Unfortunately I can't even force JSON, I'm going to be getting application/x-www-form-urlencoded encoded data posted as the whole body. I could put it into a body: "string_field" directly, but then I would be asking the parser to infer the encoding, which feels unnecessary since there is a nice way to get the content_type. I believe this functionally is akin to HTTPOverRPC from days of old (sorry for bringing that up if you remember it). This may be considered a thing that is beyond the scope for AIP, but I believe the only correct form for using this would be:

// Possibly incorrect?
rpc HandleWebhook(HandleWebhookRequest) returns (google.api.HttpBody) {
  option (google.api.http) = {
    post: "/v1/{name=webhooks/*}:handle"
    body: "request"
  };
}

message HandleWebhookRequest {
  string name = 1;
  google.api.HttpBody request = 2;
}

Unfortunately this causes a lint error. I could then add a lint exception for api-linter: core::0136::http-body=disabled to the HandleWebhook RPC, but I want to make sure that I'm not missing something obvious.

Is this what you would expect?

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

No branches or pull requests

1 participant