Skip to content

Fix skipped and collection union cases in Minimal API validation - #69870

Merged
DeagleGross merged 2 commits into
dotnet:mainfrom
DeagleGross:deaglegross-minimal-api-union-validation
Oct 19, 2026
Merged

DeagleGross merged 2 commits into
dotnet:mainfrom
DeagleGross:deaglegross-minimal-api-union-validation

Conversation

@DeagleGross

@DeagleGross DeagleGross commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

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

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
Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:33
@DeagleGross DeagleGross self-assigned this Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 SkipValidation during union-case discovery.
  • Marks synthesized Value properties 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

@Youssef1313
Youssef1313 requested a review from oroztocil October 16, 2026 10:02
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
@DeagleGross
DeagleGross merged commit cad4d7d into dotnet:main Oct 19, 2026
29 checks passed
@DeagleGross

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

✅ 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

  • Conceptual article: Not required — Bug fix in the validation generator for union cases; no public API or configuration change; signals showed no_signal.
  • Migration guidance: Not required — No action needed by users upgrading.
  • Breaking change: Not required — No concrete compatibility impact evidenced.

wtgodbe pushed a commit that referenced this pull request Oct 19, 2026
) (#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
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 30, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 988ca02d Deployed Oct 19, 2026 by DeagleGross via conclusion #70
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.

Support unions in ValidationsGenerator

3 participants