@@ -90,22 +90,42 @@ internal static void ApplyValidationAttributes(this JsonNode schema, IEnumerable
90
90
}
91
91
else if ( attribute is RangeAttribute rangeAttribute )
92
92
{
93
- // Use InvariantCulture if explicitly requested or if the range has been set via the
94
- // RangeAttribute(double, double) or RangeAttribute(int, int) constructors.
95
- var targetCulture = rangeAttribute . ParseLimitsInInvariantCulture || rangeAttribute . Minimum is double || rangeAttribute . Maximum is int
96
- ? CultureInfo . InvariantCulture
97
- : CultureInfo . CurrentCulture ;
93
+ decimal ? minDecimal = null ;
94
+ decimal ? maxDecimal = null ;
98
95
99
- var minString = Convert . ToString ( rangeAttribute . Minimum , targetCulture ) ;
100
- var maxString = Convert . ToString ( rangeAttribute . Maximum , targetCulture ) ;
96
+ if ( rangeAttribute . Minimum is int minimumInteger )
97
+ {
98
+ // The range was set with the RangeAttribute(int, int) constructor.
99
+ minDecimal = minimumInteger ;
100
+ maxDecimal = ( int ) rangeAttribute . Maximum ;
101
+ }
102
+ else
103
+ {
104
+ // Use InvariantCulture if explicitly requested or if the range has been set via the RangeAttribute(double, double) constructor.
105
+ var targetCulture = rangeAttribute . ParseLimitsInInvariantCulture || rangeAttribute . Minimum is double x
106
+ ? CultureInfo . InvariantCulture
107
+ : CultureInfo . CurrentCulture ;
108
+
109
+ var minString = Convert . ToString ( rangeAttribute . Minimum , targetCulture ) ;
110
+ var maxString = Convert . ToString ( rangeAttribute . Maximum , targetCulture ) ;
111
+
112
+ if ( decimal . TryParse ( minString , NumberStyles . Any , targetCulture , out var value ) )
113
+ {
114
+ minDecimal = value ;
115
+ }
116
+ if ( decimal . TryParse ( maxString , NumberStyles . Any , targetCulture , out value ) )
117
+ {
118
+ maxDecimal = value ;
119
+ }
120
+ }
101
121
102
- if ( decimal . TryParse ( minString , NumberStyles . Any , targetCulture , out var minDecimal ) )
122
+ if ( minDecimal is { } minValue )
103
123
{
104
- schema [ rangeAttribute . MinimumIsExclusive ? OpenApiSchemaKeywords . ExclusiveMinimum : OpenApiSchemaKeywords . MinimumKeyword ] = minDecimal ;
124
+ schema [ rangeAttribute . MinimumIsExclusive ? OpenApiSchemaKeywords . ExclusiveMinimum : OpenApiSchemaKeywords . MinimumKeyword ] = minValue ;
105
125
}
106
- if ( decimal . TryParse ( maxString , NumberStyles . Any , targetCulture , out var maxDecimal ) )
126
+ if ( maxDecimal is { } maxValue )
107
127
{
108
- schema [ rangeAttribute . MaximumIsExclusive ? OpenApiSchemaKeywords . ExclusiveMaximum : OpenApiSchemaKeywords . MaximumKeyword ] = maxDecimal ;
128
+ schema [ rangeAttribute . MaximumIsExclusive ? OpenApiSchemaKeywords . ExclusiveMaximum : OpenApiSchemaKeywords . MaximumKeyword ] = maxValue ;
109
129
}
110
130
}
111
131
else if ( attribute is RegularExpressionAttribute regularExpressionAttribute )
0 commit comments