diff --git a/packages/form-json-schema/src/defs/field-types/inputs.json b/packages/form-json-schema/src/defs/field-types/inputs.json index 75148ef7d..483ef8779 100644 --- a/packages/form-json-schema/src/defs/field-types/inputs.json +++ b/packages/form-json-schema/src/defs/field-types/inputs.json @@ -11,7 +11,8 @@ "taglist", "textfield", "textarea", - "expression" + "expression", + "script" ] } }, diff --git a/packages/form-json-schema/src/defs/rules/rules-required-properties.json b/packages/form-json-schema/src/defs/rules/rules-required-properties.json index 08f2fd7e8..c1767ab97 100644 --- a/packages/form-json-schema/src/defs/rules/rules-required-properties.json +++ b/packages/form-json-schema/src/defs/rules/rules-required-properties.json @@ -49,6 +49,46 @@ "computeOn" ] } + }, + { + "if": { + "properties": { + "type": { + "const": "script" + } + }, + "required": [ + "type" + ] + }, + "then": { + "allOf": [ + { + "required": [ + "jsFunction", + "functionParameters", + "computeOn" + ] + }, + { + "if": { + "properties": { + "computeOn": { + "const": "interval" + } + }, + "required": [ + "computeOn" + ] + }, + "then": { + "required": [ + "interval" + ] + } + } + ] + } } ] } diff --git a/packages/form-json-schema/src/defs/type.json b/packages/form-json-schema/src/defs/type.json index edd87a18b..097ad54b4 100644 --- a/packages/form-json-schema/src/defs/type.json +++ b/packages/form-json-schema/src/defs/type.json @@ -22,6 +22,7 @@ "separator", "table", "iframe", - "expression" + "expression", + "script" ] } \ No newline at end of file diff --git a/packages/form-json-schema/test/fixtures/js-interval-no-interval.js b/packages/form-json-schema/test/fixtures/js-interval-no-interval.js new file mode 100644 index 000000000..7787120c3 --- /dev/null +++ b/packages/form-json-schema/test/fixtures/js-interval-no-interval.js @@ -0,0 +1,43 @@ +export const form = { + type: 'default', + 'components': [ + { + type: 'script', + key: 'myField', + jsFunction: 'return 42', + functionParameters: '={\n value: 42\n}', + computeOn: 'interval' + } + ] +}; + +export const errors = [ + { + instancePath: '/components/0', + keyword: 'required', + message: "must have required property 'interval'", + params: { + missingProperty: 'interval' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/1/then/required' + }, + { + instancePath: '/components/0', + keyword: 'if', + message: 'must match "then" schema', + params: { + failingKeyword: 'then' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/1/if' + }, + { + instancePath: '/components/0', + keyword: 'if', + message: 'must match "then" schema', + params: { + failingKeyword: 'then' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/if' + } +]; + diff --git a/packages/form-json-schema/test/fixtures/js-no-props.js b/packages/form-json-schema/test/fixtures/js-no-props.js new file mode 100644 index 000000000..669361edf --- /dev/null +++ b/packages/form-json-schema/test/fixtures/js-no-props.js @@ -0,0 +1,67 @@ +export const form = { + type: 'default', + 'components': [ + { + type: 'script', + } + ] +}; + +export const errors = [ + { + instancePath: '/components/0', + keyword: 'required', + message: "must have required property 'key'", + params: { + missingProperty: 'key' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/0/then/required' + }, + { + instancePath: '/components/0', + keyword: 'if', + message: 'must match "then" schema', + params: { + failingKeyword: 'then' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/0/if' + }, + { + instancePath: '/components/0', + keyword: 'required', + message: "must have required property 'jsFunction'", + params: { + missingProperty: 'jsFunction' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/0/required' + }, + { + instancePath: '/components/0', + keyword: 'required', + message: "must have required property 'functionParameters'", + params: { + missingProperty: 'functionParameters' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/0/required' + }, + { + instancePath: '/components/0', + keyword: 'required', + message: "must have required property 'computeOn'", + params: { + missingProperty: 'computeOn' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/then/allOf/0/required' + }, + { + instancePath: '/components/0', + keyword: 'if', + message: 'must match "then" schema', + params: { + failingKeyword: 'then' + }, + schemaPath: '#/properties/components/items/allOf/0/allOf/3/if' + } +]; + + diff --git a/packages/form-json-schema/test/spec/validation.spec.js b/packages/form-json-schema/test/spec/validation.spec.js index 58d585907..7bae65ab0 100644 --- a/packages/form-json-schema/test/spec/validation.spec.js +++ b/packages/form-json-schema/test/spec/validation.spec.js @@ -110,9 +110,17 @@ describe('validation', function() { describe('rules - required properties', function() { - testForm('no-key'); + + testForm('expression-field-expression-required'); + + + testForm('js-interval-no-interval'); + + + testForm('js-no-props'); + }); @@ -136,9 +144,6 @@ describe('validation', function() { testForm('disabled-not-allowed'); - testForm('expression-field-expression-required'); - - testForm('action-not-allowed');