-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Support input validation for minimal APIs via generic resolver model #60724
base: main
Are you sure you want to change the base?
Conversation
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.
PR Overview
This PR implements a generic DataAnnotations‐based validation resolver model for minimal APIs. It introduces new types and interfaces for representing validatable types and parameters, registers validation services via DI, and adds tests to confirm the resolver chain order.
Reviewed Changes
File | Description |
---|---|
src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/ISymbolExtensions.cs | Provides an extension to extract display names from attributes. |
src/Http/Http.Abstractions/src/Validation/ValidatableTypeInfo.cs | Implements core validation logic for types including recursive validation with depth tracking. |
src/Http/Http.Abstractions/src/Validation/ValidatableParameterInfo.cs | Adds parameter validation logic using DataAnnotations attributes. |
src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.ValidationsGenerator/Extensions/IncrementalValuesProviderExtensions.cs | Introduces extension methods (Distinct, Concat) for incremental values. |
src/Http/Http.Abstractions/src/Validation/ValidationServiceCollectionExtensions.cs | Provides DI registration extension for validation services. |
src/Http/Http.Abstractions/src/Validation/ValidatableContext.cs | Manages validation error storage and tracking of nested validation depth. |
src/Http/Http.Abstractions/src/Validation/IValidatableInfoResolver.cs | Defines the interface for resolving validation metadata. |
src/Http/Http.Abstractions/src/Validation/ValidatableTypeAttribute.cs | Introduces an attribute to mark validatable types. |
src/Http/Http.Abstractions/src/Validation/ValidatablePropertyInfo.cs | Encapsulates member validation logic. |
src/Http/Http.Abstractions/test/ValidatableInfoResolverTests.cs | Adds tests to verify resolver chain behavior and proper resolution of metadata. |
src/Http/Http.Abstractions/src/Validation/ValidationOptions.cs | Configures maximum depth and chains resolvers for validation. |
(Other generated model files) | Define source-generated types for validation metadata. |
Copilot reviewed 44 out of 44 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/Http/Http.Abstractions/src/Validation/ValidatablePropertyInfo.cs:121
- The use of [result!.ErrorMessage!] to create an array is not standard C# syntax. Please update this to use a proper array initializer like 'new string[] { result!.ErrorMessage! }'.
context.AddValidationError(context.Prefix, [result!.ErrorMessage!]);
Implements generic DataAnnotations-based validations resolver model and consumption in minimal APIs.
Guide for reviewers:
Http.Abstractions
contains the default implementation of methods that execute validationValidationsGenerator
is the source generator that statically discoves validatable types and emits a compile-time generatedIValidatableInfoResolver
Http.Extensions/test
validate end-to-end behavior in minimal APIs and include snapshots for generated codeHttp.Abstractions/test
validate the runtime behavior of the validate APIsAddress #46349.