@remoteoss/json-schema-form 0.4.4-dev.20230830125207 → 0.4.5-beta.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 +12 -0
- package/dist/index.cjs +13 -2
- package/dist/index.js +13 -2
- package/dist/standalone.js +13 -2
- package/package.json +1 -1
- package/src/tests/const.test.js +86 -0
- package/src/tests/helpers.custom.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
#### 0.4.5-beta.0 (2023-08-31)
|
|
2
|
+
|
|
3
|
+
##### Changes
|
|
4
|
+
|
|
5
|
+
* Allow validation of consts to support single values ([#34](https://github.com/remoteoss/json-schema-form/pull/34)) ([bf07870d](https://github.com/remoteoss/json-schema-form/commit/bf07870d407d9b9b078882a078b9e4c7928df868))
|
|
6
|
+
|
|
7
|
+
#### 0.4.4-beta.0 (2023-08-30)
|
|
8
|
+
|
|
9
|
+
##### Chores
|
|
10
|
+
|
|
11
|
+
* **fieldset:** ignore values not matching the field type ([#44](https://github.com/remoteoss/json-schema-form/pull/44)) ([f0af54e5](https://github.com/remoteoss/json-schema-form/commit/f0af54e5d425fb78524ab150bb31629d00369a61))
|
|
12
|
+
|
|
1
13
|
#### 0.4.3-beta.0 (2023-08-09)
|
|
2
14
|
|
|
3
15
|
##### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.5-beta.0
|
|
5
|
+
Generated: Thu, 31 Aug 2023 07:23:05 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -606,6 +606,13 @@ function buildYupSchema(field, config) {
|
|
|
606
606
|
}) : true
|
|
607
607
|
);
|
|
608
608
|
}
|
|
609
|
+
function withConst(yupSchema) {
|
|
610
|
+
return yupSchema.test(
|
|
611
|
+
"isConst",
|
|
612
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
613
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
614
|
+
);
|
|
615
|
+
}
|
|
609
616
|
function withBaseSchema() {
|
|
610
617
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
611
618
|
if (customErrorMsg) {
|
|
@@ -673,6 +680,9 @@ function buildYupSchema(field, config) {
|
|
|
673
680
|
if (propertyFields.accept) {
|
|
674
681
|
validators.push(withFileFormat);
|
|
675
682
|
}
|
|
683
|
+
if (propertyFields.const) {
|
|
684
|
+
validators.push(withConst);
|
|
685
|
+
}
|
|
676
686
|
return (0, import_flow.default)(validators);
|
|
677
687
|
}
|
|
678
688
|
function getNoSortEdges(fields = []) {
|
|
@@ -943,6 +953,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
943
953
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
944
954
|
return (0, import_omitBy.default)(
|
|
945
955
|
{
|
|
956
|
+
const: node.const,
|
|
946
957
|
label: node.title,
|
|
947
958
|
readOnly: node.readOnly,
|
|
948
959
|
...node.deprecated && {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.5-beta.0
|
|
5
|
+
Generated: Thu, 31 Aug 2023 07:23:05 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -570,6 +570,13 @@ function buildYupSchema(field, config) {
|
|
|
570
570
|
}) : true
|
|
571
571
|
);
|
|
572
572
|
}
|
|
573
|
+
function withConst(yupSchema) {
|
|
574
|
+
return yupSchema.test(
|
|
575
|
+
"isConst",
|
|
576
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
577
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
578
|
+
);
|
|
579
|
+
}
|
|
573
580
|
function withBaseSchema() {
|
|
574
581
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
575
582
|
if (customErrorMsg) {
|
|
@@ -637,6 +644,9 @@ function buildYupSchema(field, config) {
|
|
|
637
644
|
if (propertyFields.accept) {
|
|
638
645
|
validators.push(withFileFormat);
|
|
639
646
|
}
|
|
647
|
+
if (propertyFields.const) {
|
|
648
|
+
validators.push(withConst);
|
|
649
|
+
}
|
|
640
650
|
return flow(validators);
|
|
641
651
|
}
|
|
642
652
|
function getNoSortEdges(fields = []) {
|
|
@@ -907,6 +917,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
907
917
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
908
918
|
return omitBy(
|
|
909
919
|
{
|
|
920
|
+
const: node.const,
|
|
910
921
|
label: node.title,
|
|
911
922
|
readOnly: node.readOnly,
|
|
912
923
|
...node.deprecated && {
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.5-beta.0
|
|
5
|
+
Generated: Thu, 31 Aug 2023 07:23:05 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11546,6 +11546,13 @@ function buildYupSchema(field, config) {
|
|
|
11546
11546
|
}) : true
|
|
11547
11547
|
);
|
|
11548
11548
|
}
|
|
11549
|
+
function withConst(yupSchema) {
|
|
11550
|
+
return yupSchema.test(
|
|
11551
|
+
"isConst",
|
|
11552
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
11553
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
11554
|
+
);
|
|
11555
|
+
}
|
|
11549
11556
|
function withBaseSchema() {
|
|
11550
11557
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
11551
11558
|
if (customErrorMsg) {
|
|
@@ -11613,6 +11620,9 @@ function buildYupSchema(field, config) {
|
|
|
11613
11620
|
if (propertyFields.accept) {
|
|
11614
11621
|
validators.push(withFileFormat);
|
|
11615
11622
|
}
|
|
11623
|
+
if (propertyFields.const) {
|
|
11624
|
+
validators.push(withConst);
|
|
11625
|
+
}
|
|
11616
11626
|
return (0, import_flow.default)(validators);
|
|
11617
11627
|
}
|
|
11618
11628
|
function getNoSortEdges(fields = []) {
|
|
@@ -11883,6 +11893,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11883
11893
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
11884
11894
|
return (0, import_omitBy.default)(
|
|
11885
11895
|
{
|
|
11896
|
+
const: node.const,
|
|
11886
11897
|
label: node.title,
|
|
11887
11898
|
readOnly: node.readOnly,
|
|
11888
11899
|
...node.deprecated && {
|
package/package.json
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createHeadlessForm } from '../createHeadlessForm';
|
|
2
|
+
|
|
3
|
+
describe('validations: const', () => {
|
|
4
|
+
it('Should work for number', () => {
|
|
5
|
+
const { handleValidation } = createHeadlessForm(
|
|
6
|
+
{
|
|
7
|
+
properties: {
|
|
8
|
+
ten_only: { type: 'number', const: 10 },
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
{ strictInputType: false }
|
|
12
|
+
);
|
|
13
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
14
|
+
expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
|
|
15
|
+
ten_only: 'The only accepted value is 10.',
|
|
16
|
+
});
|
|
17
|
+
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
18
|
+
// null is also considered valid until we fix @BUG RMT-518
|
|
19
|
+
// Expectation: To fail with error "The only accepted value is 10."
|
|
20
|
+
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('Should work for text', () => {
|
|
24
|
+
const { handleValidation } = createHeadlessForm(
|
|
25
|
+
{
|
|
26
|
+
properties: {
|
|
27
|
+
hello_only: { type: 'string', const: 'hello' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{ strictInputType: false }
|
|
31
|
+
);
|
|
32
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
33
|
+
expect(handleValidation({ hello_only: 'what' }).formErrors).toEqual({
|
|
34
|
+
hello_only: 'The only accepted value is hello.',
|
|
35
|
+
});
|
|
36
|
+
expect(handleValidation({ hello_only: 'hello' }).formErrors).toEqual(undefined);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('Should work for a conditionally applied const', () => {
|
|
40
|
+
const { handleValidation } = createHeadlessForm(
|
|
41
|
+
{
|
|
42
|
+
properties: {
|
|
43
|
+
answer: { type: 'string', oneOf: [{ const: 'yes' }, { const: 'no' }] },
|
|
44
|
+
amount: {
|
|
45
|
+
description: 'If you select yes, this needs to be exactly 10.',
|
|
46
|
+
type: 'number',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
allOf: [
|
|
50
|
+
{
|
|
51
|
+
if: { properties: { answer: { const: 'yes' } }, required: ['answer'] },
|
|
52
|
+
then: { properties: { amount: { const: 10 } }, required: ['amount'] },
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{ strictInputType: false }
|
|
57
|
+
);
|
|
58
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
59
|
+
expect(handleValidation({ answer: 'no' }).formErrors).toEqual(undefined);
|
|
60
|
+
expect(handleValidation({ answer: 'yes' }).formErrors).toEqual({ amount: 'Required field' });
|
|
61
|
+
expect(handleValidation({ answer: 'yes', amount: 1 }).formErrors).toEqual({
|
|
62
|
+
amount: 'The only accepted value is 10.',
|
|
63
|
+
});
|
|
64
|
+
expect(handleValidation({ answer: 'yes', amount: 10 }).formErrors).toEqual(undefined);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('Should show the custom error message', () => {
|
|
68
|
+
const { handleValidation } = createHeadlessForm(
|
|
69
|
+
{
|
|
70
|
+
properties: {
|
|
71
|
+
string: {
|
|
72
|
+
type: 'string',
|
|
73
|
+
const: 'hello',
|
|
74
|
+
'x-jsf-errorMessage': { const: 'You must say hello!!!' },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{ strictInputType: false }
|
|
79
|
+
);
|
|
80
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
81
|
+
expect(handleValidation({ string: 'hi' }).formErrors).toEqual({
|
|
82
|
+
string: 'You must say hello!!!',
|
|
83
|
+
});
|
|
84
|
+
expect(handleValidation({ string: 'hello' }).formErrors).toEqual(undefined);
|
|
85
|
+
});
|
|
86
|
+
});
|