55using System . Collections . Immutable ;
66using System . Linq ;
77using Microsoft . AspNetCore . Analyzers . Infrastructure ;
8+ using Microsoft . AspNetCore . Analyzers . RouteEmbeddedLanguage . Infrastructure ;
89using Microsoft . AspNetCore . App . Analyzers . Infrastructure ;
910using Microsoft . AspNetCore . Http . RequestDelegateGenerator . StaticRouteHandlerModel ;
1011using Microsoft . CodeAnalysis ;
@@ -30,6 +31,8 @@ internal ImmutableArray<ValidatableType> ExtractValidatableTypes(IInvocationOper
3031 WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_Metadata_IFromServiceMetadata ) ;
3132 var fromKeyedServiceAttributeSymbol = wellKnownTypes . Get (
3233 WellKnownTypeData . WellKnownType . Microsoft_Extensions_DependencyInjection_FromKeyedServicesAttribute ) ;
34+ var skipValidationAttributeSymbol = wellKnownTypes . Get (
35+ WellKnownTypeData . WellKnownType . Microsoft_Extensions_Validation_SkipValidationAttribute ) ;
3336
3437 var validatableTypes = new HashSet < ValidatableType > ( ValidatableTypeComparer . Instance ) ;
3538 List < ITypeSymbol > visitedTypes = [ ] ;
@@ -42,6 +45,12 @@ internal ImmutableArray<ValidatableType> ExtractValidatableTypes(IInvocationOper
4245 continue ;
4346 }
4447
48+ // Skip method parameter if it or its type are annotated with SkipValidationAttribute
49+ if ( parameter . IsSkippedValidationParameter ( skipValidationAttributeSymbol ) )
50+ {
51+ continue ;
52+ }
53+
4554 _ = TryExtractValidatableType ( parameter . Type , wellKnownTypes , ref validatableTypes , ref visitedTypes ) ;
4655 }
4756 return [ .. validatableTypes ] ;
@@ -122,6 +131,8 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
122131 WellKnownTypeData . WellKnownType . Microsoft_Extensions_DependencyInjection_FromKeyedServicesAttribute ) ;
123132 var jsonIgnoreAttributeSymbol = wellKnownTypes . Get (
124133 WellKnownTypeData . WellKnownType . System_Text_Json_Serialization_JsonIgnoreAttribute ) ;
134+ var skipValidationAttributeSymbol = wellKnownTypes . Get (
135+ WellKnownTypeData . WellKnownType . Microsoft_Extensions_Validation_SkipValidationAttribute ) ;
125136
126137 // Special handling for record types to extract properties from
127138 // the primary constructor.
@@ -156,6 +167,12 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
156167 continue ;
157168 }
158169
170+ // Skip primary constructor parameter if it or its type are annotated with SkipValidationAttribute
171+ if ( parameter . IsSkippedValidationParameter ( skipValidationAttributeSymbol ) )
172+ {
173+ continue ;
174+ }
175+
159176 // Skip properties that are not accessible from generated code
160177 if ( correspondingProperty . DeclaredAccessibility is not Accessibility . Public )
161178 {
@@ -218,6 +235,12 @@ internal ImmutableArray<ValidatableProperty> ExtractValidatableMembers(ITypeSymb
218235 continue ;
219236 }
220237
238+ // Skip property if it or its type are annotated with SkipValidationAttribute
239+ if ( member . IsSkippedValidationProperty ( skipValidationAttributeSymbol ) )
240+ {
241+ continue ;
242+ }
243+
221244 var hasValidatableType = TryExtractValidatableType ( member . Type , wellKnownTypes , ref validatableTypes , ref visitedTypes ) ;
222245 var attributes = ExtractValidationAttributes ( member , wellKnownTypes , out var isRequired ) ;
223246
0 commit comments