Skip to content

Let JsonException bubble through problem details in minimal APIs - #66519

Merged
Youssef1313 merged 8 commits into
mainfrom
dev/ygerges/minimal-jsonexception
May 22, 2026
Merged

Let JsonException bubble through problem details in minimal APIs#66519
Youssef1313 merged 8 commits into
mainfrom
dev/ygerges/minimal-jsonexception

Conversation

@Youssef1313

Copy link
Copy Markdown
Member

Fixes #64139

Copilot AI review requested due to automatic review settings April 28, 2026 17:40
@Youssef1313
Youssef1313 requested review from a team, BrennanConroy and halter73 as code owners April 28, 2026 17:40
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 28, 2026

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

Updates minimal API JSON body binding to emit validation-style Problem Details when System.Text.Json throws a JsonException (e.g., missing required properties), aligning the behavior more closely with MVC/controller model binding.

Changes:

  • Write HttpValidationProblemDetails via IProblemDetailsService when JSON body deserialization throws JsonException in RequestDelegateFactory.
  • Add a functional test validating consistent Problem Details output for both a minimal endpoint and an MVC [ApiController] endpoint.
  • Extend the SimpleWebSiteWithWebApplicationBuilder test app with endpoints/models to reproduce the required property scenario.

Reviewed changes

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

File Description
src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/Program.cs Adds ProblemDetails services + new endpoints/model to exercise missing required property behavior.
src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs Adds a functional test asserting Problem Details JSON for both minimal + MVC endpoints.
src/Http/Http.Extensions/src/RequestDelegateFactory.cs Emits HttpValidationProblemDetails on JsonException during minimal API JSON body binding.

Comment thread src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/Program.cs Outdated
Comment thread src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs Outdated
Comment thread src/Http/Http.Extensions/src/RequestDelegateFactory.cs Outdated

@mikekistler mikekistler left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Youssef1313 Thank you for this contribution!

I will let the engineering team weigh in on the details of this change but I fully support the effort to solve this problem.

@Youssef1313 Youssef1313 added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Apr 29, 2026
@Youssef1313

Copy link
Copy Markdown
Member Author

@BrennanConroy @halter73 @javiercn Can I get a review here please? Thanks.

Comment thread src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Comment thread src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs Outdated
@Youssef1313
Youssef1313 requested a review from BrennanConroy May 7, 2026 14:15

await endpoint.RequestDelegate(httpContext);

var logs = TestSink.Writes.ToArray();

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.

nit: unused

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.

Fixed.

Comment thread src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs Outdated
@Youssef1313

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@Youssef1313
Youssef1313 merged commit a23bff9 into main May 22, 2026
25 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/minimal-jsonexception branch May 22, 2026 16:29
@dotnet-policy-service dotnet-policy-service Bot added this to the 11.0-preview5 milestone May 22, 2026
javiercn pushed a commit that referenced this pull request May 28, 2026
)

* Let JsonException bubble through problem details in minimal APIs

* Use TryWriteAsync

* Address review comment

* Fix

* Update for RDG

* Address review comments

* Avoid diff noise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make required keyword handling produce validation error in minimal APIs

5 participants