Skip to content

Commit 58fbeb5

Browse files
committed
fix: support validations of integer type
1 parent d633b46 commit 58fbeb5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/utils/__tests__/getValidations.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@ describe('getValidations util', () => {
1717
expect(getValidations({})).toStrictEqual({});
1818
});
1919
});
20+
21+
test('should support integer type', () => {
22+
expect(
23+
getValidations({
24+
type: 'integer',
25+
minimum: 2,
26+
exclusiveMaximum: true,
27+
maximum: 20,
28+
multipleOf: 2,
29+
}),
30+
).toStrictEqual({
31+
exclusiveMaximum: true,
32+
maximum: 20,
33+
minimum: 2,
34+
multipleOf: 2,
35+
});
36+
});
2037
});

src/utils/getValidations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const COMMON_VALIDATION_TYPES = [
1818
const VALIDATION_TYPES = {
1919
string: ['minLength', 'maxLength', 'pattern'],
2020
number: ['multipleOf', 'minimum', 'exclusiveMinimum', 'maximum', 'exclusiveMaximum'],
21+
get integer() {
22+
return this.number;
23+
},
2124
object: ['additionalProperties', 'minProperties', 'maxProperties'],
2225
array: ['additionalItems', 'minItems', 'maxItems', 'uniqueItems'],
2326
};

0 commit comments

Comments
 (0)