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

impl(generator): support protobuf wrapper types as query params #14493

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

scotthart
Copy link
Member

@scotthart scotthart commented Jul 18, 2024

fixes #14491


This change is Reviewable

@scotthart scotthart requested a review from a team as a code owner July 18, 2024 19:10
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.59%. Comparing base (eb2cacc) to head (452cafc).
Report is 3 commits behind head on main.

Files Patch % Lines
generator/internal/http_option_utils.cc 98.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14493      +/-   ##
==========================================
- Coverage   93.60%   93.59%   -0.01%     
==========================================
  Files        2316     2316              
  Lines      207319   207364      +45     
==========================================
+ Hits       194054   194092      +38     
- Misses      13265    13272       +7     

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

service_file_descriptor->service(0)->method(0);
VarsDictionary vars;
SetHttpQueryParameters(ParseHttpExtension(*method), *method, vars);
EXPECT_THAT(vars.at("method_http_query_parameters"), Eq(R"""(,
Copy link
Member

Choose a reason for hiding this comment

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

comment: This is nearly a change detector test, but I think it's fine. I don't think saying: AllOf(Contains(...), Contains(...), ...) is any nicer.

Comment on lines +76 to +78
// Check presence for MESSAGE types as their default values may result in
// undesired behavior.
bool check_presence;
Copy link
Member

Choose a reason for hiding this comment

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

TIL that nested protobuf messages are inherently optional and that: "" != "foo { }"

for:

message Foo {}

message Bar {
  Foo foo = 1;
}

if (!field.is_repeated() && !field.options().deprecated()) {
if (field.cpp_type() != protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
param_info = QueryParameterInfo{
field.cpp_type(), absl::StrCat("request.", field.name(), "()"),
Copy link
Member

Choose a reason for hiding this comment

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

Here and below, I think we might need to look up the accessor name. (in case the field is called something like delete or namespace and the accessor is delete_()).

I'd guess there are 0 such cases in practice, so we can defer.

@@ -104,9 +104,18 @@ DefaultJobServiceRestStub::ListJobs(
rest_internal::DetermineApiVersion("v2", options), "/",
"projects", "/", request.project_id(), "/", "jobs"),
rest_internal::TrimEmptyQueryParameters(
{std::make_pair("all_users", request.all_users() ? "1" : "0"),
{std::make_pair("all_users", (request.all_users() ? "1" : "0")),
std::make_pair("max_results",
Copy link
Member

Choose a reason for hiding this comment

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

FYI (mostly for myself): I was expecting that we would need to say max_results.value here. But from experimenting, both max_results and max_results.value work.

$ curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  https://bigquery.googleapis.com/bigquery/v2/projects/cloud-cpp-testing-resources/jobs?maxResults=1
# response with 1 result

curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  https://bigquery.googleapis.com/bigquery/v2/projects/cloud-cpp-testing-resources/jobs?maxResults.value=1
# response with 1 result

Strange... 🤷

Copy link
Member Author

@scotthart scotthart left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 105 files reviewed, 3 unresolved discussions (waiting on @dbolduc)


generator/internal/http_option_utils.cc line 227 at r1 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

Here and below, I think we might need to look up the accessor name. (in case the field is called something like delete or namespace and the accessor is delete_()).

I'd guess there are 0 such cases in practice, so we can defer.

created #14505


generator/internal/http_option_utils_test.cc line 661 at r1 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

comment: This is nearly a change detector test, but I think it's fine. I don't think saying: AllOf(Contains(...), Contains(...), ...) is any nicer.

Ack


google/cloud/bigquerycontrol/v2/internal/job_rest_stub.cc line 108 at r1 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

FYI (mostly for myself): I was expecting that we would need to say max_results.value here. But from experimenting, both max_results and max_results.value work.

$ curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  https://bigquery.googleapis.com/bigquery/v2/projects/cloud-cpp-testing-resources/jobs?maxResults=1
# response with 1 result

curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  https://bigquery.googleapis.com/bigquery/v2/projects/cloud-cpp-testing-resources/jobs?maxResults.value=1
# response with 1 result

Strange... 🤷

It may be a compatibility allowance on the part of the service, but I'm purely speculating.

@scotthart scotthart merged commit 7603af8 into googleapis:main Jul 19, 2024
63 of 64 checks passed
cuiy0006 pushed a commit to cuiy0006/google-cloud-cpp that referenced this pull request Jul 22, 2024
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.

protobuf wrapper types not recognized as REST query parameters
2 participants