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

surface google.api.resource patterns in documentation #1372

Open
codyoss opened this issue Jul 10, 2023 · 2 comments
Open

surface google.api.resource patterns in documentation #1372

codyoss opened this issue Jul 10, 2023 · 2 comments
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@codyoss
Copy link
Member

codyoss commented Jul 10, 2023

A common issue people run into when using our clients is not properly formatting resource handles. In lieu of the api documentation being improved across thousands of RPC I wonder if you we just surface some of the formatting that is specified in the binding both in the docs and in samples we generate.

Related: googleapis/google-cloud-go#8237

@codyoss codyoss added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Jul 10, 2023
@noahdietz noahdietz changed the title surface google.api.http annotation info surface google.api.resource patterns in documentation Jul 12, 2023
@noahdietz
Copy link
Collaborator

Renamed the issue to focus on the google.api.resource patterns, which users input and end up in HTTP paths

The aspect of an HTTP path that the user provides input to (unknowingly) is the resource name that is inserted as a path variable. For example, with the following proto:

rpc GetBook (GetBookRequest) returns (Book) {
  option (google.api.http) = {
    get: "/v1/{name=books/*}"
  };
}

message GetBookRequest {
  string name = 1 [(google.api.resource_reference).type = "library.googleapis.com/Book"];
}

message Book {
  option (google.api.resource) = {
    type: "library.googleapis.com/Book"
    pattern: "books/{book}"
  };

  string name = 1;
}

The user will need to populate the GetBookRequest.name with something that resembles a Book name i.e. books/{book} e.g. `"books/the-hobbit", which will end up being used as part of the HTTP path if REST is chosen as a transport. Note: The same formatting requirements apply to gRPC requests, but aren't used in creating the request.

We can definitely improve this situation. Here are a few ideas for the generator:

  • Include accepted formats per-field in method comments: If a request message contains a field representing a resource name, the acceptable patterns must be listed out in a comment on the method using that request message
  • Include accepted formats per-field in method example_test code: The example_test snippets that end up in GoDoc examples can also have that same comment stating the accepted format for a field (maybe even generate an example like Name: "books/<BOOK_ID_HERE>", with the other supported patterns as a comment)
  • Include accepted formats per-field in standalone snippets: Do the above but also in the standalone snippet files

@quartzmo
Copy link
Member

quartzmo commented Sep 5, 2023

I discussed this with @amanda-tarafa, who approves the addition to the snippets and will also review the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants