You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
System.ComponentModel.DataAnnotations.RangeAttribute doesn't have constructor for decimal type. One of alternatives is to use constructor which accepts double values for boundaries. JSON schema generator tries to create instance of type using value provided as maximum boundary and fails if double value is greater than decimal.MaxValue with the following exception:
System.OverflowException: Value was either too large or too small for a Decimal.
in System.Decimal..ctor(Double value)
As far as I can tell it is common practice to use Range attribute with something like double.MaxValue if you only want to have lower limit on your value. Even (double)decimal.MaxValue would fail as the value produced after cast is actually greater than decimal.MaxValue.
The issue is easy to reproduce by creating Web API method with the following response class and trying to generate swagger spec in NSwagStudio:
using System.ComponentModel.DataAnnotations;
public class ResponseDto
{
[Range(0.0, double.MaxValue)]
public decimal AnyPositiveDecimal { get; set; }
}
The text was updated successfully, but these errors were encountered:
System.ComponentModel.DataAnnotations.RangeAttribute doesn't have constructor for
decimal
type. One of alternatives is to use constructor which acceptsdouble
values for boundaries. JSON schema generator tries to create instance of type using value provided as maximum boundary and fails ifdouble
value is greater thandecimal.MaxValue
with the following exception:As far as I can tell it is common practice to use
Range
attribute with something like double.MaxValue if you only want to have lower limit on your value. Even(double)decimal.MaxValue
would fail as the value produced after cast is actually greater thandecimal.MaxValue
.The issue is easy to reproduce by creating Web API method with the following response class and trying to generate swagger spec in NSwagStudio:
The text was updated successfully, but these errors were encountered: