diff --git a/src/Http/Http.Abstractions/src/Validation/RuntimeValidatableParameterInfoResolver.cs b/src/Http/Http.Abstractions/src/Validation/RuntimeValidatableParameterInfoResolver.cs index 0728c3ac8b8d..164058c14cde 100644 --- a/src/Http/Http.Abstractions/src/Validation/RuntimeValidatableParameterInfoResolver.cs +++ b/src/Http/Http.Abstractions/src/Validation/RuntimeValidatableParameterInfoResolver.cs @@ -14,7 +14,8 @@ namespace Microsoft.AspNetCore.Http.Validation; internal sealed class RuntimeValidatableParameterInfoResolver : IValidatableInfoResolver { - // TODO: the implementation currently relies on static discovery of types. + // TODO: The implementation currently relies on static discovery of types. + // See https://github.com/dotnet/aspnetcore/issues/61220 public bool TryGetValidatableTypeInfo(Type type, [NotNullWhen(true)] out IValidatableInfo? validatableInfo) { validatableInfo = null; @@ -76,17 +77,7 @@ private static bool IsClass(Type type) { // Skip primitives, enums, common built-in types, and types that are specially // handled by RDF/RDG that don't need validation if they don't have attributes - if (type.IsPrimitive || - type.IsEnum || - type == typeof(string) || - type == typeof(decimal) || - type == typeof(DateTime) || - type == typeof(DateTimeOffset) || - type == typeof(TimeOnly) || - type == typeof(DateOnly) || - type == typeof(TimeSpan) || - type == typeof(Guid) || - type == typeof(IFormFile) || + if (type == typeof(IFormFile) || type == typeof(IFormFileCollection) || type == typeof(IFormCollection) || type == typeof(HttpContext) || diff --git a/src/Http/Http.Abstractions/test/Validation/RuntimeValidatableParameterInfoResolverTests.cs b/src/Http/Http.Abstractions/test/Validation/RuntimeValidatableParameterInfoResolverTests.cs index e5f268ab4c32..b079237b1fd8 100644 --- a/src/Http/Http.Abstractions/test/Validation/RuntimeValidatableParameterInfoResolverTests.cs +++ b/src/Http/Http.Abstractions/test/Validation/RuntimeValidatableParameterInfoResolverTests.cs @@ -33,19 +33,8 @@ public void TryGetValidatableParameterInfo_WithNullName_ThrowsInvalidOperationEx } [Theory] - [InlineData(typeof(string))] - [InlineData(typeof(int))] - [InlineData(typeof(bool))] - [InlineData(typeof(DateTime))] - [InlineData(typeof(Guid))] - [InlineData(typeof(decimal))] - [InlineData(typeof(DayOfWeek))] // Enum [InlineData(typeof(ClaimsPrincipal))] [InlineData(typeof(PipeReader))] - [InlineData(typeof(DateTimeOffset))] - [InlineData(typeof(TimeOnly))] - [InlineData(typeof(DateOnly))] - [InlineData(typeof(TimeSpan))] [InlineData(typeof(IFormFile))] [InlineData(typeof(IFormFileCollection))] [InlineData(typeof(IFormCollection))] diff --git a/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Parameters.cs b/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Parameters.cs index f05f80999147..bb96efc4e368 100644 --- a/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Parameters.cs +++ b/src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGenerator.Parameters.cs @@ -40,6 +40,7 @@ public async Task CanValidateParameters() [CustomValidation, Range(10, 100)] int value5 = 10, // Skipped from validation because it is marked as a [FromService] parameter [FromServices] [Range(10, 100)] int? value6 = 4, + [MinLength(7)] string? value7 = "LongEnough", Dictionary? testDict = null) => "OK"); app.Run(); @@ -59,7 +60,7 @@ public class TestService await VerifyEndpoint(compilation, "/params", async (endpoint, serviceProvider) => { var context = CreateHttpContext(serviceProvider); - context.Request.QueryString = new QueryString("?value1=5&value2=5&value3=&value4=3&value5=5"); + context.Request.QueryString = new QueryString("?value1=5&value2=5&value3=&value4=3&value5=5&value7=Short"); await endpoint.RequestDelegate(context); var problemDetails = await AssertBadRequest(context); Assert.Collection(problemDetails.Errors, @@ -94,6 +95,11 @@ await VerifyEndpoint(compilation, "/params", async (endpoint, serviceProvider) = { Assert.Equal("The field value5 must be between 10 and 100.", error); }); + }, + error => + { + Assert.Equal("value7", error.Key); + Assert.Equal("The field value7 must be a string or array type with a minimum length of '7'.", error.Value.Single()); }); }); }