-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor result extensions with RFC7807 problem details support #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…TTP 403 fix Split the monolithic ResultExtensions class into separate concerns: - MinimalApiResultExtensions: Converts Result types to IResult for minimal APIs - MvcResultExtensions: Converts Result types to IActionResult for MVC controllers Key improvements: - Add RFC7807 Problem Details support via useProblemDetails parameter (default: true) - ValidationErrorExtensions provides error dictionary conversion for problem details - Fix HTTP status code for authorization failures: use 403 Forbidden instead of 401 - Both extensions support legacy responses when useProblemDetails=false - Comprehensive test coverage for all result types and response formats Example usage: - Add example minimal API endpoints at /minimal-apis/results/ - Add example MVC controller at /mvc/results/ - Register controllers and endpoints in Program.cs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Test Results133 tests +31 133 ✅ +33 0s ⏱️ ±0s Results for commit fb88366. ± Comparison against base commit b204dbd. This pull request removes 34 and adds 65 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request refactors the result extension methods by splitting them into separate files for MVC and Minimal API approaches, and adds support for RFC 7807 Problem Details responses.
- Splits
ResultExtensions.csintoMvcResultExtensions.csandMinimalApiResultExtensions.csfor better separation of concerns - Adds optional
useProblemDetailsparameter (defaulting totrue) to enable RFC 7807 Problem Details format for error responses - Introduces
ValidationErrorExtensions.CreateErrorDictionarymethod for converting validation errors to the dictionary format required by Minimal API's ValidationProblem - Adds example endpoints demonstrating both MVC and Minimal API approaches
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/F23.Kernel/ValidationErrorExtensions.cs |
New extension method to convert validation errors to dictionary format for Minimal API ValidationProblem support |
src/F23.Kernel.AspNetCore/ResultExtensions.cs |
Removed - split into separate MVC and Minimal API files |
src/F23.Kernel.AspNetCore/MvcResultExtensions.cs |
New file containing MVC-specific result extensions with Problem Details support |
src/F23.Kernel.AspNetCore/MinimalApiResultExtensions.cs |
New file containing Minimal API-specific result extensions with Problem Details support |
src/F23.Kernel.Tests/AspNetCore/ResultExtensionsTests.cs |
Removed - split into separate test files |
src/F23.Kernel.Tests/AspNetCore/MvcResultExtensionsTests.cs |
New comprehensive test file for MVC result extensions including Problem Details tests |
src/F23.Kernel.Tests/AspNetCore/MinimalApiResultExtensionsTests.cs |
New test file for Minimal API result extensions with basic Problem Details coverage |
src/F23.Kernel.Examples.AspNetCore/Program.cs |
Updated to register controllers and map result endpoints |
src/F23.Kernel.Examples.AspNetCore/Infrastructure/ResultsController.cs |
New MVC controller demonstrating various result types |
src/F23.Kernel.Examples.AspNetCore/Core/ResultsEndpoints.cs |
New Minimal API endpoints demonstrating various result types |
.gitignore |
Added IDE-specific ignore patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Improve CreateErrorDictionary to properly handle and accumulate multiple errors with the same key into arrays. This is critical for RFC7807 problem details format where validation fields may have multiple error messages. Changes: - Handle duplicate keys by appending messages to existing array - Use case-sensitive comparison (StringComparer.Ordinal) - Efficient array allocation strategy - Add comprehensive unit tests for all scenarios Tests cover: - Single error per key - Multiple errors with different keys - Multiple errors with same key (accumulation) - Mixed single and multiple errors - Empty collections and null validation - Case sensitivity verification - Error order preservation - Special character keys All 133 tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This PR refactors the result extension methods to support RFC7807 Problem Details format and fixes the incorrect HTTP status code for authorization failures.
Fixes #8 and #10
Changes
ResultExtensionsinto separate concerns:MinimalApiResultExtensions: Converts Result types to IResult for minimal APIsMvcResultExtensions: Converts Result types to IActionResult for MVC controllersuseProblemDetailsparameter (default: true)ValidationErrorExtensionsutility class for standardized error conversionuseProblemDetails=falseTest plan
/minimal-apis/results/demonstrate all result types/mvc/results/demonstrate all result types🤖 Generated with Claude Code