-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add JsonIgnore attribute support to Minimal API validation generator #63075
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
Changes from all commits
690e927
07e71a6
2247d7f
d038ce7
cabe2b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,8 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb | |
WellKnownTypeData.WellKnownType.Microsoft_AspNetCore_Http_Metadata_IFromServiceMetadata); | ||
var fromKeyedServiceAttributeSymbol = wellKnownTypes.Get( | ||
WellKnownTypeData.WellKnownType.Microsoft_Extensions_DependencyInjection_FromKeyedServicesAttribute); | ||
var jsonIgnoreAttributeSymbol = wellKnownTypes.Get( | ||
WellKnownTypeData.WellKnownType.System_Text_Json_Serialization_JsonIgnoreAttribute); | ||
|
||
// Special handling for record types to extract properties from | ||
// the primary constructor. | ||
|
@@ -148,6 +150,12 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb | |
continue; | ||
} | ||
|
||
// Skip properties that have JsonIgnore attribute | ||
if (correspondingProperty.IsJsonIgnoredProperty(jsonIgnoreAttributeSymbol)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a null check for Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
{ | ||
continue; | ||
} | ||
|
||
// Check if the property's type is validatable, this resolves | ||
// validatable types in the inheritance hierarchy | ||
var hasValidatableType = TryExtractValidatableType( | ||
|
@@ -186,6 +194,12 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb | |
continue; | ||
} | ||
|
||
// Skip properties that have JsonIgnore attribute | ||
if (member.IsJsonIgnoredProperty(jsonIgnoreAttributeSymbol)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a null check for Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
{ | ||
continue; | ||
} | ||
|
||
var hasValidatableType = TryExtractValidatableType(member.Type, wellKnownTypes, ref validatableTypes, ref visitedTypes); | ||
var attributes = ExtractValidationAttributes(member, wellKnownTypes, out var isRequired); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Not relevant for this change, but does this comparison work for derived types?
e.g.
MyFromKeyedServicesAttribute : FromKeyedServicesAttribute
See code a few lines above
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.
It won't, but
JsonIgnoreAttribute
is sealed so there's not likely to be derived types.FromKeyedServices
is not.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.
So we should update the keyed service check in a separate PR
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.
Yep -- we want to probably do an audit across the repo for anywhere we type check on
FromKeyedServices
andFromServices
since both of those are unsealed.