Skip to content

impl(sidekick): capture query and path parameters#2282

Closed
coryan wants to merge 2 commits intogoogleapis:mainfrom
coryan:pr05-generate-compute-zones
Closed

impl(sidekick): capture query and path parameters#2282
coryan wants to merge 2 commits intogoogleapis:mainfrom
coryan:pr05-generate-compute-zones

Conversation

@coryan
Copy link
Copy Markdown
Contributor

@coryan coryan commented Sep 20, 2025

Capture the query and path parameters of each method into a synthetic
request message.

Fixes #2275 and fixes #2267

Capture the query and path parameters of each method into a synthetic
request message.
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.06%. Comparing base (083b15a) to head (7c27326).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2282      +/-   ##
==========================================
+ Coverage   83.99%   84.06%   +0.07%     
==========================================
  Files          96       96              
  Lines        9632     9679      +47     
==========================================
+ Hits         8090     8137      +47     
  Misses       1197     1197              
  Partials      345      345              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coryan coryan marked this pull request as ready for review September 20, 2025 20:28
@coryan coryan requested a review from a team September 20, 2025 20:28
Copy link
Copy Markdown
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I agree with the output of the generation that you shared with me.

The way we are achieving it in the model seems hacky / too clever to me.

I don't want to block progress. I get that the specs don't line up and we are only going to do this hack once*. I think some comments explaining the strategy could help.

*: Well, the next language might get confused when they need to generate their compute library.

if bodyID != ".google.protobuf.Empty" {
body := &api.Field{
Documentation: fmt.Sprintf("Synthetic request body field for the [%s()][%s] method.", input.Name, id[1:]),
Name: "body",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: this could conflict with a path/query params called body. We could deal with it, if that ever arises.

optional: report an error in sidekick now? (rather than rely on cargo catching the build error in the CI)

Codec any
}

// HasRequests is used by mustache templates to optional emit code depending on
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/optional/optionally/

func makeServiceMethods(model *api.API, serviceName, serviceID string, doc *document, resource *resource) ([]*api.Method, []*api.Message, error) {
requests := &api.Message{
Name: serviceName,
ID: serviceID,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeating IDs? 😒

I know why we are doing it. It just gives me the ick.


func makeServiceMethods(model *api.API, serviceID string, doc *document, resource *resource) ([]*api.Method, error) {
func makeServiceMethods(model *api.API, serviceName, serviceID string, doc *document, resource *resource) ([]*api.Method, []*api.Message, error) {
requests := &api.Message{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going to go with this, can you add comments describing that

  • this is a parent message. child message generation goes poorly if there is not a parent.
  • it will not be generated; it is just for organization
  • we use it so the synthetic requests for a service can be scoped to a module (i.e. zones::ListRequest vs. ZonesListRequest)

// Sidekick creates synthetic messages for these specifications. The codecs
// need to generate these messages separate from "normal" messages. They
// should keep in mind that name clashes are possible.
Requests []*Message
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alternative is to add a Synthetic: bool field to an api.Message. And then in generation, we could skip generating serde for any message where m.Synthetic == true.

And we can skip generating the message at all when m.Synthetic == true && !m.Parent. Or something.

// do something special to avoid clashes.
index := slices.IndexFunc(model.Messages, func(a *api.Message) bool { return a.ID == id })
if index != -1 {
t.Errorf("synthetic request messages should not be in the `model.Messages` list")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like they should be in the list, they should just be tagged as synthetic. 🤷

@coryan coryan closed this Sep 23, 2025
@coryan coryan deleted the pr05-generate-compute-zones branch September 29, 2025 12:26
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

Successfully merging this pull request may close these issues.

[sidekick/discovery]: query parameters should be optional [sidekick/discovery]: capture request path and query parameters

2 participants