Backport/pr 42384 to release/7.0 preview7#42809
Merged
dougbu merged 1 commit intorelease/7.0-preview7from Jul 19, 2022
Merged
Conversation
* MVC Changes * ExceptionHandler changes * Routing changes * Http.Extensions changes * Minimal APi draft changes * HttpResults changes * New ProblemDetails project * Using ProblemDetailsOptions in mvc * ProblemDetails project simplification * Using metadata * Using metadata * Latest version * Removing changes * Initial cleanup * Clean up * Public api clean up * Updating public API * More clean ups * Adding initial unit tests * Updating unit tests * Adding more unit tests * Cleanup * Clean up * clean up * clean up * Removing nullable * Simplifying public api * API Review feedback * API review feedback * Clean up * Clean up * clean up * Reusing Endpoint & EndpointMetadataCollection * Fix build issues * Updates based on docs/Trimming.md * Adding Functional tests * Fix unittest * Seal context * Seal ProblemMetadata * PR Feeback * API Review * Clean up * Fixing publicapi warnings * Clean up * PR Feedback * Fixing build * Fix unit test * Fix unit tests * PR review * Fixing JsonSerializationContext issues * Adding statuscode 405 * Update src/Http/Http.Extensions/src/ProblemDetailsDefaultWriter.cs Co-authored-by: Brennan <brecon@microsoft.com> * PR review * Apply suggestions from code review Co-authored-by: Stephen Halter <halter73@gmail.com> * Fixing bad merge * Fix bad merge * Adding analysis.NextMiddlewareName * PR review * Changing to CanWrite/WriteAsync Co-authored-by: Brennan <brecon@microsoft.com> Co-authored-by: Stephen Halter <halter73@gmail.com>
Member
Author
|
The original approved via email backport PR (#42741) was merged targeting main instead of release/7.0-preview-7 |
BrennanConroy
approved these changes
Jul 19, 2022
Member
Author
|
@dotnet/aspnet-build Can I get help merging? |
Contributor
|
@mmitche this was |
Member
|
Yep go for it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #42384 to release/7.0-preview4
/cc @brunolins16
Adding ProblemDetailsService
Adding a new
ProblemDetailsServiceresponsible for consistentProblem Detailsgeneration.Description
API Controllers have a mechanism to auto generated
Problem Details(https://datatracker.ietf.org/doc/html/rfc7807) for API ControllerActionResult. The mechanism is enabled by default for allAPI Controllers, however, it will only generates aProblem Detailspayload when theAPI Controller Actionis processed and produces aHTTP Status Code 400+and noResponse Body, that means, scenarios like - unhandled exceptions, routing issues - won't produce aProblem Detailspayload.Here is overview of when the mechanism will produce the payload:
❌ = Not generated
✅ = Automatically generated
Routing issues: ❌
Unhandled Exceptions: ❌
MVC
StatusCodeResult400 and up: ✅ (based onSuppressMapClientErrors)BadRequestResultandUnprocessableEntityResultareStatusCodeResultProblemDetailsis specified in the input)UnprocessableEntityObjectResult415 UnsupportedMediaType: ✅ (Unless when aConsumesAttributeis defined)406 NotAcceptable: ❌ (when happens in the output formatter)Minimal APIswon't generate aProblem Detailspayload as well.Here are some examples of reported issues by the community:
This API introduce a new service that is consumed by
Diagnostics Middlewaresto have theProblemDetailsgenerated, for all Status 400+ and also have a mechanism that allows devs or library authors (eg. API Versioning) generateProblemDetailsresponses when opted-in by the users.Sample Usage
Default options
Fixes #42212
Customer Impact
This issue has been reported for years, including a community
middlewareis available to try fix the gap in the framework. This change does not replace the community middleware totally, however, enable the core functionality in the framework.Regression?
Risk
This is a new API. The change to existing code is very small and non-impactful unless the new
AddProblemDetailsmethod is called.Verification
Packaging changes reviewed?