Skip to content

HttpValidationProblemDetails helper#77

Merged
IeuanWalker merged 10 commits intomasterfrom
BadRequests
Jan 26, 2026
Merged

HttpValidationProblemDetails helper#77
IeuanWalker merged 10 commits intomasterfrom
BadRequests

Conversation

@IeuanWalker
Copy link
Owner

Easily add/ builder errors and return the standard ProblemHttpResult

IeuanWalker and others added 2 commits January 26, 2026 19:23
Introduced the ValidationErrors<T> class to manage and collect validation errors in ASP.NET Core minimal APIs. This class supports adding errors by property (via expressions or string keys), checking for errors, and converting them to standardized HTTP problem responses. Includes helper methods for property path extraction and example usage in exception handling. Also added an unrelated placeholder Class1.
Introduce /ValidationErrors endpoint returning standardized validation errors.
Update OpenAPI spec and operation IDs. Add RequestModel for sample errors.
Implement integration and unit tests for endpoint and ValidationErrors<T> class,
covering error addition, nested properties, and problem details response.
Copy link
Contributor

Copilot AI left a 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 PR introduces a ValidationErrors<T> helper class to streamline the creation of validation error responses in ASP.NET Core Minimal APIs. The helper provides a fluent API for building HttpValidationProblemDetails responses with strongly-typed property path expressions, making it easier to return standardized validation errors from endpoints.

Changes:

  • Added ValidationErrors<T> class with fluent API for building validation error responses
  • Included comprehensive unit tests for the new helper class
  • Added example endpoint demonstrating usage patterns
  • Updated OpenAPI documentation snapshots to reflect the new example endpoint

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/IeuanWalker.MinimalApi.Endpoints/ValidationErrors.cs Core implementation of the ValidationErrors helper class with expression-based property path resolution
tests/IeuanWalker.MinimalApi.Endpoints.Tests/ValidationErrorsTests.cs Comprehensive unit tests covering HasErrors, Add methods, expression handling, and response generation
example/ExampleApi/Endpoints/Validation/GetValidationErrors/GetValidationErrorsEndpoint.cs Example endpoint demonstrating ValidationErrors usage with nested properties
example/ExampleApi/Endpoints/Validation/GetValidationErrors/RequestModel.cs Request model for the example endpoint
tests/ExampleApi.IntegrationTests/Endpoints/Validation/ValidationErrorsTests.cs Integration test verifying end-to-end behavior and proper HTTP response format
tests/ExampleApi.IntegrationTests/ExpectedOpenApi.json Updated OpenAPI specification including the new endpoint and adjusted operation IDs
tests/ExampleApi.IntegrationTests/Infrastructure/OpenApiTests.Validation.cs Updated OpenAPI validation test with new endpoint entry and sequential operation ID adjustments
ValidationErrors.cs Extraneous template file that should be removed

Add ValidateMessages to ensure at least one message is provided when adding errors in ValidationErrors<T>. Update both Add overloads to use this check. Add unit tests to confirm ArgumentException is thrown when no messages are supplied.
Enforce non-empty key in ValidationErrors<T>.Add by throwing
ArgumentNullException for null, empty, or whitespace keys.
Add theory-based unit tests to verify exception behavior.
Deleted commented-out code mapping exceptions to validation error responses for UPRN, easting, and northing fields. The main ValidationErrors<T> class remains unchanged.
Deleted Class1 and its constructor from ValidationErrors.cs, leaving the file empty. This cleans up unused code.
Added detailed XML documentation comments to the ValidationErrors<T> class and its public methods, describing their purpose, parameters, return values, and exceptions. These changes improve code readability and developer guidance without affecting functionality.
Refactor GetPropertyPath to safely handle indexer expressions by
checking for direct member access before casting. Now throws a clear
exception for unsupported indexer usage, preventing invalid casts and
improving error messages.
@IeuanWalker IeuanWalker requested a review from Copilot January 26, 2026 21:36
@IeuanWalker IeuanWalker marked this pull request as ready for review January 26, 2026 21:40
Copy link
Contributor

Copilot AI left a 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 7 out of 7 changed files in this pull request and generated 2 comments.

Enhanced ValidationErrors<T> to correctly generate property paths for nested indexers and collection items. Added comprehensive unit tests for nested indexers, object properties, and list items. Expanded test models to support new test scenarios.
Copy link
Contributor

Copilot AI left a 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 7 out of 7 changed files in this pull request and generated no new comments.

Previously, assembly loading for system, ASP.NET Core, and FluentValidation references was wrapped in try-catch blocks to silently skip missing assemblies. Now, exceptions will be thrown if an assembly fails to load, making errors more visible during test setup.
@github-actions
Copy link

Summary

Summary
Generated on: 1/26/2026 - 10:23:47 PM
Coverage date: 1/26/2026 - 10:23:35 PM - 1/26/2026 - 10:23:39 PM
Parser: MultiReport (4x Cobertura)
Assemblies: 3
Classes: 83
Files: 70
Line coverage: 90.1% (5172 of 5735)
Covered lines: 5172
Uncovered lines: 563
Coverable lines: 5735
Total lines: 9736
Branch coverage: 83% (2450 of 2949)
Covered branches: 2450
Total branches: 2949
Method coverage: Feature is only available for sponsors
Tag: 390_21376228380

Coverage

ExampleApi - 97%
Name Line Branch
ExampleApi 97% 78.5%
ExampleApi.Data.InMemoryTodoStore 100% 100%
ExampleApi.EndpointExtensions 95.6%
ExampleApi.Endpoints.Enum.PostFromBody.RequestModelValidator 100%
ExampleApi.Endpoints.FileHandling.PostListOfFiles.PostFileHandlingListOfFil
esEndpoint
100%
ExampleApi.Endpoints.FileHandling.PostMultipart.PostFileHandlingMultipartEn
dpoint
100% 66.6%
ExampleApi.Endpoints.FileHandling.PostSingleFile.PostFileHandlingSingleFile
Endpoint
100%
ExampleApi.Endpoints.Todos.Delete.DeleteTodoEndpoint 100%
ExampleApi.Endpoints.Todos.GetAll.GetAllTodosEndpoint 100%
ExampleApi.Endpoints.Todos.GetById.GetTodoByIdEndpoint 100% 100%
ExampleApi.Endpoints.Todos.GetExport.GetExportEndpoint 100% 83.3%
ExampleApi.Endpoints.Todos.Patch.PatchTodoEndpoint 100% 100%
ExampleApi.Endpoints.Todos.Post.PostTodoEndpoint 100%
ExampleApi.Endpoints.Todos.Post.RequestModelValidator 100%
ExampleApi.Endpoints.Todos.Post.ResponseModel 100%
ExampleApi.Endpoints.Todos.Put.PutTodoEndpoint 100% 100%
ExampleApi.Endpoints.TypeExamples.TypeExamplesEndpointGroup 100%
ExampleApi.Endpoints.Validation.GetDataAnnotationsFromQuery.GetFluentValida
tionFromQuery
0%
ExampleApi.Endpoints.Validation.GetFluentValidationFromQuery.GetFluentValid
ationFromQuery
0%
ExampleApi.Endpoints.Validation.GetFluentValidationFromQuery.RequestModelVa
lidator
98% 0%
ExampleApi.Endpoints.Validation.GetValidationErrors.GetValidationErrorsEndp
oint
100%
ExampleApi.Endpoints.Validation.PostDataAnnotationsFromBody.PostDataValidat
ionEndpoint
0%
ExampleApi.Endpoints.Validation.PostFluentValidation.NestedObjectModelValid
ator
100% 50%
ExampleApi.Endpoints.Validation.PostFluentValidation.PostFluentValidationEn
dpoint
0%
ExampleApi.Endpoints.Validation.PostFluentValidation.RequestModelValidator 100% 100%
ExampleApi.Endpoints.Validation.PostFluentValidationFromFrom.PostFluentVali
dationFromFromEndpoint
0%
ExampleApi.Endpoints.WeatherForecast.Get.V1.GetWeatherForecastEndpoint 100%
ExampleApi.Endpoints.WeatherForecast.Get.V2.GetWeatherForecastEndpoint 100%
Program 100%
IeuanWalker.MinimalApi.Endpoints - 87.2%
Name Line Branch
IeuanWalker.MinimalApi.Endpoints 87.2% 82.1%
IeuanWalker.MinimalApi.Endpoints.Extensions.StringExtensions 100% 100%
IeuanWalker.MinimalApi.Endpoints.Filters.FluentValidationFilter`1 100% 100%
IeuanWalker.MinimalApi.Endpoints.FluentValidationEnumExtensions 100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.AuthorizationP
oliciesAndRequirementsOperationTransformer
100% 92.3%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.EndpointRequestTypeMapper
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.OpenApiPathMatcher
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.OpenApiSchemaHelper
97% 93%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.SchemaConstants
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.SchemaTypeResolver
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.EnumSchemaTransformer
100% 90%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.NullableSchemaReorderTransformer
100% 93.2%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.TypeDocumentTransformer
95% 90.7%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.UnusedComponentsCleanupTransformer
91.7% 83.6%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.AlterOperation
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.CustomRule`1
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.DescriptionRule
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.EmailRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.EnumRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.PatternRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.PropertyValidationBuilder`2
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RangeRule`1
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RemoveAllOperation
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RemoveOperation
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RequiredRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.StringLengthRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.UrlRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationConfiguration`1
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationConfigurationBuilder`1
97.4% 85.2%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationMetadata`1
100% 50%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationRule
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.RequestPropert
yEnhancer.ValidationDocumentTransformer
74.5% 69.4%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.SecurityScheme
Transformer
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.SecurityScheme
TransformerOptions
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiExtensions 93.1% 100%
IeuanWalker.MinimalApi.Endpoints.ValidationErrors`1 98.2% 95.8%
IeuanWalkerMinimalApiEndpoints.EndpointExtensions 0%
IeuanWalker.MinimalApi.Endpoints.Generator - 95.9%
Name Line Branch
IeuanWalker.MinimalApi.Endpoints.Generator 95.9% 88.8%
IeuanWalker.MinimalApi.Endpoints.Generator.AbstractValidatorInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.Block 100% 100%
IeuanWalker.MinimalApi.Endpoints.Generator.CachableLocation 100% 83.3%
IeuanWalker.MinimalApi.Endpoints.Generator.DiagnosticInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.EndpointGenerator 98.2% 86.7%
IeuanWalker.MinimalApi.Endpoints.Generator.EndpointGroupInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.EndpointInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.Extensions.SourceGeneratorExtens
ions
100% 92.3%
IeuanWalker.MinimalApi.Endpoints.Generator.Extensions.StringExtensions 100% 100%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.EndpointGeneratorHelpers 95.8% 95.6%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.HttpVerbRouteHelpers 93.6% 85.7%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.MapGroupHelpers 88.4% 78.8%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.RequestBindingTypeHelper
s
95.8% 92.6%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.ValidationHelpers 94.8% 90.9%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.WithNameHelpers 100% 91.6%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.WithTagsHelpers 94.3% 91.9%
IeuanWalker.MinimalApi.Endpoints.Generator.IndentedTextBuilder 100%
IeuanWalker.MinimalApi.Endpoints.Generator.TypeInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.ValidatorInfo 100%

@IeuanWalker IeuanWalker merged commit 2e9f486 into master Jan 26, 2026
1 check passed
@IeuanWalker IeuanWalker deleted the BadRequests branch January 26, 2026 22:25
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.

2 participants