Add support for internal types in validation source generator (#65632)#66061
Open
XL1TTE wants to merge 5 commits intodotnet:mainfrom
Open
Add support for internal types in validation source generator (#65632)#66061XL1TTE wants to merge 5 commits intodotnet:mainfrom
XL1TTE wants to merge 5 commits intodotnet:mainfrom
Conversation
…#65632) Enable validation of internal request DTOs and properties through a new IncludeInternalTypes() configuration option. By default, the validation source generator only processes public types and members. This change adds an opt-in mechanism for applications that keep request models internal for encapsulation purposes. Usage: builder.Services.AddValidation(options => options.IncludeInternalTypes()); Added test coverage for internal types, internal properties, and verification that private/protected members remain excluded from validation.
Author
|
@dotnet-policy-service agree |
3 tasks
Update DynamicallyAccessedMembers annotations on generated code to satisfy NativeAOT trimming requirements. - **GeneratedValidatablePropertyInfo.ContainingType**: Changed from `PublicProperties|PublicConstructors` to `PublicProperties|NonPublicProperties` to match base class ValidatablePropertyInfo requirements - **ValidationAttributeCache.CacheKey.ContainingType**: Added `PublicConstructors|NonPublicConstructors` to support `GetConstructors()` calls that access both public and non-public constructors. - **ValidationAttributeCache.GetPropertyValidationAttributes**: Updated parameter annotation to include `PublicConstructors|NonPublicConstructors` for consistency with CacheKey. Should fix trimming errors **IL2067**, **IL2072**, and **IL2075** that occurred when building NativeAOT and trimming test projects.
2c36e9c to
d001b06
Compare
This was referenced Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for internal types in validation source generator (#65632)
This change adds an opt-in mechanism for applications that keep request models internal for encapsulation purposes.
Added test coverage for internal types, internal properties, and verification that private/protected members remain excluded from validation.
Description
By default, the validation source generator only processes public types and members. When
IncludeInternalTypes()call detected,ValidationsGeneratorwill start to include internal types and members to validation process.Added Tests
Internal Types Validation
InternalType_NotValidated_ByDefault[ValidatableType]attribute without configurationInternalType_Validated_With_IncludeInternalTypes[ValidatableType]attribute withIncludeInternalTypes()Internal Properties Validation
InternalProperty_NotValidated_ByDefault[Required]InternalProperty_Validated_With_IncludeInternalTypes[Required]withIncludeInternalTypes()Private and Protected Properties Validation
PrivateProperty_Never_Validated[Required]withIncludeInternalTypes()IncludeInternalTypes())ProtectedProperty_Never_Validated[Required]withIncludeInternalTypes()IncludeInternalTypes())Internal Nested Types Validation
InternalNestedType_Validated_With_IncludeInternalTypeIncludeInternalTypes()Configuration Syntax Validation
IncludeInternalTypes_BlockLambda_Supported{ options.IncludeInternalTypes(); }IncludeInternalTypes_ExpressionLambda_Supportedoptions => options.IncludeInternalTypes()Test Summary
IncludeInternalTypes()enables internal types and propertiesUsage:
Fixes #65632