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