-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Skip non-public properties in validations generator #63076
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the validation generator to skip non-public properties and types during code generation, addressing issue #62757. The changes ensure that only publicly accessible members are included in the generated validation code.
Key Changes
- Modified the type parser to skip non-public types and properties in validation generation
- Updated test cases to verify that only public properties are included in generated validation code
- Added comprehensive test coverage for accessibility scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
ValidationsGenerator.TypesParser.cs |
Added accessibility checks to skip non-public types and properties during validation generation |
ValidationsGenerator.ComplexType.cs |
Added new test case to verify non-public properties are skipped while public properties remain validated |
ValidationsGeneratorTests.SkipsClassesWithNonAccessibleTypes#ValidatableInfoResolver.g.verified.cs |
New snapshot showing generated code only includes public properties |
ValidationsGeneratorTests.CanValidateParameters#ValidatableInfoResolver.g.verified.cs |
Updated snapshot removing non-public properties from Dictionary validation |
return false; | ||
} | ||
|
||
// Skip types that are not accessible from generated code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining why non-public types are skipped, as this is a significant behavioral change that affects which types get validation generation.
// Skip types that are not accessible from generated code | |
// Skip types that are not accessible from generated code | |
// Only public types are included for validation generation because generated code can only access public types. | |
// This is a significant behavioral decision: non-public types will not have validation generated. |
Copilot uses AI. Check for mistakes.
continue; | ||
} | ||
|
||
// Skip properties that are not accessible from generated code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining why non-public properties are skipped, similar to the type-level check, to maintain consistency in documentation.
// Skip properties that are not accessible from generated code | |
// Skip properties that are not accessible from generated code | |
// Only public properties can be accessed by generated code, so non-public properties are skipped. |
Copilot uses AI. Check for mistakes.
continue; | ||
} | ||
|
||
// Skip properties that are not accessible from generated code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining why non-public properties are skipped, to maintain consistency with the other accessibility checks in this file.
// Skip properties that are not accessible from generated code | |
// Skip properties that are not accessible from generated code | |
// Non-public properties are skipped because they cannot be accessed by the generated code. |
Copilot uses AI. Check for mistakes.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Non-public properties are validated at run-time still? Is there test coverage for that? |
I was specifically refering to types that are resolved from the DI container but not annotated with the app.MapGet("/", (CatalogDbContext dbContext) => ...); In the example above, there's no way to determine at compile-time that In this new model, we'll still create a |
Closes #62757.