Skip to content

Commit 8420742

Browse files
committed
feat: Recognize number format 'double' as no-op
1 parent ffac280 commit 8420742

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/com/retailsvc/http/validate/DefaultValidator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ private record NumberFormatCheck(DoublePredicate isValid, String message) {}
9494
"float",
9595
new NumberFormatCheck(
9696
n -> !Double.isNaN(n) && !Double.isInfinite(n) && Math.abs(n) <= Float.MAX_VALUE,
97-
"value does not fit in float"));
97+
"value does not fit in float"),
98+
"double",
99+
new NumberFormatCheck(n -> true, "value does not fit in double"));
98100

99101
private final Function<String, Schema> refResolver;
100102
private final ConcurrentMap<String, Pattern> compiledPatterns = new ConcurrentHashMap<>();

src/test/java/com/retailsvc/http/validate/StringIntegerNumberTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ void integerFormatInt32() {
266266
.isEqualTo("format");
267267
}
268268

269+
@Test
270+
void numberFormatDoubleAcceptsAnyDouble() {
271+
NumberSchema s =
272+
new NumberSchema(Set.of(TypeName.NUMBER), null, null, null, null, null, "double");
273+
assertThatCode(() -> v.validate(Double.MAX_VALUE, s, "/v")).doesNotThrowAnyException();
274+
assertThatCode(() -> v.validate(-Double.MAX_VALUE, s, "/v")).doesNotThrowAnyException();
275+
assertThatCode(() -> v.validate(0.0, s, "/v")).doesNotThrowAnyException();
276+
assertThatCode(() -> v.validate(1.5, s, "/v")).doesNotThrowAnyException();
277+
}
278+
269279
@Test
270280
void numberFormatFloat() {
271281
NumberSchema s =

0 commit comments

Comments
 (0)