ErrorOrX.Generators package provides a Roslyn source generator that converts ErrorOr<T> handlers into ASP.NET Core Minimal API endpoints.
What Gets Generated
Route Attributes
| Attribute | HTTP Method |
|---|---|
[Get("/path")] | GET |
[Post("/path")] | POST |
[Put("/path")] | PUT |
[Patch("/path")] | PATCH |
[Delete("/path")] | DELETE |
Parameter Binding
The generator infers parameter sources based on HTTP method and type.Binding Priority
| Priority | Condition | Binding |
|---|---|---|
| 1 | Explicit attribute ([FromBody], [FromServices], etc.) | As specified |
| 2 | Special types (HttpContext, CancellationToken) | Auto-detected |
| 3 | Parameter name matches route {param} | Route |
| 4 | Primitive type not in route | Query |
| 5 | Interface type | Service |
| 6 | Abstract type | Service |
| 7 | Service naming pattern | Service |
| 8 | POST/PUT/PATCH + complex type | Body |
| 9 | GET/DELETE + complex type | Error EOE025 |
| 10 | Fallback | Service |
Service Type Detection
These patterns are detected as service types:Complex Type on GET/DELETE
Complex types on GET/DELETE require explicit binding:Middleware Attributes
The generator emits middleware fluent calls since the wrapper delegate loses original method attributes:| Attribute | Generated Call |
|---|---|
[Authorize] | .RequireAuthorization() |
[Authorize("Policy")] | .RequireAuthorization("Policy") |
[EnableRateLimiting("Policy")] | .RequireRateLimiting("Policy") |
[OutputCache] | .CacheOutput() |
[EnableCors("Policy")] | .RequireCors("Policy") |
JSON Context Generation
Default Behavior
WhenErrorOrGenerateJsonContext is true (default):
With Custom Context
Disable generation and use your own:MSBuild Properties
| Property | Default | Purpose |
|---|---|---|
ErrorOrGenerateJsonContext | true | Generate JSON serialization context |
AOT Compatibility
The generator produces AOT-compatible code:- No
(Delegate)cast - Uses typedMapGet/MapPost - Wrapper pattern - Returns
Task, notTask<Results<...>> - Explicit
ExecuteAsync- Handles response serialization
API Versioning
SupportsAsp.Versioning.Http:
