Repository navigation
Fix skipped and collection union cases in Minimal API validation - #69870
DeagleGross merged 2 commits into
Conversation
Respect SkipValidation when discovering union alternatives and use the active case type for collection traversal through the synthesized Value property. Cover sync/async validation and endpoint responses with regression tests. Co-authored-by: Copilot App <[email protected]> Copilot-Session: f20efd42-f75e-4e3b-be78-32f9211c50d4
There was a problem hiding this comment.
🟡 Changes recommended
Collection traversal bypasses case suppression and existing collection-level validators.
4 open findings
What changed in this PR
Updates Minimal API validation’s union support for #68268, covering skipped alternatives and collection-valued active cases.
Changes:
- Checks
SkipValidationduring union-case discovery. - Marks synthesized
Valueproperties for runtime collection detection. - Adds synchronous, asynchronous, and endpoint regression coverage; refreshes generated snapshots.
Paths below are relative to src/Validation/; snapshot filenames are under test/Microsoft.Extensions.Validation.GeneratorTests/snapshots/.
| File | Description |
|---|---|
test/Microsoft.Extensions.Validation.GeneratorTests/ValidationsGenerator.Union.cs |
Adds skipped-case and collection tests. |
ValidationsGeneratorTests.ValidatesPropertiesWithJsonIgnoreWhenWritingConditions#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.ValidatesInternalTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.SkipsNonReadableAndStaticProperties#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.SkipsIndexerPropertiesOnTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.SkipsFileLocalTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.SkipsClassesWithNonAccessibleTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.IValidatableObject_ReceivesValidatedInstanceAsObjectInstance#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.DoesNotEmitForExemptTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.DoesNotEmit_ForSkipValidationAttribute_OnRecordProperties#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.DoesNotEmit_ForSkipValidationAttribute_OnEndpointParameters#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.DoesNotEmit_ForSkipValidationAttribute_OnClassProperties#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateValidationAttributesOnClasses#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateUnionCollectionCases#ValidatableInfoResolver.g.verified.cs |
Adds collection-union baseline. |
ValidationsGeneratorTests.CanValidateUnionCases#ValidatableInfoResolver.g.verified.cs |
Marks synthesized union properties. |
ValidationsGeneratorTests.CanValidateTypeWithParsableProperties#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateRecursiveTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateRecordTypesWithAttribute#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateRecordTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateRecordStructTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidatePolymorphicTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateParametersFromDelegateVariableHandler#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateParameters#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateMultipleNamespaces#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateMembersOfParsableType#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateIValidatableObject#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateIValidatableObject_WithoutPropertyValidations#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateComplexTypesWithJsonIgnore#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateComplexTypes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanValidateClassTypesWithAttribute#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorTests.CanGenerateWhenAddValidationCalledMultipleTimes#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.TypeDisplayName_WithResourceType#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.TypeDisplayName_WithNameOnly#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.TypeDisplayName_WithDisplayNameAttribute#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.RecordPropertyDisplayName_WithResourceType#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.RecordPropertyDisplayName_WithNameOnly#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.RecordPropertyDisplayName_LiteralOnConstructorParameter#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_WithResourceType#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_WithResourceType_OnHiddenGenericProperty#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_WithoutDisplayAttribute_UsesPropertyName#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_WithNameOnly#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_WithDisplayNameAttribute#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_WithControlCharacters_EmitsValidLiteral#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_DisplayAttributeTakesPrecedenceOverDisplayNameAttribute#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.PropertyDisplayName_DisplayAttributeResourceTypeTakesPrecedenceOverDisplayNameAttribute#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.ParameterDisplayName_WithResourceType#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
ValidationsGeneratorDisplayNameTests.ParameterDisplayName_WithNameOnly#ValidatableInfoResolver.g.verified.cs |
Refreshes generated traversal. |
gen/Templates/ValidatablePropertyInfo.cs |
Uses active-case types for collection traversal. |
gen/Parsers/ValidationsGenerator.TypesParser.cs |
Checks suppression and identifies union properties. |
gen/Models/ValidatableProperty.cs |
Stores the union-property marker. |
gen/Emitters/ValidationsGenerator.Emitter.cs |
Emits the union-property marker. |
🧠 Review effort: Balanced
Carry skipped union case predicates into generated property metadata, check skipped element types before discovery, and validate collection cases themselves before traversing their elements. Add sync/async and endpoint regression coverage, and fix construction of the Boolean union control. Co-authored-by: Copilot App <[email protected]> Copilot-Session: f20efd42-f75e-4e3b-be78-32f9211c50d4
|
/backport to release/11.0 |
|
Started backporting to |
|
✅ No documentation PR was created. Confidence that documentation is needed: 15% No docs needed: the change fixes SkipValidation and collection handling for union cases in the validation generator, with tests and snapshots only. Documentation surfaces considered
|
) (#69928) * Fix skipped and collection union cases in Minimal API validation Respect SkipValidation when discovering union alternatives and use the active case type for collection traversal through the synthesized Value property. Cover sync/async validation and endpoint responses with regression tests. Co-authored-by: Copilot App <[email protected]> * Preserve suppression and self-validation for union collections Carry skipped union case predicates into generated property metadata, check skipped element types before discovery, and validate collection cases themselves before traversing their elements. Add sync/async and endpoint regression coverage, and fix construction of the Boolean union control. Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: Korolev Dmitry <[email protected]> Copilot-Session: f20efd42-f75e-4e3b-be78-32f9211c50d4


Respect SkipValidation when discovering union alternatives and use the active case type for collection traversal through the synthesized Value property.
see #69834 (comment)
Fixes #68268
release/11.0 backport