Skip to content

Validation: skip static properties in generated model traversal#66728

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-static-properties-validation
Draft

Validation: skip static properties in generated model traversal#66728
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-static-properties-validation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Skip static properties during validation traversal

Description

Minimal API validation could recurse indefinitely when generated metadata included static self-referential properties (e.g., public static MyModel TheAnswer => new()). This change ensures static properties are ignored at runtime traversal, preventing false circular-depth failures.

  • Runtime behavior change

    • Added a static-getter guard in ValidatablePropertyInfo.ValidateAsync to skip validation for static properties.
  • Regression coverage

    • Added Validate_IgnoresStaticProperties to verify static self-referential metadata does not recurse.
    • Added Validate_ThrowsForRecursiveInstanceProperties as a control to confirm instance recursion behavior is unchanged (max-depth still enforced).
var property = DeclaringType.GetProperty(Name)
    ?? throw new InvalidOperationException(...);

if (property.GetMethod?.IsStatic is true)
{
    return;
}

@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label May 18, 2026
Copilot AI and others added 4 commits May 18, 2026 17:18
Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/a42125f4-648d-44d7-bc40-25b3e6a30e2b

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix validation generator to ignore static properties Validation: skip static properties in generated model traversal May 18, 2026
Copilot AI requested a review from Youssef1313 May 18, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft.Extensions.Validation.ValidationsGenerator - static properties cause circular reference

3 participants