Skip to content

Commit 5b3c2db

Browse files
Merge pull request #1367 from open-circle/copilot/support-min-value-integer
Support integer type for min_value and max_value actions
2 parents 838cad3 + 287733e commit 5b3c2db

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

packages/to-json-schema/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to the library will be documented in this file.
55
## vX.X.X (Month DD, YYYY)
66

77
- Add support for `examples` action
8+
- Add support for `integer` when used with `minValue` and `maxValue` actions (pull request #1367)
89
- Fix conversion of `exactOptional` object properties (pull request #1220)
910
- Fix conversion of `variant` to use `oneOf` instead of `anyOf` (pull request #1193)
1011

packages/to-json-schema/src/converters/convertAction/convertAction.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,19 @@ describe('convertAction', () => {
460460
});
461461
});
462462

463+
test('should convert max value action for integers', () => {
464+
expect(
465+
convertAction(
466+
{ type: 'integer' },
467+
v.maxValue<v.ValueInput, 100>(100),
468+
undefined
469+
)
470+
).toStrictEqual({
471+
type: 'integer',
472+
maximum: 100,
473+
});
474+
});
475+
463476
test('should throw error for max value action with invalid type', () => {
464477
const action = v.maxValue<v.ValueInput, 3>(3);
465478
const error1 =
@@ -629,6 +642,19 @@ describe('convertAction', () => {
629642
});
630643
});
631644

645+
test('should convert min value action for integers', () => {
646+
expect(
647+
convertAction(
648+
{ type: 'integer' },
649+
v.minValue<v.ValueInput, 1>(1),
650+
undefined
651+
)
652+
).toStrictEqual({
653+
type: 'integer',
654+
minimum: 1,
655+
});
656+
});
657+
632658
test('should throw error for min value action with invalid type', () => {
633659
const action = v.minValue<v.ValueInput, 3>(3);
634660
const error1 =

packages/to-json-schema/src/converters/convertAction/convertAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function convertAction(
261261
}
262262

263263
case 'max_value': {
264-
if (jsonSchema.type !== 'number') {
264+
if (jsonSchema.type !== 'number' && jsonSchema.type !== 'integer') {
265265
errors = addError(
266266
errors,
267267
`The "max_value" action is not supported on type "${jsonSchema.type}".`
@@ -313,7 +313,7 @@ export function convertAction(
313313
}
314314

315315
case 'min_value': {
316-
if (jsonSchema.type !== 'number') {
316+
if (jsonSchema.type !== 'number' && jsonSchema.type !== 'integer') {
317317
errors = addError(
318318
errors,
319319
`The "min_value" action is not supported on type "${jsonSchema.type}".`

0 commit comments

Comments
 (0)