@trayio/commons 4.69.0 → 4.71.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.
|
@@ -39,7 +39,7 @@ const TypeCodec_1 = require("../codec/TypeCodec");
|
|
|
39
39
|
const Try_1 = require("../try/Try");
|
|
40
40
|
const draft04SchemaUrl = 'http://json-schema.org/draft-04/schema';
|
|
41
41
|
const schemaProperty = '$schema';
|
|
42
|
-
const ajv = new ajv_draft_04_1.default({ strict: false, removeAdditional:
|
|
42
|
+
const ajv = new ajv_draft_04_1.default({ strict: false, removeAdditional: true });
|
|
43
43
|
/*
|
|
44
44
|
We define additional formats for the JSON schema
|
|
45
45
|
See: https://ajv.js.org/packages/ajv-formats.html#formats
|
|
@@ -47,7 +47,7 @@ const ajv = new ajv_draft_04_1.default({ strict: false, removeAdditional: 'all'
|
|
|
47
47
|
(0, ajv_formats_1.default)(ajv);
|
|
48
48
|
const ajvWithCoercion = new ajv_draft_04_1.default({
|
|
49
49
|
strict: false,
|
|
50
|
-
removeAdditional:
|
|
50
|
+
removeAdditional: true,
|
|
51
51
|
coerceTypes: true,
|
|
52
52
|
});
|
|
53
53
|
(0, ajv_formats_1.default)(ajvWithCoercion);
|
|
@@ -571,7 +571,7 @@ describe('DynamicSchema', () => {
|
|
|
571
571
|
it('should return a Right with the value when strict is false and value matches the schema', () => {
|
|
572
572
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
573
573
|
if (E.isRight(schema)) {
|
|
574
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, value, O.some(
|
|
574
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, value, O.some(true));
|
|
575
575
|
expect(E.isRight(result)).toBe(true);
|
|
576
576
|
if (E.isRight(result)) {
|
|
577
577
|
expect(result.right).toEqual(value);
|
|
@@ -581,17 +581,27 @@ describe('DynamicSchema', () => {
|
|
|
581
581
|
it('should return a Right with non extra values when value matches the schema but has extra fields', () => {
|
|
582
582
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
583
583
|
if (E.isRight(schema)) {
|
|
584
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields, O.some(
|
|
584
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields, O.some(true));
|
|
585
585
|
expect(E.isRight(result)).toBe(true);
|
|
586
586
|
if (E.isRight(result)) {
|
|
587
587
|
expect(result.right).toEqual(value);
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
590
|
});
|
|
591
|
+
it('should return a Right with extra values when value matches the schema but has extra fields and strict is false', () => {
|
|
592
|
+
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
593
|
+
if (E.isRight(schema)) {
|
|
594
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields, O.some(false));
|
|
595
|
+
expect(E.isRight(result)).toBe(true);
|
|
596
|
+
if (E.isRight(result)) {
|
|
597
|
+
expect(result.right).toEqual(valueWithExtraFields);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
});
|
|
591
601
|
it('should return a Right with when value matches the schema but has coerceable types', () => {
|
|
592
602
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
593
603
|
if (E.isRight(schema)) {
|
|
594
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithCoerceableTypes, O.some(
|
|
604
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithCoerceableTypes, O.some(true), true);
|
|
595
605
|
expect(E.isRight(result)).toBe(true);
|
|
596
606
|
if (E.isRight(result)) {
|
|
597
607
|
expect(result.right).toEqual(value);
|