Skip to content

Add configure-once ProblemDetails customization for Minimal API#256

Open
inghamc wants to merge 1 commit into
ardalis:mainfrom
inghamc:feature/customizable-minimal-api-problemdetails
Open

Add configure-once ProblemDetails customization for Minimal API#256
inghamc wants to merge 1 commit into
ardalis:mainfrom
inghamc:feature/customizable-minimal-api-problemdetails

Conversation

@inghamc

@inghamc inghamc commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Addresses #244, and lets consumers resolve #124 and #126 themselves.

ToMinimalApiResult hard-codes the ProblemDetails Title and the "Next error(s) occurred:" Detail prefix, with no Minimal API customization hook (controllers have AddResultConvention; the Minimal API path never got an equivalent — see #244).

This adds an opt-in, configure-once hook:

ResultProblemDetailsOptions.Customize = context =>
{
    context.ProblemDetails.Title = "...";                                      // e.g. localize (#126)
    context.ProblemDetails.Detail = string.Join("; ", context.Result.Errors); // drop the prefix (#124)
};

The hook receives a ResultProblemDetailsContext (result status, HTTP status code, the result, and the ProblemDetails) for every error-class result before it is returned. It defaults to null, 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 an HttpContext / 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

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>
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.

errorMessages should be passed as string

1 participant