-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Implement runtime-based IValidatableTypeInfoResolver for minimal API validation #62497
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
base: main
Are you sure you want to change the base?
Conversation
Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
…tion Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
IValidatableTypeInfoResolver
implementation
@copilot Update the RuntimeValidatableTypeInfoResolverTests tests to use the validatable info types returned by cases that support them to validate actual test data. |
…t data Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Updated the RuntimeValidatableTypeInfoResolverTests to use the returned validatable info objects to validate actual test data. The tests now verify validation behavior with both valid and invalid data scenarios, ensuring the runtime resolver works correctly in practice. Commit ee9c087 |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
This PR implements a runtime implementation of
IValidatableTypeInfoResolver
to enable minimal-API validation when the source-generator path is unavailable (e.g., dynamic compilation, IDEs without generators, or environments where generators are turned off).Background
Previously, the validation system had:
Microsoft.AspNetCore.Http.ValidationsGenerator
source-generator for AOT-friendly static lookupsRuntimeValidatableParameterInfoResolver
for method parametersTryGetValidatableTypeInfo
was a stub that always returnedfalse
This left a gap where validation wouldn't work in dynamic scenarios without the generator.
Implementation
Core Components
RuntimeValidatableTypeInfoResolver
- Main resolver class that:ValidatableTypeInfo
graphs that mirror compile-time generator output[Required]
,[Range]
,[Display]
, etc.Cycle Prevention & Performance:
HashSet<Type>
tracking during discovery prevents infinite recursion (A ↔ B references)ConcurrentDictionary<Type, IValidatableInfo?>
for thread-safe cachingRegistration:
ValidationOptions.Resolvers
inAddValidation()
Example Usage
Testing
All tests pass and validate the expected behavior matches the original issue requirements.
Fixes #61220.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.