Skip to content

Commit

Permalink
fix: Correction to query parameter population in gRPC transcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Sep 6, 2022
1 parent 533703d commit b97297d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
81 changes: 67 additions & 14 deletions Google.Api.Gax.Grpc.Tests/Rest/TranscoderTest.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,24 @@ static TranscoderTestReflection() {
"aRgCIAEoCRIlCgRib2R5GAMgASgLMhcuZ29vZ2xlLnByb3RvYnVmLlN0cnVj",
"dCIOCgxFbXB0eVJlcXVlc3QiLQoMU2ltcGxlRmllbGRzEgwKBG5hbWUYASAB",
"KAkSDwoHaW50ZWdlchgCIAEoBSIsChRSZXF1aXJlZEJvb2xlYW5GaWVsZBIU",
"Cgdib29sZWFuGAEgASgIQgPgQQIikQIKEFF1ZXJ5VGVzdE1lc3NhZ2USHQoQ",
"Cgdib29sZWFuGAEgASgIQgPgQQIiqwIKEFF1ZXJ5VGVzdE1lc3NhZ2USHQoQ",
"cmVxdWlyZWRfaW50ZWdlchgBIAEoBUID4EECEiQKF3Byb3RvM19vcHRpb25h",
"bF9pbnRlZ2VyGAIgASgFSACIAQESFwoPcmVwZWF0ZWRfc3RyaW5nGAMgAygJ",
"EkcKBm5lc3RlZBgEIAEoCzI3Lmdvb2dsZS5hcGkuZ2F4LmdycGMucmVzdC50",
"ZXN0cy5RdWVyeVRlc3RNZXNzYWdlLk5lc3RlZBIPCgdpbl9wYXRoGAUgASgJ",
"GikKBk5lc3RlZBIJCgF4GAEgASgFEgkKAXkYAiABKAUSCQoBehgDIAEoBUIa",
"ChhfcHJvdG8zX29wdGlvbmFsX2ludGVnZXIilwIKG1JlcXVlc3RXaXRoUmVj",
"dXJzaXZlTWVzc2FnZRJQCgF6GAEgASgLMkUuZ29vZ2xlLmFwaS5nYXguZ3Jw",
"Yy5yZXN0LnRlc3RzLlJlcXVlc3RXaXRoUmVjdXJzaXZlTWVz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CQoBeRgCIAEoBSJ+ChNTZXBhcmF0ZUJvZHlSZXF1ZXN0EkYK",
"BGJvZHkYASABKAsyOC5nb29nbGUuYXBpLmdheC5ncnBjLnJlc3QudGVzdHMu",
"U2VwYXJhdGVCb2R5UmVxdWVzdC5Cb2R5EgwKBG5hbWUYAiABKAkaEQoEQm9k",
"eRIJCgF4GAEgASgFIjEKEE11bHRpTmFtZVJlcXVlc3QSDQoFZmlyc3QYASAB",
"KAkSDgoGc2Vjb25kGAIgASgJYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor, global::Google.Api.FieldBehaviorReflection.Descriptor, global::Google.Api.HttpReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
Expand All @@ -69,7 +70,7 @@ static TranscoderTestReflection() {
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.EmptyRequest), global::Google.Api.Gax.Grpc.Rest.Tests.EmptyRequest.Parser, null, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.SimpleFields), global::Google.Api.Gax.Grpc.Rest.Tests.SimpleFields.Parser, new[]{ "Name", "Integer" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.RequiredBooleanField), global::Google.Api.Gax.Grpc.Rest.Tests.RequiredBooleanField.Parser, new[]{ "Boolean" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage), global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage.Parser, new[]{ "RequiredInteger", "Proto3OptionalInteger", "RepeatedString", "Nested", "InPath" }, new[]{ "Proto3OptionalInteger" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage.Types.Nested), global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage.Types.Nested.Parser, new[]{ "X", "Y", "Z" }, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage), global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage.Parser, new[]{ "RequiredInteger", "Proto3OptionalInteger", "RepeatedString", "Nested", "InPath" }, new[]{ "Proto3OptionalInteger" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage.Types.Nested), global::Google.Api.Gax.Grpc.Rest.Tests.QueryTestMessage.Types.Nested.Parser, new[]{ "X", "Y", "Z", "Opt" }, new[]{ "Opt" }, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.RequestWithRecursiveMessage), global::Google.Api.Gax.Grpc.Rest.Tests.RequestWithRecursiveMessage.Parser, new[]{ "Z", "Simple" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.RequestWithRecursiveMessage.Types.Recursive), global::Google.Api.Gax.Grpc.Rest.Tests.RequestWithRecursiveMessage.Types.Recursive.Parser, new[]{ "X", "Y" }, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.SeparateBodyRequest), global::Google.Api.Gax.Grpc.Rest.Tests.SeparateBodyRequest.Parser, new[]{ "Body", "Name" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.SeparateBodyRequest.Types.Body), global::Google.Api.Gax.Grpc.Rest.Tests.SeparateBodyRequest.Types.Body.Parser, new[]{ "X" }, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Api.Gax.Grpc.Rest.Tests.MultiNameRequest), global::Google.Api.Gax.Grpc.Rest.Tests.MultiNameRequest.Parser, new[]{ "First", "Second" }, null, null, null, null)
Expand Down Expand Up @@ -2136,6 +2137,7 @@ public sealed partial class Nested : pb::IMessage<Nested>
{
private static readonly pb::MessageParser<Nested> _parser = new pb::MessageParser<Nested>(() => new Nested());
private pb::UnknownFieldSet _unknownFields;
private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<Nested> Parser { get { return _parser; } }
Expand Down Expand Up @@ -2163,9 +2165,11 @@ public Nested() {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Nested(Nested other) : this() {
_hasBits0 = other._hasBits0;
x_ = other.x_;
y_ = other.y_;
z_ = other.z_;
opt_ = other.opt_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}

Expand Down Expand Up @@ -2211,6 +2215,31 @@ public int Z {
}
}

/// <summary>Field number for the "opt" field.</summary>
public const int OptFieldNumber = 4;
private int opt_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int Opt {
get { if ((_hasBits0 & 1) != 0) { return opt_; } else { return 0; } }
set {
_hasBits0 |= 1;
opt_ = value;
}
}
/// <summary>Gets whether the "opt" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasOpt {
get { return (_hasBits0 & 1) != 0; }
}
/// <summary>Clears the value of the "opt" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearOpt() {
_hasBits0 &= ~1;
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
Expand All @@ -2229,6 +2258,7 @@ public bool Equals(Nested other) {
if (X != other.X) return false;
if (Y != other.Y) return false;
if (Z != other.Z) return false;
if (Opt != other.Opt) return false;
return Equals(_unknownFields, other._unknownFields);
}

Expand All @@ -2239,6 +2269,7 @@ public override int GetHashCode() {
if (X != 0) hash ^= X.GetHashCode();
if (Y != 0) hash ^= Y.GetHashCode();
if (Z != 0) hash ^= Z.GetHashCode();
if (HasOpt) hash ^= Opt.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
Expand Down Expand Up @@ -2269,6 +2300,10 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(24);
output.WriteInt32(Z);
}
if (HasOpt) {
output.WriteRawTag(32);
output.WriteInt32(Opt);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
Expand All @@ -2291,6 +2326,10 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(24);
output.WriteInt32(Z);
}
if (HasOpt) {
output.WriteRawTag(32);
output.WriteInt32(Opt);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
Expand All @@ -2310,6 +2349,9 @@ public int CalculateSize() {
if (Z != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Z);
}
if (HasOpt) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Opt);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
Expand All @@ -2331,6 +2373,9 @@ public void MergeFrom(Nested other) {
if (other.Z != 0) {
Z = other.Z;
}
if (other.HasOpt) {
Opt = other.Opt;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}

Expand Down Expand Up @@ -2358,6 +2403,10 @@ public void MergeFrom(pb::CodedInputStream input) {
Z = input.ReadInt32();
break;
}
case 32: {
Opt = input.ReadInt32();
break;
}
}
}
#endif
Expand Down Expand Up @@ -2385,6 +2434,10 @@ public void MergeFrom(pb::CodedInputStream input) {
Z = input.ReadInt32();
break;
}
case 32: {
Opt = input.ReadInt32();
break;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Google.Api.Gax.Grpc.Tests/Rest/transcoder_test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ message QueryTestMessage {
int32 x = 1;
int32 y = 2;
int32 z = 3;
optional int32 opt = 4;
}

// A required field should be present even if the value is the default.
Expand Down
2 changes: 1 addition & 1 deletion Google.Api.Gax.Grpc/Rest/HttpRuleTranscoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internal IEnumerable<string> GetValues(IMessage request)
yield break;
}

if (_field.HasPresence && !_field.Accessor.HasValue(request))
if (_field.HasPresence && !_field.Accessor.HasValue(parent))
{
yield break;
}
Expand Down

0 comments on commit b97297d

Please sign in to comment.