Add configure-once ProblemDetails customization for Minimal API#256
Open
inghamc wants to merge 1 commit into
Open
Add configure-once ProblemDetails customization for Minimal API#256inghamc wants to merge 1 commit into
inghamc wants to merge 1 commit into
Conversation
ToMinimalApiResult hard-codes the ProblemDetails Title and the "Next error(s) occurred:" Detail prefix, with no way to override them for Minimal API (unlike controllers, which have AddResultConvention). Add an opt-in ResultProblemDetailsOptions.Customize hook, invoked with a ResultProblemDetailsContext (status, status code, result, ProblemDetails) for every error-class result before it is returned. Defaults to null, so existing output is unchanged; set it once at startup to adjust Title, Detail, Extensions, etc. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Addresses #244, and lets consumers resolve #124 and #126 themselves.
ToMinimalApiResulthard-codes theProblemDetailsTitleand the"Next error(s) occurred:"Detailprefix, with no Minimal API customization hook (controllers haveAddResultConvention; the Minimal API path never got an equivalent — see #244).This adds an opt-in, configure-once hook:
The hook receives a
ResultProblemDetailsContext(result status, HTTP status code, the result, and theProblemDetails) for every error-class result before it is returned. It defaults tonull, so existing output is byte-for-byte unchanged.Design note: this mirrors ASP.NET Core's
CustomizeProblemDetails(Action<context>)idiom, but as a static configure-once hook because the Minimal API conversion runs without anHttpContext/ DI. Happy to switch to a per-call overload or a DI-based variant if you'd prefer. Tested on net6.0 / net7.0 / net8.0.🤖 Generated with Claude Code