Skip to content

Commit 31b8eea

Browse files
authored
Merge pull request dotnet#44198 from dotnet-maestro-bot/merge/release/7.0-to-main
[automated] Merge branch 'release/7.0' => 'main'
2 parents fb537bb + 410ce53 commit 31b8eea

File tree

25 files changed

+320
-260
lines changed

25 files changed

+320
-260
lines changed

eng/Versions.props

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@
248248
<CommandLineParserVersion>2.3.0</CommandLineParserVersion>
249249
<FSharpCoreVersion>6.0.0</FSharpCoreVersion>
250250
<GoogleApiCommonProtosVersion>2.5.0</GoogleApiCommonProtosVersion>
251-
<GoogleProtobufVersion>3.18.1</GoogleProtobufVersion>
252-
<GrpcAspNetCoreVersion>2.45.0</GrpcAspNetCoreVersion>
253-
<GrpcAspNetCoreServerVersion>2.45.0</GrpcAspNetCoreServerVersion>
254-
<GrpcAuthVersion>2.45.0</GrpcAuthVersion>
255-
<GrpcNetClientVersion>2.45.0</GrpcNetClientVersion>
256-
<GrpcToolsVersion>2.45.0</GrpcToolsVersion>
251+
<GoogleProtobufVersion>3.21.5</GoogleProtobufVersion>
252+
<GrpcAspNetCoreVersion>2.49.0</GrpcAspNetCoreVersion>
253+
<GrpcAspNetCoreServerVersion>2.49.0</GrpcAspNetCoreServerVersion>
254+
<GrpcAuthVersion>2.49.0</GrpcAuthVersion>
255+
<GrpcNetClientVersion>2.49.0</GrpcNetClientVersion>
256+
<GrpcToolsVersion>2.49.0</GrpcToolsVersion>
257257
<DuendeIdentityServerAspNetIdentityVersion>6.0.4</DuendeIdentityServerAspNetIdentityVersion>
258258
<DuendeIdentityServerEntityFrameworkVersion>6.0.4</DuendeIdentityServerEntityFrameworkVersion>
259259
<DuendeIdentityServerVersion>6.0.4</DuendeIdentityServerVersion>

src/Grpc/Interop/test/testassets/InteropClient/InteropClient.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<Nullable>enable</Nullable>
7-
<!-- Suppress warnings about lowercase variable names in generated code -->
8-
<NoWarn>$(NoWarn);CS8981</NoWarn>
97
</PropertyGroup>
108

119
<ItemGroup>
@@ -14,7 +12,7 @@
1412
<Protobuf Include="..\Proto\grpc\testing\messages.proto" GrpcServices="None" Link="Protos\messages.proto" />
1513

1614
<Compile Include="$(SharedSourceRoot)HttpClient\HttpEventSourceListener.cs" />
17-
15+
1816
<Reference Include="CommandLineParser" />
1917
<Reference Include="Google.Protobuf" />
2018
<Reference Include="Grpc.Auth" />

src/Grpc/Interop/test/testassets/InteropWebsite/InteropWebsite.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<Nullable>enable</Nullable>
77
<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);$(ArtifactsShippingPackagesDir)</RestoreAdditionalProjectSources>
88
<UseAspNetCoreSharedRuntime>true</UseAspNetCoreSharedRuntime>
9-
<!-- Suppress warnings about lowercase variable names in generated code -->
10-
<NoWarn>$(NoWarn);CS8981</NoWarn>
119
</PropertyGroup>
1210

1311
<ItemGroup>

src/Grpc/JsonTranscoding/perf/Microsoft.AspNetCore.Grpc.Microbenchmarks/Microsoft.AspNetCore.Grpc.Microbenchmarks.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<TieredCompilation>false</TieredCompilation>
88
<DefineConstants>$(DefineConstants);IS_BENCHMARKS</DefineConstants>
9-
<!-- Suppress warnings about lowercase variable names in generated code -->
10-
<NoWarn>$(NoWarn);CS8981</NoWarn>
119
</PropertyGroup>
1210

1311
<ItemGroup>

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/GrpcJsonSettings.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ namespace Microsoft.AspNetCore.Grpc.JsonTranscoding;
99
public sealed class GrpcJsonSettings
1010
{
1111
/// <summary>
12-
/// Whether fields which would otherwise not be included in the formatted data
13-
/// should be formatted even when the value is not present, or has the default value.
14-
/// This option only affects fields which don't support "presence" (e.g.
15-
/// singular non-optional proto3 primitive fields).
12+
/// Gets or sets a value that indicates whether fields with default values are ignored during serialization.
13+
/// This setting only affects fields which don't support "presence", such as singular non-optional proto3 primitive fields.
14+
/// Default value is false.
1615
/// </summary>
1716
public bool IgnoreDefaultValues { get; set; }
1817

@@ -23,7 +22,7 @@ public sealed class GrpcJsonSettings
2322
public bool WriteEnumsAsIntegers { get; set; }
2423

2524
/// <summary>
26-
/// Gets or sets a value that indicates whether <see cref="Int64"/> and <see cref="UInt64"/> values are written as strings instead of numbers.
25+
/// Gets or sets a value that indicates whether <see cref="long"/> and <see cref="ulong"/> values are written as strings instead of numbers.
2726
/// Default value is false.
2827
/// </summary>
2928
public bool WriteInt64sAsStrings { get; set; }

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Internal/Binding/JsonTranscodingProviderServiceBinder.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ private static CallHandlerDescriptorInfo CreateDescriptorInfo(string body, strin
244244
FieldDescriptor? responseBodyDescriptor = null;
245245
if (!string.IsNullOrEmpty(responseBody))
246246
{
247+
if (responseBody.Contains('.', StringComparison.Ordinal))
248+
{
249+
throw new InvalidOperationException($"The response body field '{responseBody}' references a nested field. The response body field name must be on the top-level response message.");
250+
}
247251
responseBodyDescriptor = methodDescriptor.OutputType.FindFieldByName(responseBody);
248252
if (responseBodyDescriptor == null)
249253
{
@@ -255,7 +259,7 @@ private static CallHandlerDescriptorInfo CreateDescriptorInfo(string body, strin
255259
responseBodyDescriptor,
256260
bodyDescriptor?.Descriptor,
257261
bodyDescriptor?.IsDescriptorRepeated ?? false,
258-
bodyDescriptor?.FieldDescriptors,
262+
bodyDescriptor?.FieldDescriptor,
259263
routeParameterDescriptors,
260264
routeAdapter);
261265
return descriptorInfo;

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Internal/CallHandlers/CallHandlerDescriptorInfo.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Collections.Concurrent;
55
using System.Diagnostics.CodeAnalysis;
6-
using System.Linq;
76
using Google.Protobuf.Reflection;
87
using Grpc.Shared;
98

@@ -15,30 +14,25 @@ public CallHandlerDescriptorInfo(
1514
FieldDescriptor? responseBodyDescriptor,
1615
MessageDescriptor? bodyDescriptor,
1716
bool bodyDescriptorRepeated,
18-
List<FieldDescriptor>? bodyFieldDescriptors,
17+
FieldDescriptor? bodyFieldDescriptor,
1918
Dictionary<string, RouteParameter> routeParameterDescriptors,
2019
JsonTranscodingRouteAdapter routeAdapter)
2120
{
2221
ResponseBodyDescriptor = responseBodyDescriptor;
2322
BodyDescriptor = bodyDescriptor;
2423
BodyDescriptorRepeated = bodyDescriptorRepeated;
25-
BodyFieldDescriptors = bodyFieldDescriptors;
24+
BodyFieldDescriptor = bodyFieldDescriptor;
2625
RouteParameterDescriptors = routeParameterDescriptors;
2726
RouteAdapter = routeAdapter;
28-
if (BodyFieldDescriptors != null)
29-
{
30-
BodyFieldDescriptorsPath = string.Join('.', BodyFieldDescriptors.Select(d => d.Name));
31-
}
3227
PathDescriptorsCache = new ConcurrentDictionary<string, List<FieldDescriptor>?>();
3328
}
3429

3530
public FieldDescriptor? ResponseBodyDescriptor { get; }
3631
public MessageDescriptor? BodyDescriptor { get; }
37-
[MemberNotNullWhen(true, nameof(BodyFieldDescriptors), nameof(BodyFieldDescriptorsPath))]
32+
[MemberNotNullWhen(true, nameof(BodyFieldDescriptor))]
3833
public bool BodyDescriptorRepeated { get; }
39-
public List<FieldDescriptor>? BodyFieldDescriptors { get; }
34+
public FieldDescriptor? BodyFieldDescriptor { get; }
4035
public Dictionary<string, RouteParameter> RouteParameterDescriptors { get; }
4136
public JsonTranscodingRouteAdapter RouteAdapter { get; }
4237
public ConcurrentDictionary<string, List<FieldDescriptor>?> PathDescriptorsCache { get; }
43-
public string? BodyFieldDescriptorsPath { get; }
4438
}

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Internal/JsonRequestHelpers.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Collections;
54
using System.Diagnostics;
6-
using System.Linq;
75
using System.Text;
86
using System.Text.Json;
97
using Google.Api;
@@ -201,7 +199,7 @@ public static async ValueTask<TRequest> ReadMessage<TRequest>(JsonTranscodingSer
201199

202200
// TODO: JsonSerializer currently doesn't support deserializing values onto an existing object or collection.
203201
// Either update this to use new functionality in JsonSerializer or improve work-around perf.
204-
type = JsonConverterHelper.GetFieldType(serverCallContext.DescriptorInfo.BodyFieldDescriptors.Last());
202+
type = JsonConverterHelper.GetFieldType(serverCallContext.DescriptorInfo.BodyFieldDescriptor);
205203
type = type.GetGenericArguments()[0];
206204
type = typeof(List<>).MakeGenericType(type);
207205

@@ -231,10 +229,13 @@ public static async ValueTask<TRequest> ReadMessage<TRequest>(JsonTranscodingSer
231229
}
232230
}
233231

234-
if (serverCallContext.DescriptorInfo.BodyFieldDescriptors != null)
232+
if (serverCallContext.DescriptorInfo.BodyFieldDescriptor != null)
235233
{
236234
requestMessage = (IMessage)Activator.CreateInstance<TRequest>();
237-
ServiceDescriptorHelpers.RecursiveSetValue(requestMessage, serverCallContext.DescriptorInfo.BodyFieldDescriptors, bodyContent); // TODO - check nullability
235+
236+
// The spec says that request body must be on the top-level message.
237+
// Recursive request body isn't supported.
238+
ServiceDescriptorHelpers.SetValue(requestMessage, serverCallContext.DescriptorInfo.BodyFieldDescriptor, bodyContent);
238239
}
239240
else
240241
{
@@ -355,7 +356,8 @@ public static async ValueTask SendMessage<TResponse>(JsonTranscodingServerCallCo
355356

356357
if (serverCallContext.DescriptorInfo.ResponseBodyDescriptor != null)
357358
{
358-
// TODO: Support recursive response body?
359+
// The spec says that response body must be on the top-level message.
360+
// Recursive response body isn't supported.
359361
responseBody = serverCallContext.DescriptorInfo.ResponseBodyDescriptor.Accessor.GetValue((IMessage)message);
360362
responseType = JsonConverterHelper.GetFieldType(serverCallContext.DescriptorInfo.ResponseBodyDescriptor);
361363
}
@@ -381,17 +383,24 @@ private static bool CanBindQueryStringVariable(JsonTranscodingServerCallContext
381383
{
382384
if (serverCallContext.DescriptorInfo.BodyDescriptor != null)
383385
{
384-
if (serverCallContext.DescriptorInfo.BodyFieldDescriptors == null || serverCallContext.DescriptorInfo.BodyFieldDescriptors.Count == 0)
386+
var bodyFieldName = serverCallContext.DescriptorInfo.BodyFieldDescriptor?.Name;
387+
388+
// Null field name indicates "*" which means the entire message is bound to the body.
389+
if (bodyFieldName == null)
385390
{
386391
return false;
387392
}
388393

389-
if (variable == serverCallContext.DescriptorInfo.BodyFieldDescriptorsPath)
394+
// Exact match
395+
if (variable == bodyFieldName)
390396
{
391397
return false;
392398
}
393399

394-
if (variable.StartsWith(serverCallContext.DescriptorInfo.BodyFieldDescriptorsPath!, StringComparison.Ordinal))
400+
// Nested field of field name.
401+
if (bodyFieldName.Length + 1 < variable.Length &&
402+
variable.StartsWith(bodyFieldName, StringComparison.Ordinal) &&
403+
variable[bodyFieldName.Length] == '.')
395404
{
396405
return false;
397406
}

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Microsoft.AspNetCore.Grpc.JsonTranscoding.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<Description>HTTP API for gRPC ASP.NET Core</Description>
44
<PackageTags>gRPC RPC HTTP/2 REST</PackageTags>
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
6-
<!-- Suppress warnings about lowercase variable names in generated code -->
7-
<NoWarn>$(NoWarn);CS8981</NoWarn>
86
</PropertyGroup>
97

108
<ItemGroup>

src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.Swagger/Internal/GrpcJsonTranscodingDescriptionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static ApiDescription CreateApiDescription(RouteEndpoint routeEndpoint,
137137
});
138138
}
139139

140-
var queryParameters = ServiceDescriptorHelpers.ResolveQueryParameterDescriptors(routeParameters, methodDescriptor, bodyDescriptor?.Descriptor, bodyDescriptor?.FieldDescriptors);
140+
var queryParameters = ServiceDescriptorHelpers.ResolveQueryParameterDescriptors(routeParameters, methodDescriptor, bodyDescriptor?.Descriptor, bodyDescriptor?.FieldDescriptor);
141141
foreach (var queryDescription in queryParameters)
142142
{
143143
var fieldType = MessageDescriptorHelpers.ResolveFieldType(queryDescription.Value);

0 commit comments

Comments
 (0)