Skip to content

Commit 9bdc120

Browse files
committed
feat: Recognize integer format 'int64' as no-op
1 parent 765aa89 commit 9bdc120

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ private record NumberFormatCheck(DoublePredicate isValid, String message) {}
8585
Map.of(
8686
"int32",
8787
new IntegerFormatCheck(
88-
n -> n >= Integer.MIN_VALUE && n <= Integer.MAX_VALUE,
89-
"value does not fit in int32"));
88+
n -> n >= Integer.MIN_VALUE && n <= Integer.MAX_VALUE, "value does not fit in int32"),
89+
"int64",
90+
new IntegerFormatCheck(n -> true, "value does not fit in int64"));
9091

9192
private static final Map<String, NumberFormatCheck> NUMBER_FORMAT_CHECKS = Map.of();
9293

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ void stringFormatUnknownIsIgnored() {
242242
assertThatCode(() -> v.validate("anything", s, "/v")).doesNotThrowAnyException();
243243
}
244244

245+
@Test
246+
void integerFormatInt64AcceptsAnyLong() {
247+
IntegerSchema s =
248+
new IntegerSchema(Set.of(TypeName.INTEGER), null, null, null, null, null, "int64");
249+
assertThatCode(() -> v.validate(Long.MAX_VALUE, s, "/v")).doesNotThrowAnyException();
250+
assertThatCode(() -> v.validate(Long.MIN_VALUE, s, "/v")).doesNotThrowAnyException();
251+
assertThatCode(() -> v.validate(0L, s, "/v")).doesNotThrowAnyException();
252+
assertThatCode(() -> v.validate(123L, s, "/v")).doesNotThrowAnyException();
253+
}
254+
245255
@Test
246256
void integerFormatInt32() {
247257
IntegerSchema s =

0 commit comments

Comments
 (0)