@@ -10,6 +10,7 @@ import {
10
10
pluralizeType ,
11
11
serializeParameterValue ,
12
12
sortByRequired ,
13
+ humanizeNumberRange ,
13
14
} from '../' ;
14
15
15
16
import { FieldModel , OpenAPIParser , RedocNormalizedOptions } from '../../services' ;
@@ -410,6 +411,76 @@ describe('Utils', () => {
410
411
} ) ;
411
412
} ) ;
412
413
414
+ describe ( 'openapi humanizeNumberRange' , ( ) => {
415
+ it ( 'should return `>=` when only minimum value present or exclusiveMinimum = false' , ( ) => {
416
+ const expected = '>= 0' ;
417
+ expect ( humanizeNumberRange ( { minimum : 0 } ) ) . toEqual ( expected ) ;
418
+ expect ( humanizeNumberRange ( { minimum : 0 , exclusiveMinimum : false } ) ) . toEqual ( expected ) ;
419
+ } ) ;
420
+
421
+ it ( 'should return `>` when minimum value present and exclusiveMinimum set to true' , ( ) => {
422
+ expect ( humanizeNumberRange ( { minimum : 0 , exclusiveMinimum : true } ) ) . toEqual ( '> 0' ) ;
423
+ } ) ;
424
+
425
+ it ( 'should return `<=` when only maximum value present or exclusiveMinimum = false' , ( ) => {
426
+ const expected = '<= 10' ;
427
+ expect ( humanizeNumberRange ( { maximum : 10 } ) ) . toEqual ( expected ) ;
428
+ expect ( humanizeNumberRange ( { maximum : 10 , exclusiveMaximum : false } ) ) . toEqual ( expected ) ;
429
+ } ) ;
430
+
431
+ it ( 'should return `<` when maximum value present and exclusiveMaximum set to true' , ( ) => {
432
+ expect ( humanizeNumberRange ( { maximum : 10 , exclusiveMaximum : true } ) ) . toEqual ( '< 10' ) ;
433
+ } ) ;
434
+
435
+ it ( 'should return correct range for minimum and maximum values and with different exclusive set' , ( ) => {
436
+ expect ( humanizeNumberRange ( { minimum : 0 , maximum : 10 } ) ) . toEqual ( '[ 0 .. 10 ]' ) ;
437
+ expect (
438
+ humanizeNumberRange ( {
439
+ minimum : 0 ,
440
+ exclusiveMinimum : true ,
441
+ maximum : 10 ,
442
+ exclusiveMaximum : true ,
443
+ } ) ,
444
+ ) . toEqual ( '( 0 .. 10 )' ) ;
445
+ expect (
446
+ humanizeNumberRange ( {
447
+ minimum : 0 ,
448
+ maximum : 10 ,
449
+ exclusiveMaximum : true ,
450
+ } ) ,
451
+ ) . toEqual ( '[ 0 .. 10 )' ) ;
452
+ expect (
453
+ humanizeNumberRange ( {
454
+ minimum : 0 ,
455
+ exclusiveMinimum : true ,
456
+ maximum : 10 ,
457
+ } ) ,
458
+ ) . toEqual ( '( 0 .. 10 ]' ) ;
459
+ } ) ;
460
+
461
+ it ( 'should return correct range exclusive values only' , ( ) => {
462
+ expect ( humanizeNumberRange ( { exclusiveMinimum : 0 } ) ) . toEqual ( '> 0' ) ;
463
+ expect ( humanizeNumberRange ( { exclusiveMaximum : 10 } ) ) . toEqual ( '< 10' ) ;
464
+ expect ( humanizeNumberRange ( { exclusiveMinimum : 0 , exclusiveMaximum : 10 } ) ) . toEqual (
465
+ '( 0 .. 10 )' ,
466
+ ) ;
467
+ } ) ;
468
+
469
+ it ( 'should return correct min value' , ( ) => {
470
+ expect ( humanizeNumberRange ( { minimum : 5 , exclusiveMinimum : 10 } ) ) . toEqual ( '> 5' ) ;
471
+ expect ( humanizeNumberRange ( { minimum : - 5 , exclusiveMinimum : - 10 } ) ) . toEqual ( '> -10' ) ;
472
+ } ) ;
473
+
474
+ it ( 'should return correct max value' , ( ) => {
475
+ expect ( humanizeNumberRange ( { maximum : 10 , exclusiveMaximum : 15 } ) ) . toEqual ( '< 15' ) ;
476
+ expect ( humanizeNumberRange ( { maximum : - 10 , exclusiveMaximum : - 15 } ) ) . toEqual ( '< -10' ) ;
477
+ } ) ;
478
+
479
+ it ( 'should return undefined' , ( ) => {
480
+ expect ( humanizeNumberRange ( { } ) ) . toEqual ( undefined ) ;
481
+ } ) ;
482
+ } ) ;
483
+
413
484
describe ( 'openapi humanizeConstraints' , ( ) => {
414
485
const itemConstraintSchema = (
415
486
min ?: number ,
0 commit comments