Skip to content

gRPC transcoding: respecting json-name aliases#67108

Merged
wtgodbe merged 1 commit into
mainfrom
wtgodbe/grpc
Jun 10, 2026
Merged

gRPC transcoding: respecting json-name aliases#67108
wtgodbe merged 1 commit into
mainfrom
wtgodbe/grpc

Conversation

@wtgodbe

@wtgodbe wtgodbe commented Jun 10, 2026

Copy link
Copy Markdown
Member

No description provided.

… aliases

Fixed issue where in grpc transcoding query parameter processing overwrites route or body-bound fields. Also fixing unmatched query parameters stored in the descriptor cache
Copilot AI review requested due to automatic review settings June 10, 2026 00:18
@github-actions github-actions Bot added the area-grpc Includes: GRPC wire-up, templates label Jun 10, 2026
@wtgodbe wtgodbe requested a review from DeagleGross June 10, 2026 00:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates gRPC JSON transcoding binding behavior to better respect protobuf json_name aliases, ensuring query string parameters that target a route-bound field (via either proto name or JSON name) don’t overwrite values already bound from the route/body.

Changes:

  • Prevent query-string binding from overwriting route-bound fields when the query uses the field’s JSON name alias.
  • Avoid caching unresolved query-string paths in PathDescriptorsCache (only cache successful resolutions).
  • Add unit + integration test coverage for alias/non-alias overwrite scenarios and for not caching unmatched query paths.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Internal/JsonRequestHelpers.cs Updates query-string binding eligibility (body field JSON-name blocking + route JSON-path blocking) and adjusts descriptor-path caching behavior.
src/Grpc/JsonTranscoding/src/Microsoft.AspNetCore.Grpc.JsonTranscoding/Internal/CallHandlers/CallHandlerDescriptorInfo.cs Adds storage for route-parameter JSON paths and changes the descriptor-path cache to store only non-null descriptor paths.
src/Grpc/JsonTranscoding/test/Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests/UnaryServerCallHandlerTests.cs Adds unit tests for alias overwrite prevention and for not caching unmatched query-string keys.
src/Grpc/JsonTranscoding/test/Microsoft.AspNetCore.Grpc.JsonTranscoding.IntegrationTests/RouteTests.cs Adds integration test ensuring nested JSON-name query params don’t overwrite route-bound values.
src/Grpc/JsonTranscoding/test/Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests/Proto/transcoding.proto Adds sub_data to enable coverage for body-field JSON-name prefix blocking (subData.*).

Comment on lines +29 to 35
var jsonPaths = new HashSet<string>(StringComparer.Ordinal);
foreach (var routeParameter in routeParameterDescriptors.Values)
{
jsonPaths.Add(routeParameter.JsonPath);
}
RouteParameterJsonPaths = jsonPaths;
}
Comment on lines 362 to +375
private static List<FieldDescriptor>? GetPathDescriptors(JsonTranscodingServerCallContext serverCallContext, IMessage requestMessage, string path)
{
return serverCallContext.DescriptorInfo.PathDescriptorsCache.GetOrAdd(path, p =>
// Must not add null values for paths that don't resolve to a descriptor
var cache = serverCallContext.DescriptorInfo.PathDescriptorsCache;
if (cache.TryGetValue(path, out var pathDescriptors))
{
ServiceDescriptorHelpers.TryResolveDescriptors(requestMessage.Descriptor, p.Split('.'), allowJsonName: true, out var pathDescriptors);
return pathDescriptors;
});
}
if (ServiceDescriptorHelpers.TryResolveDescriptors(requestMessage.Descriptor, path.Split('.'), allowJsonName: true, out pathDescriptors))
{
cache.TryAdd(path, pathDescriptors);
return pathDescriptors;
}
return null;
public async Task HandleCallAsync_QueryStringProtoName_DoesNotOverwriteRouteValue()
{
// Arrange
// A query parameter using the proto name is not overwritting the route-bound field.
@wtgodbe

wtgodbe commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

/ba-g unrelated mac failure

@wtgodbe wtgodbe merged commit b0fe49c into main Jun 10, 2026
22 of 28 checks passed
@wtgodbe wtgodbe deleted the wtgodbe/grpc branch June 10, 2026 04:06
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-grpc Includes: GRPC wire-up, templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants