diff --git a/Swashbuckle.Core/Swagger/SchemaExtensions.cs b/Swashbuckle.Core/Swagger/SchemaExtensions.cs index a1c5c63bd..2ea414c20 100644 --- a/Swashbuckle.Core/Swagger/SchemaExtensions.cs +++ b/Swashbuckle.Core/Swagger/SchemaExtensions.cs @@ -16,12 +16,10 @@ public static Schema WithValidationProperties(this Schema schema, JsonProperty j foreach (var attribute in propInfo.GetCustomAttributes(false)) { - var regex = attribute as RegularExpressionAttribute; - if (regex != null) + if (attribute is RegularExpressionAttribute regex) schema.pattern = regex.Pattern; - var range = attribute as RangeAttribute; - if (range != null) + if (attribute is RangeAttribute range) { int maximum; if (Int32.TryParse(range.Maximum.ToString(), out maximum)) @@ -32,12 +30,21 @@ public static Schema WithValidationProperties(this Schema schema, JsonProperty j schema.minimum = minimum; } - var length = attribute as StringLengthAttribute; - if (length != null) + if (attribute is StringLengthAttribute length) { schema.maxLength = length.MaximumLength; schema.minLength = length.MinimumLength; } + + if (attribute is MaxLengthAttribute maxLength) + { + schema.maxLength = maxLength.Length; + } + + if (attribute is MinLengthAttribute minLength) + { + schema.minLength = minLength.Length; + } } if (!jsonProperty.Writable) diff --git a/Swashbuckle.Core/Swashbuckle.Core.csproj b/Swashbuckle.Core/Swashbuckle.Core.csproj index d830ccbba..0f74fa450 100644 --- a/Swashbuckle.Core/Swashbuckle.Core.csproj +++ b/Swashbuckle.Core/Swashbuckle.Core.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,7 +9,7 @@ Properties Swashbuckle Swashbuckle.Core - v4.0 + v4.5 512 ..\ true @@ -43,22 +43,24 @@ - - ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll + + + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll - ..\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll - - ..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll + + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll + ..\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll @@ -124,8 +126,12 @@ Designer - - + + Designer + + + Designer + @@ -137,6 +143,11 @@ + + + + +