Skip to content

Fix RDG check for endpoint uniqueness - #67591

Merged
Youssef1313 merged 2 commits into
mainfrom
dev/ygerges/rdg-endpoint-uniqueness
Jul 7, 2026
Merged

Youssef1313 merged 2 commits into
mainfrom
dev/ygerges/rdg-endpoint-uniqueness

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #66912

Before the fix, we considered the signature for both of the following endpoints as the same:

app.MapPost("/required",    (Todo t) => "ok");
app.MapPost("/allow-empty", ([FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] Todo t) => "ok");

And so they collapsed into a single interceptor, even though they would otherwise have had different implementations.

This PR makes the equality of endpoint parameter stronger so that the parameter source and optionality are taken into account.

This removes SignatureEquals from EndpointParameter, which was a subset of EndpointParameter.Equals. And we now use EndpointParameter.Equals for correct and accurate equality.

In addition, Endpoint hash code calculation now considers the full hash code of the endpoint parameters, instead of taking only the type into account.

Copilot AI review requested due to automatic review settings July 3, 2026 17:01
@Youssef1313
Youssef1313 requested a review from halter73 as a code owner July 3, 2026 17:01

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 fixes an RDG (Request Delegate Generator) endpoint de-duplication bug where endpoints sharing the same delegate signature could incorrectly collapse into a single generated interceptor, causing binding metadata differences (e.g., [FromBody(EmptyBodyBehavior = Allow)]) to be silently lost.

Changes:

  • Adds a regression test to ensure two endpoints with the same delegate signature but different [FromBody] binding behavior do not collapse.
  • Removes EndpointParameter.SignatureEquals and switches endpoint signature comparison to use EndpointParameter.Equals.
  • Updates signature hashing to incorporate EndpointParameter hashing.

Reviewed changes

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

File Description
src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.JsonBody.cs Adds regression test covering shared delegate signature + differing EmptyBodyBehavior.
src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator/StaticRouteHandlerModel/EndpointParameter.cs Removes SignatureEquals so signature grouping relies on Equals.
src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator/StaticRouteHandlerModel/Endpoint.cs Uses EndpointParameter.Equals for signature equality and updates signature hash computation.

@Youssef1313
Youssef1313 force-pushed the dev/ygerges/rdg-endpoint-uniqueness branch from dffba3d to d672abd Compare July 3, 2026 17:11
@Youssef1313
Youssef1313 requested a review from DeagleGross July 3, 2026 21:02
SymbolEqualityComparer.IncludeNullability.Equals(other.Type, Type) &&
other.KeyedServiceKey == KeyedServiceKey;

public bool SignatureEquals(object obj) =>

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 wonder why there was such method. And I am afraid of the implications of changing GetHashCode() - can we check where it is used? maybe EndpointParameter is a key in some dict?

Should we instead add check here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it might have been trying to optimize to re-use the methods as much as possible, but it was wrong optimization?

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.

Source generator silently drops [FromBody(EmptyBodyBehavior=Allow)] when two endpoints share a delegate signature

3 participants