apostrophe 3.58.1 → 3.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/modules/@apostrophecms/area/index.js +7 -0
- package/modules/@apostrophecms/asset/lib/webpack/apos/webpack.config.js +3 -0
- package/modules/@apostrophecms/doc-type/index.js +1 -0
- package/modules/@apostrophecms/doc-type/ui/apos/components/AposDocEditor.vue +11 -4
- package/modules/@apostrophecms/express/index.js +28 -0
- package/modules/@apostrophecms/modal/ui/apos/mixins/AposDocErrorsMixin.js +5 -4
- package/modules/@apostrophecms/modal/ui/apos/mixins/AposEditorMixin.js +11 -8
- package/modules/@apostrophecms/modal/ui/apos/mixins/AposModalTabsMixin.js +4 -3
- package/modules/@apostrophecms/module/index.js +6 -0
- package/modules/@apostrophecms/piece-page-type/index.js +9 -3
- package/modules/@apostrophecms/rich-text-widget/ui/apos/components/AposImageControlDialog.vue +10 -3
- package/modules/@apostrophecms/rich-text-widget/ui/apos/components/AposTiptapAnchor.vue +6 -1
- package/modules/@apostrophecms/rich-text-widget/ui/apos/components/AposTiptapLink.vue +12 -3
- package/modules/@apostrophecms/schema/index.js +105 -51
- package/modules/@apostrophecms/schema/ui/apos/components/AposArrayEditor.vue +3 -3
- package/modules/@apostrophecms/schema/ui/apos/components/AposInputArray.vue +10 -6
- package/modules/@apostrophecms/schema/ui/apos/components/AposInputObject.vue +5 -3
- package/modules/@apostrophecms/schema/ui/apos/components/AposInputRadio.vue +16 -11
- package/modules/@apostrophecms/schema/ui/apos/components/AposSchema.vue +2 -1
- package/modules/@apostrophecms/schema/ui/apos/components/AposSubform.vue +3 -3
- package/modules/@apostrophecms/schema/ui/apos/lib/conditionalFields.js +76 -71
- package/modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js +9 -1
- package/modules/@apostrophecms/schema/ui/apos/logic/AposInputArray.js +48 -20
- package/modules/@apostrophecms/schema/ui/apos/logic/AposInputDateAndTime.js +10 -1
- package/modules/@apostrophecms/schema/ui/apos/logic/AposInputObject.js +8 -3
- package/modules/@apostrophecms/schema/ui/apos/logic/AposInputRadio.js +3 -2
- package/modules/@apostrophecms/schema/ui/apos/logic/AposSchema.js +45 -25
- package/modules/@apostrophecms/schema/ui/apos/logic/AposSubform.js +4 -1
- package/modules/@apostrophecms/schema/ui/apos/mixins/AposInputConditionalFieldsMixin.js +11 -4
- package/modules/@apostrophecms/schema/ui/apos/mixins/AposInputFollowingMixin.js +1 -1
- package/modules/@apostrophecms/schema/ui/apos/mixins/AposInputMixin.js +4 -6
- package/modules/@apostrophecms/template/index.js +99 -31
- package/modules/@apostrophecms/widget-type/ui/apos/components/AposWidgetEditor.vue +5 -2
- package/package.json +1 -1
- package/test/schemas.js +1700 -0
package/test/schemas.js
CHANGED
|
@@ -2381,6 +2381,1706 @@ describe('Schemas', function() {
|
|
|
2381
2381
|
|
|
2382
2382
|
assert.deepEqual(actual, expected);
|
|
2383
2383
|
});
|
|
2384
|
+
|
|
2385
|
+
it('should enforce required property not equal match', async function() {
|
|
2386
|
+
const req = apos.task.getReq();
|
|
2387
|
+
const schema = apos.schema.compose({
|
|
2388
|
+
addFields: [
|
|
2389
|
+
{
|
|
2390
|
+
name: 'prop1',
|
|
2391
|
+
type: 'string',
|
|
2392
|
+
required: false
|
|
2393
|
+
},
|
|
2394
|
+
{
|
|
2395
|
+
name: 'requiredProp',
|
|
2396
|
+
type: 'integer',
|
|
2397
|
+
required: true,
|
|
2398
|
+
if: { prop1: { $ne: 'test' } }
|
|
2399
|
+
}
|
|
2400
|
+
]
|
|
2401
|
+
});
|
|
2402
|
+
const output = {};
|
|
2403
|
+
await apos.schema.convert(req, schema, {
|
|
2404
|
+
requiredProp: null,
|
|
2405
|
+
prop1: 'test'
|
|
2406
|
+
}, output);
|
|
2407
|
+
assert(!output.requiredProp);
|
|
2408
|
+
});
|
|
2409
|
+
|
|
2410
|
+
it('should error required property not equal match', async function() {
|
|
2411
|
+
const schema = apos.schema.compose({
|
|
2412
|
+
addFields: [
|
|
2413
|
+
{
|
|
2414
|
+
name: 'prop1',
|
|
2415
|
+
type: 'string',
|
|
2416
|
+
required: false
|
|
2417
|
+
},
|
|
2418
|
+
{
|
|
2419
|
+
name: 'requiredProp',
|
|
2420
|
+
type: 'integer',
|
|
2421
|
+
required: true,
|
|
2422
|
+
if: { prop1: { $ne: 'test' } }
|
|
2423
|
+
}
|
|
2424
|
+
]
|
|
2425
|
+
});
|
|
2426
|
+
await testSchemaError(schema, {
|
|
2427
|
+
requiredProp: null,
|
|
2428
|
+
prop1: 'test2'
|
|
2429
|
+
}, 'requiredProp', 'required');
|
|
2430
|
+
});
|
|
2431
|
+
|
|
2432
|
+
it('should enforce required property nested boolean', async function() {
|
|
2433
|
+
const req = apos.task.getReq();
|
|
2434
|
+
const schema = apos.schema.compose({
|
|
2435
|
+
addFields: [
|
|
2436
|
+
{
|
|
2437
|
+
name: 'prop1',
|
|
2438
|
+
type: 'object',
|
|
2439
|
+
required: false,
|
|
2440
|
+
fields: {
|
|
2441
|
+
add: {
|
|
2442
|
+
subfield: {
|
|
2443
|
+
type: 'boolean'
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
},
|
|
2447
|
+
schema: [
|
|
2448
|
+
{
|
|
2449
|
+
name: 'subfield',
|
|
2450
|
+
type: 'boolean'
|
|
2451
|
+
}
|
|
2452
|
+
]
|
|
2453
|
+
},
|
|
2454
|
+
{
|
|
2455
|
+
name: 'requiredProp',
|
|
2456
|
+
type: 'integer',
|
|
2457
|
+
required: true,
|
|
2458
|
+
if: {
|
|
2459
|
+
'prop1.subfield': true
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
]
|
|
2463
|
+
});
|
|
2464
|
+
const output = {};
|
|
2465
|
+
await apos.schema.convert(req, schema, {
|
|
2466
|
+
requiredProp: null,
|
|
2467
|
+
prop1: {
|
|
2468
|
+
subfield: false
|
|
2469
|
+
}
|
|
2470
|
+
}, output);
|
|
2471
|
+
console.log('output', require('util').inspect(output, {
|
|
2472
|
+
colors: true,
|
|
2473
|
+
depth: 1
|
|
2474
|
+
}));
|
|
2475
|
+
assert(!output.requiredProp);
|
|
2476
|
+
});
|
|
2477
|
+
|
|
2478
|
+
it('should error required property nested boolean', async function() {
|
|
2479
|
+
const schema = apos.schema.compose({
|
|
2480
|
+
addFields: [
|
|
2481
|
+
{
|
|
2482
|
+
name: 'prop1',
|
|
2483
|
+
type: 'object',
|
|
2484
|
+
required: false,
|
|
2485
|
+
fields: {
|
|
2486
|
+
add: {
|
|
2487
|
+
subfield: {
|
|
2488
|
+
type: 'boolean'
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
},
|
|
2492
|
+
schema: [
|
|
2493
|
+
{
|
|
2494
|
+
name: 'subfield',
|
|
2495
|
+
type: 'boolean'
|
|
2496
|
+
}
|
|
2497
|
+
]
|
|
2498
|
+
},
|
|
2499
|
+
{
|
|
2500
|
+
name: 'requiredProp',
|
|
2501
|
+
type: 'integer',
|
|
2502
|
+
required: true,
|
|
2503
|
+
if: {
|
|
2504
|
+
'prop1.subfield': true
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
]
|
|
2508
|
+
});
|
|
2509
|
+
await testSchemaError(schema, {
|
|
2510
|
+
requiredProp: null,
|
|
2511
|
+
prop1: {
|
|
2512
|
+
subfield: true
|
|
2513
|
+
}
|
|
2514
|
+
}, 'requiredProp', 'required');
|
|
2515
|
+
});
|
|
2516
|
+
|
|
2517
|
+
it('should enforce required property nested string', async function() {
|
|
2518
|
+
const req = apos.task.getReq();
|
|
2519
|
+
const schema = apos.schema.compose({
|
|
2520
|
+
addFields: [
|
|
2521
|
+
{
|
|
2522
|
+
name: 'prop1',
|
|
2523
|
+
type: 'object',
|
|
2524
|
+
required: false,
|
|
2525
|
+
fields: {
|
|
2526
|
+
add: {
|
|
2527
|
+
subfield: {
|
|
2528
|
+
type: 'string'
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
},
|
|
2532
|
+
schema: [
|
|
2533
|
+
{
|
|
2534
|
+
name: 'subfield',
|
|
2535
|
+
type: 'string'
|
|
2536
|
+
}
|
|
2537
|
+
]
|
|
2538
|
+
},
|
|
2539
|
+
{
|
|
2540
|
+
name: 'requiredProp',
|
|
2541
|
+
type: 'integer',
|
|
2542
|
+
required: true,
|
|
2543
|
+
if: {
|
|
2544
|
+
'prop1.subfield': 'test'
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
]
|
|
2548
|
+
});
|
|
2549
|
+
const output = {};
|
|
2550
|
+
await apos.schema.convert(req, schema, {
|
|
2551
|
+
requiredProp: null,
|
|
2552
|
+
prop1: {
|
|
2553
|
+
subfield: ''
|
|
2554
|
+
}
|
|
2555
|
+
}, output);
|
|
2556
|
+
assert(!output.requiredProp);
|
|
2557
|
+
});
|
|
2558
|
+
|
|
2559
|
+
it('should error required property nested string', async function() {
|
|
2560
|
+
const schema = apos.schema.compose({
|
|
2561
|
+
addFields: [
|
|
2562
|
+
{
|
|
2563
|
+
name: 'prop1',
|
|
2564
|
+
type: 'object',
|
|
2565
|
+
required: false,
|
|
2566
|
+
fields: {
|
|
2567
|
+
add: {
|
|
2568
|
+
subfield: {
|
|
2569
|
+
type: 'string'
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
},
|
|
2573
|
+
schema: [
|
|
2574
|
+
{
|
|
2575
|
+
name: 'subfield',
|
|
2576
|
+
type: 'string'
|
|
2577
|
+
}
|
|
2578
|
+
]
|
|
2579
|
+
},
|
|
2580
|
+
{
|
|
2581
|
+
name: 'requiredProp',
|
|
2582
|
+
type: 'integer',
|
|
2583
|
+
required: true,
|
|
2584
|
+
if: {
|
|
2585
|
+
'prop1.subfield': 'test'
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
]
|
|
2589
|
+
});
|
|
2590
|
+
await testSchemaError(schema, {
|
|
2591
|
+
requiredProp: null,
|
|
2592
|
+
prop1: {
|
|
2593
|
+
subfield: 'test'
|
|
2594
|
+
}
|
|
2595
|
+
}, 'requiredProp', 'required');
|
|
2596
|
+
});
|
|
2597
|
+
|
|
2598
|
+
it('should enforce required property nested number', async function() {
|
|
2599
|
+
const req = apos.task.getReq();
|
|
2600
|
+
const schema = apos.schema.compose({
|
|
2601
|
+
addFields: [
|
|
2602
|
+
{
|
|
2603
|
+
name: 'prop1',
|
|
2604
|
+
type: 'object',
|
|
2605
|
+
required: false,
|
|
2606
|
+
fields: {
|
|
2607
|
+
add: {
|
|
2608
|
+
subfield: {
|
|
2609
|
+
type: 'integer'
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
},
|
|
2613
|
+
schema: [
|
|
2614
|
+
{
|
|
2615
|
+
name: 'subfield',
|
|
2616
|
+
type: 'integer'
|
|
2617
|
+
}
|
|
2618
|
+
]
|
|
2619
|
+
},
|
|
2620
|
+
{
|
|
2621
|
+
name: 'requiredProp',
|
|
2622
|
+
type: 'integer',
|
|
2623
|
+
required: true,
|
|
2624
|
+
if: {
|
|
2625
|
+
'prop1.subfield': 1
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
]
|
|
2629
|
+
});
|
|
2630
|
+
const output = {};
|
|
2631
|
+
await apos.schema.convert(req, schema, {
|
|
2632
|
+
requiredProp: null,
|
|
2633
|
+
prop1: {
|
|
2634
|
+
subfield: 2
|
|
2635
|
+
}
|
|
2636
|
+
}, output);
|
|
2637
|
+
assert(!output.requiredProp);
|
|
2638
|
+
});
|
|
2639
|
+
|
|
2640
|
+
it('should error required property nested number', async function() {
|
|
2641
|
+
const schema = apos.schema.compose({
|
|
2642
|
+
addFields: [
|
|
2643
|
+
{
|
|
2644
|
+
name: 'prop1',
|
|
2645
|
+
type: 'object',
|
|
2646
|
+
required: false,
|
|
2647
|
+
fields: {
|
|
2648
|
+
add: {
|
|
2649
|
+
subfield: {
|
|
2650
|
+
type: 'integer'
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
},
|
|
2654
|
+
schema: [
|
|
2655
|
+
{
|
|
2656
|
+
name: 'subfield',
|
|
2657
|
+
type: 'integer'
|
|
2658
|
+
}
|
|
2659
|
+
]
|
|
2660
|
+
},
|
|
2661
|
+
{
|
|
2662
|
+
name: 'requiredProp',
|
|
2663
|
+
type: 'integer',
|
|
2664
|
+
required: true,
|
|
2665
|
+
if: {
|
|
2666
|
+
'prop1.subfield': 1
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
]
|
|
2670
|
+
});
|
|
2671
|
+
await testSchemaError(schema, {
|
|
2672
|
+
requiredProp: null,
|
|
2673
|
+
prop1: {
|
|
2674
|
+
subfield: 1
|
|
2675
|
+
}
|
|
2676
|
+
}, 'requiredProp', 'required');
|
|
2677
|
+
});
|
|
2678
|
+
|
|
2679
|
+
it('should enforce required property nested logical AND', async function() {
|
|
2680
|
+
const req = apos.task.getReq();
|
|
2681
|
+
const schema = apos.schema.compose({
|
|
2682
|
+
addFields: [
|
|
2683
|
+
{
|
|
2684
|
+
name: 'prop1',
|
|
2685
|
+
type: 'object',
|
|
2686
|
+
required: false,
|
|
2687
|
+
fields: {
|
|
2688
|
+
add: {
|
|
2689
|
+
subfield: {
|
|
2690
|
+
type: 'integer'
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
},
|
|
2694
|
+
schema: [
|
|
2695
|
+
{
|
|
2696
|
+
name: 'subfield',
|
|
2697
|
+
type: 'integer'
|
|
2698
|
+
}
|
|
2699
|
+
]
|
|
2700
|
+
},
|
|
2701
|
+
{
|
|
2702
|
+
name: 'prop2',
|
|
2703
|
+
type: 'boolean',
|
|
2704
|
+
required: false
|
|
2705
|
+
},
|
|
2706
|
+
{
|
|
2707
|
+
name: 'requiredProp',
|
|
2708
|
+
required: true,
|
|
2709
|
+
type: 'integer',
|
|
2710
|
+
if: {
|
|
2711
|
+
'prop1.subfield': 1,
|
|
2712
|
+
prop2: true
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
]
|
|
2716
|
+
});
|
|
2717
|
+
const output = {};
|
|
2718
|
+
await apos.schema.convert(req, schema, {
|
|
2719
|
+
requiredProp: null,
|
|
2720
|
+
prop1: {
|
|
2721
|
+
subfield: 1
|
|
2722
|
+
},
|
|
2723
|
+
prop2: false
|
|
2724
|
+
}, output);
|
|
2725
|
+
assert(!output.requiredProp);
|
|
2726
|
+
});
|
|
2727
|
+
|
|
2728
|
+
it('should error required property nested logical AND', async function() {
|
|
2729
|
+
const schema = apos.schema.compose({
|
|
2730
|
+
addFields: [
|
|
2731
|
+
{
|
|
2732
|
+
name: 'prop1',
|
|
2733
|
+
type: 'object',
|
|
2734
|
+
required: false,
|
|
2735
|
+
fields: {
|
|
2736
|
+
add: {
|
|
2737
|
+
subfield: {
|
|
2738
|
+
type: 'integer'
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
},
|
|
2742
|
+
schema: [
|
|
2743
|
+
{
|
|
2744
|
+
name: 'subfield',
|
|
2745
|
+
type: 'integer'
|
|
2746
|
+
}
|
|
2747
|
+
]
|
|
2748
|
+
},
|
|
2749
|
+
{
|
|
2750
|
+
name: 'prop2',
|
|
2751
|
+
type: 'boolean',
|
|
2752
|
+
required: false
|
|
2753
|
+
},
|
|
2754
|
+
{
|
|
2755
|
+
name: 'requiredProp',
|
|
2756
|
+
type: 'integer',
|
|
2757
|
+
required: true,
|
|
2758
|
+
if: {
|
|
2759
|
+
'prop1.subfield': 1,
|
|
2760
|
+
prop2: true
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
]
|
|
2764
|
+
});
|
|
2765
|
+
await testSchemaError(schema, {
|
|
2766
|
+
requiredProp: null,
|
|
2767
|
+
prop1: {
|
|
2768
|
+
subfield: 1
|
|
2769
|
+
},
|
|
2770
|
+
prop2: true
|
|
2771
|
+
}, 'requiredProp', 'required');
|
|
2772
|
+
});
|
|
2773
|
+
|
|
2774
|
+
it('should enforce required property nested logical OR', async function() {
|
|
2775
|
+
const req = apos.task.getReq();
|
|
2776
|
+
const schema = apos.schema.compose({
|
|
2777
|
+
addFields: [
|
|
2778
|
+
{
|
|
2779
|
+
name: 'prop1',
|
|
2780
|
+
type: 'object',
|
|
2781
|
+
required: false,
|
|
2782
|
+
fields: {
|
|
2783
|
+
add: {
|
|
2784
|
+
subfield: {
|
|
2785
|
+
type: 'integer'
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
},
|
|
2789
|
+
schema: [
|
|
2790
|
+
{
|
|
2791
|
+
name: 'subfield',
|
|
2792
|
+
type: 'integer'
|
|
2793
|
+
}
|
|
2794
|
+
]
|
|
2795
|
+
},
|
|
2796
|
+
{
|
|
2797
|
+
name: 'prop2',
|
|
2798
|
+
type: 'boolean',
|
|
2799
|
+
required: false
|
|
2800
|
+
},
|
|
2801
|
+
{
|
|
2802
|
+
name: 'requiredProp',
|
|
2803
|
+
type: 'integer',
|
|
2804
|
+
required: true,
|
|
2805
|
+
if: {
|
|
2806
|
+
$or: [
|
|
2807
|
+
{ 'prop1.subfield': 1 },
|
|
2808
|
+
{ prop2: true }
|
|
2809
|
+
]
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
]
|
|
2813
|
+
});
|
|
2814
|
+
const output = {};
|
|
2815
|
+
await apos.schema.convert(req, schema, {
|
|
2816
|
+
requiredProp: null,
|
|
2817
|
+
prop1: {
|
|
2818
|
+
subfield: 2
|
|
2819
|
+
},
|
|
2820
|
+
prop2: false
|
|
2821
|
+
}, output);
|
|
2822
|
+
assert(!output.requiredProp);
|
|
2823
|
+
});
|
|
2824
|
+
|
|
2825
|
+
it('should error required property nested logical OR', async function() {
|
|
2826
|
+
const schema = apos.schema.compose({
|
|
2827
|
+
addFields: [
|
|
2828
|
+
{
|
|
2829
|
+
name: 'prop1',
|
|
2830
|
+
type: 'object',
|
|
2831
|
+
required: false,
|
|
2832
|
+
fields: {
|
|
2833
|
+
add: {
|
|
2834
|
+
subfield: {
|
|
2835
|
+
type: 'integer'
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
},
|
|
2839
|
+
schema: [
|
|
2840
|
+
{
|
|
2841
|
+
name: 'subfield',
|
|
2842
|
+
type: 'integer'
|
|
2843
|
+
}
|
|
2844
|
+
]
|
|
2845
|
+
},
|
|
2846
|
+
{
|
|
2847
|
+
name: 'prop2',
|
|
2848
|
+
type: 'boolean',
|
|
2849
|
+
required: false
|
|
2850
|
+
},
|
|
2851
|
+
{
|
|
2852
|
+
name: 'requiredProp',
|
|
2853
|
+
type: 'integer',
|
|
2854
|
+
required: true,
|
|
2855
|
+
if: {
|
|
2856
|
+
$or: [
|
|
2857
|
+
{ 'prop1.subfield': 1 },
|
|
2858
|
+
{ prop2: true }
|
|
2859
|
+
]
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
]
|
|
2863
|
+
});
|
|
2864
|
+
await testSchemaError(schema, {
|
|
2865
|
+
requiredProp: null,
|
|
2866
|
+
prop1: {
|
|
2867
|
+
subfield: 1
|
|
2868
|
+
},
|
|
2869
|
+
prop2: false
|
|
2870
|
+
}, 'requiredProp', 'required');
|
|
2871
|
+
});
|
|
2872
|
+
|
|
2873
|
+
it('should enforce required property nested not equal match', async function() {
|
|
2874
|
+
const req = apos.task.getReq();
|
|
2875
|
+
const schema = apos.schema.compose({
|
|
2876
|
+
addFields: [
|
|
2877
|
+
{
|
|
2878
|
+
name: 'prop1',
|
|
2879
|
+
type: 'object',
|
|
2880
|
+
required: false,
|
|
2881
|
+
fields: {
|
|
2882
|
+
add: {
|
|
2883
|
+
subfield: {
|
|
2884
|
+
type: 'string'
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
},
|
|
2888
|
+
schema: [
|
|
2889
|
+
{
|
|
2890
|
+
name: 'subfield',
|
|
2891
|
+
type: 'string'
|
|
2892
|
+
}
|
|
2893
|
+
]
|
|
2894
|
+
},
|
|
2895
|
+
{
|
|
2896
|
+
name: 'requiredProp',
|
|
2897
|
+
type: 'integer',
|
|
2898
|
+
required: true,
|
|
2899
|
+
if: {
|
|
2900
|
+
'prop1.subfield': { $ne: 'test' }
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
]
|
|
2904
|
+
});
|
|
2905
|
+
const output = {};
|
|
2906
|
+
await apos.schema.convert(req, schema, {
|
|
2907
|
+
requiredProp: null,
|
|
2908
|
+
prop1: {
|
|
2909
|
+
subfield: 'test'
|
|
2910
|
+
}
|
|
2911
|
+
}, output);
|
|
2912
|
+
assert(!output.requiredProp);
|
|
2913
|
+
});
|
|
2914
|
+
|
|
2915
|
+
it('should error required property nested not equal match', async function() {
|
|
2916
|
+
const schema = apos.schema.compose({
|
|
2917
|
+
addFields: [
|
|
2918
|
+
{
|
|
2919
|
+
name: 'prop1',
|
|
2920
|
+
type: 'object',
|
|
2921
|
+
required: false,
|
|
2922
|
+
fields: {
|
|
2923
|
+
add: {
|
|
2924
|
+
subfield: {
|
|
2925
|
+
type: 'string'
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
},
|
|
2929
|
+
schema: [
|
|
2930
|
+
{
|
|
2931
|
+
name: 'subfield',
|
|
2932
|
+
type: 'string'
|
|
2933
|
+
}
|
|
2934
|
+
]
|
|
2935
|
+
},
|
|
2936
|
+
{
|
|
2937
|
+
name: 'requiredProp',
|
|
2938
|
+
type: 'integer',
|
|
2939
|
+
required: true,
|
|
2940
|
+
if: {
|
|
2941
|
+
'prop1.subfield': { $ne: 'test' }
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
]
|
|
2945
|
+
});
|
|
2946
|
+
await testSchemaError(schema, {
|
|
2947
|
+
requiredProp: null,
|
|
2948
|
+
prop1: {
|
|
2949
|
+
subfield: 'test2'
|
|
2950
|
+
}
|
|
2951
|
+
}, 'requiredProp', 'required');
|
|
2952
|
+
});
|
|
2953
|
+
|
|
2954
|
+
it('should enforce required property with ifRequired boolean', async function() {
|
|
2955
|
+
const req = apos.task.getReq();
|
|
2956
|
+
const schema = apos.schema.compose({
|
|
2957
|
+
addFields: [
|
|
2958
|
+
{
|
|
2959
|
+
name: 'age',
|
|
2960
|
+
type: 'integer',
|
|
2961
|
+
required: false
|
|
2962
|
+
},
|
|
2963
|
+
{
|
|
2964
|
+
name: 'shoeSize',
|
|
2965
|
+
type: 'integer',
|
|
2966
|
+
requiredIf: {
|
|
2967
|
+
age: true
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
]
|
|
2971
|
+
});
|
|
2972
|
+
const output = {};
|
|
2973
|
+
await apos.schema.convert(req, schema, {
|
|
2974
|
+
shoeSize: '',
|
|
2975
|
+
age: ''
|
|
2976
|
+
}, output);
|
|
2977
|
+
assert(output.shoeSize === null);
|
|
2978
|
+
});
|
|
2979
|
+
|
|
2980
|
+
it('should error required property with ifRequired boolean', async function() {
|
|
2981
|
+
const schema = apos.schema.compose({
|
|
2982
|
+
addFields: [
|
|
2983
|
+
{
|
|
2984
|
+
name: 'age',
|
|
2985
|
+
type: 'integer',
|
|
2986
|
+
required: false
|
|
2987
|
+
},
|
|
2988
|
+
{
|
|
2989
|
+
name: 'shoeSize',
|
|
2990
|
+
type: 'integer',
|
|
2991
|
+
requiredIf: {
|
|
2992
|
+
age: true
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
]
|
|
2996
|
+
});
|
|
2997
|
+
await testSchemaError(schema, {
|
|
2998
|
+
shoeSize: '',
|
|
2999
|
+
age: '18'
|
|
3000
|
+
}, 'shoeSize', 'required');
|
|
3001
|
+
});
|
|
3002
|
+
|
|
3003
|
+
it('should enforce required property with ifRequired string', async function() {
|
|
3004
|
+
const req = apos.task.getReq();
|
|
3005
|
+
const schema = apos.schema.compose({
|
|
3006
|
+
addFields: [
|
|
3007
|
+
{
|
|
3008
|
+
name: 'age',
|
|
3009
|
+
type: 'integer',
|
|
3010
|
+
required: false
|
|
3011
|
+
},
|
|
3012
|
+
{
|
|
3013
|
+
name: 'shoeSize',
|
|
3014
|
+
type: 'integer',
|
|
3015
|
+
requiredIf: {
|
|
3016
|
+
age: '18'
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
]
|
|
3020
|
+
});
|
|
3021
|
+
const output = {};
|
|
3022
|
+
await apos.schema.convert(req, schema, {
|
|
3023
|
+
shoeSize: '',
|
|
3024
|
+
age: '17'
|
|
3025
|
+
}, output);
|
|
3026
|
+
assert(output.shoeSize === null);
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
it('should error required property with ifRequired string', async function() {
|
|
3030
|
+
const schema = apos.schema.compose({
|
|
3031
|
+
addFields: [
|
|
3032
|
+
{
|
|
3033
|
+
name: 'age',
|
|
3034
|
+
type: 'integer',
|
|
3035
|
+
required: false
|
|
3036
|
+
},
|
|
3037
|
+
{
|
|
3038
|
+
name: 'shoeSize',
|
|
3039
|
+
type: 'integer',
|
|
3040
|
+
requiredIf: {
|
|
3041
|
+
age: '18'
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
]
|
|
3045
|
+
});
|
|
3046
|
+
await testSchemaError(schema, {
|
|
3047
|
+
shoeSize: '',
|
|
3048
|
+
age: '18'
|
|
3049
|
+
}, 'shoeSize', 'required');
|
|
3050
|
+
});
|
|
3051
|
+
|
|
3052
|
+
it('should enforce required property with ifRequired number', async function() {
|
|
3053
|
+
const req = apos.task.getReq();
|
|
3054
|
+
const schema = apos.schema.compose({
|
|
3055
|
+
addFields: [
|
|
3056
|
+
{
|
|
3057
|
+
name: 'age',
|
|
3058
|
+
type: 'integer',
|
|
3059
|
+
required: false
|
|
3060
|
+
},
|
|
3061
|
+
{
|
|
3062
|
+
name: 'shoeSize',
|
|
3063
|
+
type: 'integer',
|
|
3064
|
+
requiredIf: {
|
|
3065
|
+
age: 18
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
]
|
|
3069
|
+
});
|
|
3070
|
+
const output = {};
|
|
3071
|
+
await apos.schema.convert(req, schema, {
|
|
3072
|
+
shoeSize: '',
|
|
3073
|
+
age: 17
|
|
3074
|
+
}, output);
|
|
3075
|
+
assert(output.shoeSize === null);
|
|
3076
|
+
});
|
|
3077
|
+
|
|
3078
|
+
it('should error required property with ifRequired number', async function() {
|
|
3079
|
+
const schema = apos.schema.compose({
|
|
3080
|
+
addFields: [
|
|
3081
|
+
{
|
|
3082
|
+
name: 'age',
|
|
3083
|
+
type: 'integer',
|
|
3084
|
+
required: false
|
|
3085
|
+
},
|
|
3086
|
+
{
|
|
3087
|
+
name: 'shoeSize',
|
|
3088
|
+
type: 'integer',
|
|
3089
|
+
requiredIf: {
|
|
3090
|
+
age: 18
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
]
|
|
3094
|
+
});
|
|
3095
|
+
await testSchemaError(schema, {
|
|
3096
|
+
shoeSize: '',
|
|
3097
|
+
age: 18
|
|
3098
|
+
}, 'shoeSize', 'required');
|
|
3099
|
+
});
|
|
3100
|
+
|
|
3101
|
+
it('should enforce required property with ifRequired number min', async function() {
|
|
3102
|
+
const req = apos.task.getReq();
|
|
3103
|
+
const schema = apos.schema.compose({
|
|
3104
|
+
addFields: [
|
|
3105
|
+
{
|
|
3106
|
+
name: 'age',
|
|
3107
|
+
type: 'integer',
|
|
3108
|
+
required: false
|
|
3109
|
+
},
|
|
3110
|
+
{
|
|
3111
|
+
name: 'shoeSize',
|
|
3112
|
+
type: 'integer',
|
|
3113
|
+
requiredIf: {
|
|
3114
|
+
age: {
|
|
3115
|
+
min: 18
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
]
|
|
3120
|
+
});
|
|
3121
|
+
const output = {};
|
|
3122
|
+
await apos.schema.convert(req, schema, {
|
|
3123
|
+
shoeSize: '',
|
|
3124
|
+
age: 17
|
|
3125
|
+
}, output);
|
|
3126
|
+
assert(output.shoeSize === null);
|
|
3127
|
+
});
|
|
3128
|
+
|
|
3129
|
+
it('should error required property with ifRequired number min', async function() {
|
|
3130
|
+
const schema = apos.schema.compose({
|
|
3131
|
+
addFields: [
|
|
3132
|
+
{
|
|
3133
|
+
name: 'age',
|
|
3134
|
+
type: 'integer',
|
|
3135
|
+
required: false
|
|
3136
|
+
},
|
|
3137
|
+
{
|
|
3138
|
+
name: 'prop2',
|
|
3139
|
+
type: 'boolean',
|
|
3140
|
+
required: false
|
|
3141
|
+
},
|
|
3142
|
+
{
|
|
3143
|
+
name: 'shoeSize',
|
|
3144
|
+
type: 'integer',
|
|
3145
|
+
requiredIf: {
|
|
3146
|
+
age: {
|
|
3147
|
+
min: 18
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
]
|
|
3152
|
+
});
|
|
3153
|
+
await testSchemaError(schema, {
|
|
3154
|
+
shoeSize: '',
|
|
3155
|
+
age: 19,
|
|
3156
|
+
prop2: false
|
|
3157
|
+
}, 'shoeSize', 'required');
|
|
3158
|
+
});
|
|
3159
|
+
|
|
3160
|
+
it('should enforce required property with ifRequired number max', async function() {
|
|
3161
|
+
const req = apos.task.getReq();
|
|
3162
|
+
const schema = apos.schema.compose({
|
|
3163
|
+
addFields: [
|
|
3164
|
+
{
|
|
3165
|
+
name: 'age',
|
|
3166
|
+
type: 'integer',
|
|
3167
|
+
required: false
|
|
3168
|
+
},
|
|
3169
|
+
{
|
|
3170
|
+
name: 'shoeSize',
|
|
3171
|
+
type: 'integer',
|
|
3172
|
+
requiredIf: {
|
|
3173
|
+
age: {
|
|
3174
|
+
min: 18,
|
|
3175
|
+
max: 36
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
]
|
|
3180
|
+
});
|
|
3181
|
+
const output = {};
|
|
3182
|
+
await apos.schema.convert(req, schema, {
|
|
3183
|
+
shoeSize: '',
|
|
3184
|
+
age: 37
|
|
3185
|
+
}, output);
|
|
3186
|
+
assert(output.shoeSize === null);
|
|
3187
|
+
});
|
|
3188
|
+
|
|
3189
|
+
it('should error required property with ifRequired number max', async function() {
|
|
3190
|
+
const schema = apos.schema.compose({
|
|
3191
|
+
addFields: [
|
|
3192
|
+
{
|
|
3193
|
+
name: 'age',
|
|
3194
|
+
type: 'integer',
|
|
3195
|
+
required: false
|
|
3196
|
+
},
|
|
3197
|
+
{
|
|
3198
|
+
name: 'prop2',
|
|
3199
|
+
type: 'boolean',
|
|
3200
|
+
required: false
|
|
3201
|
+
},
|
|
3202
|
+
{
|
|
3203
|
+
name: 'shoeSize',
|
|
3204
|
+
type: 'integer',
|
|
3205
|
+
requiredIf: {
|
|
3206
|
+
age: {
|
|
3207
|
+
min: 18,
|
|
3208
|
+
max: 36
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
]
|
|
3213
|
+
});
|
|
3214
|
+
await testSchemaError(schema, {
|
|
3215
|
+
shoeSize: '',
|
|
3216
|
+
age: 36
|
|
3217
|
+
}, 'shoeSize', 'required');
|
|
3218
|
+
});
|
|
3219
|
+
|
|
3220
|
+
it('should enforce required property with ifRequired logical AND', async function() {
|
|
3221
|
+
const req = apos.task.getReq();
|
|
3222
|
+
const schema = apos.schema.compose({
|
|
3223
|
+
addFields: [
|
|
3224
|
+
{
|
|
3225
|
+
name: 'prop1',
|
|
3226
|
+
type: 'string',
|
|
3227
|
+
required: false
|
|
3228
|
+
},
|
|
3229
|
+
{
|
|
3230
|
+
name: 'prop2',
|
|
3231
|
+
type: 'boolean',
|
|
3232
|
+
required: false
|
|
3233
|
+
},
|
|
3234
|
+
{
|
|
3235
|
+
name: 'requiredIfProp',
|
|
3236
|
+
type: 'integer',
|
|
3237
|
+
requiredIf: {
|
|
3238
|
+
prop1: 'test',
|
|
3239
|
+
prop2: true
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
]
|
|
3243
|
+
});
|
|
3244
|
+
const output = {};
|
|
3245
|
+
await apos.schema.convert(req, schema, {
|
|
3246
|
+
requiredIfProp: null,
|
|
3247
|
+
prop1: 'test',
|
|
3248
|
+
prop2: false
|
|
3249
|
+
}, output);
|
|
3250
|
+
assert(output.requiredIfProp === null);
|
|
3251
|
+
});
|
|
3252
|
+
|
|
3253
|
+
it('should error required property with ifRequired logical AND', async function() {
|
|
3254
|
+
const schema = apos.schema.compose({
|
|
3255
|
+
addFields: [
|
|
3256
|
+
{
|
|
3257
|
+
name: 'prop1',
|
|
3258
|
+
type: 'string',
|
|
3259
|
+
required: false
|
|
3260
|
+
},
|
|
3261
|
+
{
|
|
3262
|
+
name: 'prop2',
|
|
3263
|
+
type: 'boolean',
|
|
3264
|
+
required: false
|
|
3265
|
+
},
|
|
3266
|
+
{
|
|
3267
|
+
name: 'requiredIfProp',
|
|
3268
|
+
type: 'integer',
|
|
3269
|
+
requiredIf: {
|
|
3270
|
+
prop1: 'test',
|
|
3271
|
+
prop2: true
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
]
|
|
3275
|
+
});
|
|
3276
|
+
await testSchemaError(schema, {
|
|
3277
|
+
requiredIfProp: null,
|
|
3278
|
+
prop1: 'test',
|
|
3279
|
+
prop2: true
|
|
3280
|
+
}, 'requiredIfProp', 'required');
|
|
3281
|
+
});
|
|
3282
|
+
|
|
3283
|
+
it('should enforce required property with ifRequired logical AND with inverted props', async function() {
|
|
3284
|
+
const req = apos.task.getReq();
|
|
3285
|
+
const schema = apos.schema.compose({
|
|
3286
|
+
addFields: [
|
|
3287
|
+
{
|
|
3288
|
+
name: 'prop1',
|
|
3289
|
+
type: 'string',
|
|
3290
|
+
required: false
|
|
3291
|
+
},
|
|
3292
|
+
{
|
|
3293
|
+
name: 'prop2',
|
|
3294
|
+
type: 'boolean',
|
|
3295
|
+
required: false
|
|
3296
|
+
},
|
|
3297
|
+
{
|
|
3298
|
+
name: 'requiredIfProp',
|
|
3299
|
+
type: 'integer',
|
|
3300
|
+
requiredIf: {
|
|
3301
|
+
prop2: true,
|
|
3302
|
+
prop1: 'test'
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
]
|
|
3306
|
+
});
|
|
3307
|
+
const output = {};
|
|
3308
|
+
await apos.schema.convert(req, schema, {
|
|
3309
|
+
requiredIfProp: null,
|
|
3310
|
+
prop1: 'test',
|
|
3311
|
+
prop2: false
|
|
3312
|
+
}, output);
|
|
3313
|
+
assert(output.requiredIfProp === null);
|
|
3314
|
+
});
|
|
3315
|
+
|
|
3316
|
+
it('should error required property with ifRequired logical AND with inverted props', async function() {
|
|
3317
|
+
const schema = apos.schema.compose({
|
|
3318
|
+
addFields: [
|
|
3319
|
+
{
|
|
3320
|
+
name: 'prop1',
|
|
3321
|
+
type: 'string',
|
|
3322
|
+
required: false
|
|
3323
|
+
},
|
|
3324
|
+
{
|
|
3325
|
+
name: 'prop2',
|
|
3326
|
+
type: 'boolean',
|
|
3327
|
+
required: false
|
|
3328
|
+
},
|
|
3329
|
+
{
|
|
3330
|
+
name: 'requiredIfProp',
|
|
3331
|
+
type: 'integer',
|
|
3332
|
+
requiredIf: {
|
|
3333
|
+
prop2: true,
|
|
3334
|
+
prop1: 'test'
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
]
|
|
3338
|
+
});
|
|
3339
|
+
await testSchemaError(schema, {
|
|
3340
|
+
requiredIfProp: null,
|
|
3341
|
+
prop1: 'test',
|
|
3342
|
+
prop2: true
|
|
3343
|
+
}, 'requiredIfProp', 'required');
|
|
3344
|
+
});
|
|
3345
|
+
|
|
3346
|
+
it('should enforce required property with ifRequired logical OR', async function() {
|
|
3347
|
+
const req = apos.task.getReq();
|
|
3348
|
+
const schema = apos.schema.compose({
|
|
3349
|
+
addFields: [
|
|
3350
|
+
{
|
|
3351
|
+
name: 'prop1',
|
|
3352
|
+
type: 'string',
|
|
3353
|
+
required: false
|
|
3354
|
+
},
|
|
3355
|
+
{
|
|
3356
|
+
name: 'prop2',
|
|
3357
|
+
type: 'boolean',
|
|
3358
|
+
required: false
|
|
3359
|
+
},
|
|
3360
|
+
{
|
|
3361
|
+
name: 'requiredIfProp',
|
|
3362
|
+
type: 'integer',
|
|
3363
|
+
requiredIf: {
|
|
3364
|
+
$or: [
|
|
3365
|
+
{ prop1: 'test' },
|
|
3366
|
+
{ prop2: true }
|
|
3367
|
+
]
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
]
|
|
3371
|
+
});
|
|
3372
|
+
const output = {};
|
|
3373
|
+
await apos.schema.convert(req, schema, {
|
|
3374
|
+
requiredIfProp: null,
|
|
3375
|
+
prop1: 'test2',
|
|
3376
|
+
prop2: false
|
|
3377
|
+
}, output);
|
|
3378
|
+
assert(output.requiredIfProp === null);
|
|
3379
|
+
});
|
|
3380
|
+
|
|
3381
|
+
it('should error required property with ifRequired logical OR', async function() {
|
|
3382
|
+
const schema = apos.schema.compose({
|
|
3383
|
+
addFields: [
|
|
3384
|
+
{
|
|
3385
|
+
name: 'prop1',
|
|
3386
|
+
type: 'string',
|
|
3387
|
+
required: false
|
|
3388
|
+
},
|
|
3389
|
+
{
|
|
3390
|
+
name: 'prop2',
|
|
3391
|
+
type: 'boolean',
|
|
3392
|
+
required: false
|
|
3393
|
+
},
|
|
3394
|
+
{
|
|
3395
|
+
name: 'requiredIfProp',
|
|
3396
|
+
type: 'integer',
|
|
3397
|
+
requiredIf: {
|
|
3398
|
+
$or: [
|
|
3399
|
+
{ prop1: 'test' },
|
|
3400
|
+
{ prop2: true }
|
|
3401
|
+
]
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
]
|
|
3405
|
+
});
|
|
3406
|
+
await testSchemaError(schema, {
|
|
3407
|
+
requiredIfProp: null,
|
|
3408
|
+
prop1: 'test2',
|
|
3409
|
+
prop2: true
|
|
3410
|
+
}, 'requiredIfProp', 'required');
|
|
3411
|
+
});
|
|
3412
|
+
|
|
3413
|
+
it('should enforce required property with ifRequired logical OR with inverted props', async function() {
|
|
3414
|
+
const req = apos.task.getReq();
|
|
3415
|
+
const schema = apos.schema.compose({
|
|
3416
|
+
addFields: [
|
|
3417
|
+
{
|
|
3418
|
+
name: 'prop1',
|
|
3419
|
+
type: 'string',
|
|
3420
|
+
required: false
|
|
3421
|
+
},
|
|
3422
|
+
{
|
|
3423
|
+
name: 'prop2',
|
|
3424
|
+
type: 'boolean',
|
|
3425
|
+
required: false
|
|
3426
|
+
},
|
|
3427
|
+
{
|
|
3428
|
+
name: 'requiredIfProp',
|
|
3429
|
+
type: 'integer',
|
|
3430
|
+
requiredIf: {
|
|
3431
|
+
$or: [
|
|
3432
|
+
{ prop2: true },
|
|
3433
|
+
{ prop1: 'test' }
|
|
3434
|
+
]
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
]
|
|
3438
|
+
});
|
|
3439
|
+
const output = {};
|
|
3440
|
+
await apos.schema.convert(req, schema, {
|
|
3441
|
+
requiredIfProp: null,
|
|
3442
|
+
prop1: 'test2',
|
|
3443
|
+
prop2: false
|
|
3444
|
+
}, output);
|
|
3445
|
+
assert(output.requiredIfProp === null);
|
|
3446
|
+
});
|
|
3447
|
+
|
|
3448
|
+
it('should error required property with ifRequired logical OR with inverted props', async function() {
|
|
3449
|
+
const schema = apos.schema.compose({
|
|
3450
|
+
addFields: [
|
|
3451
|
+
{
|
|
3452
|
+
name: 'prop1',
|
|
3453
|
+
type: 'string',
|
|
3454
|
+
required: false
|
|
3455
|
+
},
|
|
3456
|
+
{
|
|
3457
|
+
name: 'prop2',
|
|
3458
|
+
type: 'boolean',
|
|
3459
|
+
required: false
|
|
3460
|
+
},
|
|
3461
|
+
{
|
|
3462
|
+
name: 'requiredIfProp',
|
|
3463
|
+
type: 'integer',
|
|
3464
|
+
requiredIf: {
|
|
3465
|
+
$or: [
|
|
3466
|
+
{ prop2: true },
|
|
3467
|
+
{ prop1: 'test' }
|
|
3468
|
+
]
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
]
|
|
3472
|
+
});
|
|
3473
|
+
await testSchemaError(schema, {
|
|
3474
|
+
requiredIfProp: null,
|
|
3475
|
+
prop1: 'test2',
|
|
3476
|
+
prop2: true
|
|
3477
|
+
}, 'requiredIfProp', 'required');
|
|
3478
|
+
});
|
|
3479
|
+
|
|
3480
|
+
it('should enforce required property with ifRequired not equal match', async function() {
|
|
3481
|
+
const req = apos.task.getReq();
|
|
3482
|
+
const schema = apos.schema.compose({
|
|
3483
|
+
addFields: [
|
|
3484
|
+
{
|
|
3485
|
+
name: 'prop1',
|
|
3486
|
+
type: 'string',
|
|
3487
|
+
required: false
|
|
3488
|
+
},
|
|
3489
|
+
{
|
|
3490
|
+
name: 'prop2',
|
|
3491
|
+
type: 'boolean',
|
|
3492
|
+
required: false
|
|
3493
|
+
},
|
|
3494
|
+
{
|
|
3495
|
+
name: 'requiredIfProp',
|
|
3496
|
+
type: 'integer',
|
|
3497
|
+
requiredIf: { prop1: { $ne: 'test' } }
|
|
3498
|
+
}
|
|
3499
|
+
]
|
|
3500
|
+
});
|
|
3501
|
+
const output = {};
|
|
3502
|
+
await apos.schema.convert(req, schema, {
|
|
3503
|
+
requiredIfProp: null,
|
|
3504
|
+
prop1: 'test'
|
|
3505
|
+
}, output);
|
|
3506
|
+
assert(output.requiredIfProp === null);
|
|
3507
|
+
});
|
|
3508
|
+
|
|
3509
|
+
it('should error required property with ifRequired not equal match', async function() {
|
|
3510
|
+
const schema = apos.schema.compose({
|
|
3511
|
+
addFields: [
|
|
3512
|
+
{
|
|
3513
|
+
name: 'prop1',
|
|
3514
|
+
type: 'string',
|
|
3515
|
+
required: false
|
|
3516
|
+
},
|
|
3517
|
+
{
|
|
3518
|
+
name: 'prop2',
|
|
3519
|
+
type: 'boolean',
|
|
3520
|
+
required: false
|
|
3521
|
+
},
|
|
3522
|
+
{
|
|
3523
|
+
name: 'requiredIfProp',
|
|
3524
|
+
type: 'integer',
|
|
3525
|
+
requiredIf: { prop1: { $ne: 'test' } }
|
|
3526
|
+
}
|
|
3527
|
+
]
|
|
3528
|
+
});
|
|
3529
|
+
await testSchemaError(schema, {
|
|
3530
|
+
requiredIfProp: null,
|
|
3531
|
+
prop1: 'test2'
|
|
3532
|
+
}, 'requiredIfProp', 'required');
|
|
3533
|
+
});
|
|
3534
|
+
|
|
3535
|
+
it('should enforce required property with ifRequired nested boolean', async function() {
|
|
3536
|
+
const req = apos.task.getReq();
|
|
3537
|
+
const schema = apos.schema.compose({
|
|
3538
|
+
addFields: [
|
|
3539
|
+
{
|
|
3540
|
+
name: 'prop1',
|
|
3541
|
+
type: 'object',
|
|
3542
|
+
required: false,
|
|
3543
|
+
fields: {
|
|
3544
|
+
add: {
|
|
3545
|
+
subfield: {
|
|
3546
|
+
type: 'boolean'
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
},
|
|
3550
|
+
schema: [
|
|
3551
|
+
{
|
|
3552
|
+
name: 'subfield',
|
|
3553
|
+
type: 'boolean'
|
|
3554
|
+
}
|
|
3555
|
+
]
|
|
3556
|
+
},
|
|
3557
|
+
{
|
|
3558
|
+
name: 'requiredIfProp',
|
|
3559
|
+
type: 'integer',
|
|
3560
|
+
requiredIf: {
|
|
3561
|
+
'prop1.subfield': true
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
]
|
|
3565
|
+
});
|
|
3566
|
+
const output = {};
|
|
3567
|
+
await apos.schema.convert(req, schema, {
|
|
3568
|
+
requiredIfProp: null,
|
|
3569
|
+
prop1: {
|
|
3570
|
+
subfield: false
|
|
3571
|
+
}
|
|
3572
|
+
}, output);
|
|
3573
|
+
assert(output.requiredIfProp === null);
|
|
3574
|
+
});
|
|
3575
|
+
|
|
3576
|
+
it('should error required property with ifRequired nested boolean', async function() {
|
|
3577
|
+
const schema = apos.schema.compose({
|
|
3578
|
+
addFields: [
|
|
3579
|
+
{
|
|
3580
|
+
name: 'prop1',
|
|
3581
|
+
type: 'object',
|
|
3582
|
+
required: false,
|
|
3583
|
+
fields: {
|
|
3584
|
+
add: {
|
|
3585
|
+
subfield: {
|
|
3586
|
+
type: 'boolean'
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
},
|
|
3590
|
+
schema: [
|
|
3591
|
+
{
|
|
3592
|
+
name: 'subfield',
|
|
3593
|
+
type: 'boolean'
|
|
3594
|
+
}
|
|
3595
|
+
]
|
|
3596
|
+
},
|
|
3597
|
+
{
|
|
3598
|
+
name: 'requiredIfProp',
|
|
3599
|
+
type: 'integer',
|
|
3600
|
+
requiredIf: {
|
|
3601
|
+
'prop1.subfield': true
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
]
|
|
3605
|
+
});
|
|
3606
|
+
await testSchemaError(schema, {
|
|
3607
|
+
requiredIfProp: null,
|
|
3608
|
+
prop1: {
|
|
3609
|
+
subfield: true
|
|
3610
|
+
}
|
|
3611
|
+
}, 'requiredIfProp', 'required');
|
|
3612
|
+
});
|
|
3613
|
+
|
|
3614
|
+
it('should enforce required property with ifRequired nested string', async function() {
|
|
3615
|
+
const req = apos.task.getReq();
|
|
3616
|
+
const schema = apos.schema.compose({
|
|
3617
|
+
addFields: [
|
|
3618
|
+
{
|
|
3619
|
+
name: 'prop1',
|
|
3620
|
+
type: 'object',
|
|
3621
|
+
required: false,
|
|
3622
|
+
fields: {
|
|
3623
|
+
add: {
|
|
3624
|
+
subfield: {
|
|
3625
|
+
type: 'string'
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
},
|
|
3629
|
+
schema: [
|
|
3630
|
+
{
|
|
3631
|
+
name: 'subfield',
|
|
3632
|
+
type: 'string'
|
|
3633
|
+
}
|
|
3634
|
+
]
|
|
3635
|
+
},
|
|
3636
|
+
{
|
|
3637
|
+
name: 'requiredIfProp',
|
|
3638
|
+
type: 'integer',
|
|
3639
|
+
requiredIf: {
|
|
3640
|
+
'prop1.subfield': 'test'
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
]
|
|
3644
|
+
});
|
|
3645
|
+
const output = {};
|
|
3646
|
+
await apos.schema.convert(req, schema, {
|
|
3647
|
+
requiredIfProp: null,
|
|
3648
|
+
prop1: {
|
|
3649
|
+
subfield: ''
|
|
3650
|
+
}
|
|
3651
|
+
}, output);
|
|
3652
|
+
assert(output.requiredIfProp === null);
|
|
3653
|
+
});
|
|
3654
|
+
|
|
3655
|
+
it('should error required property with ifRequired nested string', async function() {
|
|
3656
|
+
const schema = apos.schema.compose({
|
|
3657
|
+
addFields: [
|
|
3658
|
+
{
|
|
3659
|
+
name: 'prop1',
|
|
3660
|
+
type: 'object',
|
|
3661
|
+
required: false,
|
|
3662
|
+
fields: {
|
|
3663
|
+
add: {
|
|
3664
|
+
subfield: {
|
|
3665
|
+
type: 'string'
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
},
|
|
3669
|
+
schema: [
|
|
3670
|
+
{
|
|
3671
|
+
name: 'subfield',
|
|
3672
|
+
type: 'string'
|
|
3673
|
+
}
|
|
3674
|
+
]
|
|
3675
|
+
},
|
|
3676
|
+
{
|
|
3677
|
+
name: 'requiredIfProp',
|
|
3678
|
+
type: 'integer',
|
|
3679
|
+
requiredIf: {
|
|
3680
|
+
'prop1.subfield': 'test'
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
]
|
|
3684
|
+
});
|
|
3685
|
+
await testSchemaError(schema, {
|
|
3686
|
+
requiredIfProp: null,
|
|
3687
|
+
prop1: {
|
|
3688
|
+
subfield: 'test'
|
|
3689
|
+
}
|
|
3690
|
+
}, 'requiredIfProp', 'required');
|
|
3691
|
+
});
|
|
3692
|
+
|
|
3693
|
+
it('should enforce required property with ifRequired nested number', async function() {
|
|
3694
|
+
const req = apos.task.getReq();
|
|
3695
|
+
const schema = apos.schema.compose({
|
|
3696
|
+
addFields: [
|
|
3697
|
+
{
|
|
3698
|
+
name: 'prop1',
|
|
3699
|
+
type: 'object',
|
|
3700
|
+
required: false,
|
|
3701
|
+
fields: {
|
|
3702
|
+
add: {
|
|
3703
|
+
subfield: {
|
|
3704
|
+
type: 'integer'
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
},
|
|
3708
|
+
schema: [
|
|
3709
|
+
{
|
|
3710
|
+
name: 'subfield',
|
|
3711
|
+
type: 'integer'
|
|
3712
|
+
}
|
|
3713
|
+
]
|
|
3714
|
+
},
|
|
3715
|
+
{
|
|
3716
|
+
name: 'requiredIfProp',
|
|
3717
|
+
type: 'integer',
|
|
3718
|
+
requiredIf: {
|
|
3719
|
+
'prop1.subfield': 1
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
]
|
|
3723
|
+
});
|
|
3724
|
+
const output = {};
|
|
3725
|
+
await apos.schema.convert(req, schema, {
|
|
3726
|
+
requiredIfProp: null,
|
|
3727
|
+
prop1: {
|
|
3728
|
+
subfield: 2
|
|
3729
|
+
}
|
|
3730
|
+
}, output);
|
|
3731
|
+
assert(output.requiredIfProp === null);
|
|
3732
|
+
});
|
|
3733
|
+
|
|
3734
|
+
it('should error required property with ifRequired nested number', async function() {
|
|
3735
|
+
const schema = apos.schema.compose({
|
|
3736
|
+
addFields: [
|
|
3737
|
+
{
|
|
3738
|
+
name: 'prop1',
|
|
3739
|
+
type: 'object',
|
|
3740
|
+
required: false,
|
|
3741
|
+
fields: {
|
|
3742
|
+
add: {
|
|
3743
|
+
subfield: {
|
|
3744
|
+
type: 'integer'
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
},
|
|
3748
|
+
schema: [
|
|
3749
|
+
{
|
|
3750
|
+
name: 'subfield',
|
|
3751
|
+
type: 'integer'
|
|
3752
|
+
}
|
|
3753
|
+
]
|
|
3754
|
+
},
|
|
3755
|
+
{
|
|
3756
|
+
name: 'requiredIfProp',
|
|
3757
|
+
type: 'integer',
|
|
3758
|
+
requiredIf: {
|
|
3759
|
+
'prop1.subfield': 1
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
]
|
|
3763
|
+
});
|
|
3764
|
+
await testSchemaError(schema, {
|
|
3765
|
+
requiredIfProp: null,
|
|
3766
|
+
prop1: {
|
|
3767
|
+
subfield: 1
|
|
3768
|
+
}
|
|
3769
|
+
}, 'requiredIfProp', 'required');
|
|
3770
|
+
});
|
|
3771
|
+
|
|
3772
|
+
it('should enforce required property with ifRequired nested logical AND', async function() {
|
|
3773
|
+
const req = apos.task.getReq();
|
|
3774
|
+
const schema = apos.schema.compose({
|
|
3775
|
+
addFields: [
|
|
3776
|
+
{
|
|
3777
|
+
name: 'prop1',
|
|
3778
|
+
type: 'object',
|
|
3779
|
+
required: false,
|
|
3780
|
+
fields: {
|
|
3781
|
+
add: {
|
|
3782
|
+
subfield: {
|
|
3783
|
+
type: 'integer'
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
},
|
|
3787
|
+
schema: [
|
|
3788
|
+
{
|
|
3789
|
+
name: 'subfield',
|
|
3790
|
+
type: 'integer'
|
|
3791
|
+
}
|
|
3792
|
+
]
|
|
3793
|
+
},
|
|
3794
|
+
{
|
|
3795
|
+
name: 'prop2',
|
|
3796
|
+
type: 'boolean',
|
|
3797
|
+
required: false
|
|
3798
|
+
},
|
|
3799
|
+
{
|
|
3800
|
+
name: 'requiredIfProp',
|
|
3801
|
+
type: 'integer',
|
|
3802
|
+
requiredIf: {
|
|
3803
|
+
'prop1.subfield': 1,
|
|
3804
|
+
prop2: true
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
]
|
|
3808
|
+
});
|
|
3809
|
+
const output = {};
|
|
3810
|
+
await apos.schema.convert(req, schema, {
|
|
3811
|
+
requiredIfProp: null,
|
|
3812
|
+
prop1: {
|
|
3813
|
+
subfield: 1
|
|
3814
|
+
},
|
|
3815
|
+
prop2: false
|
|
3816
|
+
}, output);
|
|
3817
|
+
assert(output.requiredIfProp === null);
|
|
3818
|
+
});
|
|
3819
|
+
|
|
3820
|
+
it('should error required property with ifRequired nested logical AND', async function() {
|
|
3821
|
+
const schema = apos.schema.compose({
|
|
3822
|
+
addFields: [
|
|
3823
|
+
{
|
|
3824
|
+
name: 'prop1',
|
|
3825
|
+
type: 'object',
|
|
3826
|
+
required: false,
|
|
3827
|
+
fields: {
|
|
3828
|
+
add: {
|
|
3829
|
+
subfield: {
|
|
3830
|
+
type: 'integer'
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
},
|
|
3834
|
+
schema: [
|
|
3835
|
+
{
|
|
3836
|
+
name: 'subfield',
|
|
3837
|
+
type: 'integer'
|
|
3838
|
+
}
|
|
3839
|
+
]
|
|
3840
|
+
},
|
|
3841
|
+
{
|
|
3842
|
+
name: 'prop2',
|
|
3843
|
+
type: 'boolean',
|
|
3844
|
+
required: false
|
|
3845
|
+
},
|
|
3846
|
+
{
|
|
3847
|
+
name: 'requiredIfProp',
|
|
3848
|
+
type: 'integer',
|
|
3849
|
+
requiredIf: {
|
|
3850
|
+
'prop1.subfield': 1,
|
|
3851
|
+
prop2: true
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
]
|
|
3855
|
+
});
|
|
3856
|
+
await testSchemaError(schema, {
|
|
3857
|
+
requiredIfProp: null,
|
|
3858
|
+
prop1: {
|
|
3859
|
+
subfield: 1
|
|
3860
|
+
},
|
|
3861
|
+
prop2: true
|
|
3862
|
+
}, 'requiredIfProp', 'required');
|
|
3863
|
+
});
|
|
3864
|
+
|
|
3865
|
+
it('should enforce required property with ifRequired nested logical OR', async function() {
|
|
3866
|
+
const req = apos.task.getReq();
|
|
3867
|
+
const schema = apos.schema.compose({
|
|
3868
|
+
addFields: [
|
|
3869
|
+
{
|
|
3870
|
+
name: 'prop1',
|
|
3871
|
+
type: 'object',
|
|
3872
|
+
required: false,
|
|
3873
|
+
fields: {
|
|
3874
|
+
add: {
|
|
3875
|
+
subfield: {
|
|
3876
|
+
type: 'integer'
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
},
|
|
3880
|
+
schema: [
|
|
3881
|
+
{
|
|
3882
|
+
name: 'subfield',
|
|
3883
|
+
type: 'integer'
|
|
3884
|
+
}
|
|
3885
|
+
]
|
|
3886
|
+
},
|
|
3887
|
+
{
|
|
3888
|
+
name: 'prop2',
|
|
3889
|
+
type: 'boolean',
|
|
3890
|
+
required: false
|
|
3891
|
+
},
|
|
3892
|
+
{
|
|
3893
|
+
name: 'requiredIfProp',
|
|
3894
|
+
type: 'integer',
|
|
3895
|
+
requiredIf: {
|
|
3896
|
+
$or: [
|
|
3897
|
+
{ 'prop1.subfield': 1 },
|
|
3898
|
+
{ prop2: true }
|
|
3899
|
+
]
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
]
|
|
3903
|
+
});
|
|
3904
|
+
const output = {};
|
|
3905
|
+
await apos.schema.convert(req, schema, {
|
|
3906
|
+
requiredIfProp: null,
|
|
3907
|
+
prop1: {
|
|
3908
|
+
subfield: 2
|
|
3909
|
+
},
|
|
3910
|
+
prop2: false
|
|
3911
|
+
}, output);
|
|
3912
|
+
assert(output.requiredIfProp === null);
|
|
3913
|
+
});
|
|
3914
|
+
|
|
3915
|
+
it('should error required property with ifRequired nested logical OR', async function() {
|
|
3916
|
+
const schema = apos.schema.compose({
|
|
3917
|
+
addFields: [
|
|
3918
|
+
{
|
|
3919
|
+
name: 'prop1',
|
|
3920
|
+
type: 'object',
|
|
3921
|
+
required: false,
|
|
3922
|
+
fields: {
|
|
3923
|
+
add: {
|
|
3924
|
+
subfield: {
|
|
3925
|
+
type: 'integer'
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
},
|
|
3929
|
+
schema: [
|
|
3930
|
+
{
|
|
3931
|
+
name: 'subfield',
|
|
3932
|
+
type: 'integer'
|
|
3933
|
+
}
|
|
3934
|
+
]
|
|
3935
|
+
},
|
|
3936
|
+
{
|
|
3937
|
+
name: 'prop2',
|
|
3938
|
+
type: 'boolean',
|
|
3939
|
+
required: false
|
|
3940
|
+
},
|
|
3941
|
+
{
|
|
3942
|
+
name: 'requiredIfProp',
|
|
3943
|
+
type: 'integer',
|
|
3944
|
+
requiredIf: {
|
|
3945
|
+
$or: [
|
|
3946
|
+
{ 'prop1.subfield': 1 },
|
|
3947
|
+
{ prop2: true }
|
|
3948
|
+
]
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
]
|
|
3952
|
+
});
|
|
3953
|
+
await testSchemaError(schema, {
|
|
3954
|
+
requiredIfProp: null,
|
|
3955
|
+
prop1: {
|
|
3956
|
+
subfield: 1
|
|
3957
|
+
},
|
|
3958
|
+
prop2: false
|
|
3959
|
+
}, 'requiredIfProp', 'required');
|
|
3960
|
+
});
|
|
3961
|
+
|
|
3962
|
+
it('should enforce required property with ifRequired nested not equal match', async function() {
|
|
3963
|
+
const req = apos.task.getReq();
|
|
3964
|
+
const schema = apos.schema.compose({
|
|
3965
|
+
addFields: [
|
|
3966
|
+
{
|
|
3967
|
+
name: 'prop1',
|
|
3968
|
+
type: 'object',
|
|
3969
|
+
required: false,
|
|
3970
|
+
fields: {
|
|
3971
|
+
add: {
|
|
3972
|
+
subfield: {
|
|
3973
|
+
type: 'string'
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
},
|
|
3977
|
+
schema: [
|
|
3978
|
+
{
|
|
3979
|
+
name: 'subfield',
|
|
3980
|
+
type: 'string'
|
|
3981
|
+
}
|
|
3982
|
+
]
|
|
3983
|
+
},
|
|
3984
|
+
{
|
|
3985
|
+
name: 'requiredIfProp',
|
|
3986
|
+
type: 'integer',
|
|
3987
|
+
requiredIf: {
|
|
3988
|
+
'prop1.subfield': { $ne: 'test' }
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
]
|
|
3992
|
+
});
|
|
3993
|
+
const output = {};
|
|
3994
|
+
await apos.schema.convert(req, schema, {
|
|
3995
|
+
requiredIfProp: null,
|
|
3996
|
+
prop1: {
|
|
3997
|
+
subfield: 'test'
|
|
3998
|
+
}
|
|
3999
|
+
}, output);
|
|
4000
|
+
assert(output.requiredIfProp === null);
|
|
4001
|
+
});
|
|
4002
|
+
|
|
4003
|
+
it('should error required property with ifRequired nested not equal match', async function() {
|
|
4004
|
+
const schema = apos.schema.compose({
|
|
4005
|
+
addFields: [
|
|
4006
|
+
{
|
|
4007
|
+
name: 'prop1',
|
|
4008
|
+
type: 'object',
|
|
4009
|
+
required: false,
|
|
4010
|
+
fields: {
|
|
4011
|
+
add: {
|
|
4012
|
+
subfield: {
|
|
4013
|
+
type: 'string'
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
},
|
|
4017
|
+
schema: [
|
|
4018
|
+
{
|
|
4019
|
+
name: 'subfield',
|
|
4020
|
+
type: 'string'
|
|
4021
|
+
}
|
|
4022
|
+
]
|
|
4023
|
+
},
|
|
4024
|
+
{
|
|
4025
|
+
name: 'requiredIfProp',
|
|
4026
|
+
type: 'integer',
|
|
4027
|
+
requiredIf: {
|
|
4028
|
+
'prop1.subfield': { $ne: 'test' }
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
]
|
|
4032
|
+
});
|
|
4033
|
+
await testSchemaError(schema, {
|
|
4034
|
+
requiredIfProp: null,
|
|
4035
|
+
prop1: {
|
|
4036
|
+
subfield: 'test2'
|
|
4037
|
+
}
|
|
4038
|
+
}, 'requiredIfProp', 'required');
|
|
4039
|
+
});
|
|
4040
|
+
|
|
4041
|
+
it('should ignore requiredIf property when external condition does not match', async function() {
|
|
4042
|
+
const req = apos.task.getReq();
|
|
4043
|
+
const schema = apos.schema.compose({
|
|
4044
|
+
addFields: [
|
|
4045
|
+
{
|
|
4046
|
+
name: 'age',
|
|
4047
|
+
type: 'integer',
|
|
4048
|
+
required: true,
|
|
4049
|
+
requiredIf: {
|
|
4050
|
+
'external-condition:externalCondition()': 'no'
|
|
4051
|
+
}
|
|
4052
|
+
},
|
|
4053
|
+
{
|
|
4054
|
+
name: 'shoeSize',
|
|
4055
|
+
type: 'integer',
|
|
4056
|
+
required: false
|
|
4057
|
+
}
|
|
4058
|
+
]
|
|
4059
|
+
});
|
|
4060
|
+
const output = {};
|
|
4061
|
+
await apos.schema.convert(req, schema, {
|
|
4062
|
+
shoeSize: 20
|
|
4063
|
+
}, output);
|
|
4064
|
+
assert(output.shoeSize === 20);
|
|
4065
|
+
});
|
|
4066
|
+
|
|
4067
|
+
it('should enforce requiredIf property when external condition matches', async function() {
|
|
4068
|
+
const schema = apos.schema.compose({
|
|
4069
|
+
addFields: [
|
|
4070
|
+
{
|
|
4071
|
+
name: 'age',
|
|
4072
|
+
type: 'integer',
|
|
4073
|
+
required: true,
|
|
4074
|
+
requiredIf: {
|
|
4075
|
+
'external-condition:externalCondition()': 'yes'
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
]
|
|
4079
|
+
});
|
|
4080
|
+
|
|
4081
|
+
await testSchemaError(schema, {}, 'age', 'required');
|
|
4082
|
+
});
|
|
4083
|
+
|
|
2384
4084
|
});
|
|
2385
4085
|
});
|
|
2386
4086
|
|