Skip to content

Commit

Permalink
feat: script component schema definition
Browse files Browse the repository at this point in the history
Related to #1102
  • Loading branch information
Skaiir committed Apr 4, 2024
1 parent 2c5f4de commit 5a340ef
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/form-json-schema/src/defs/field-types/inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"taglist",
"textfield",
"textarea",
"expression"
"expression",
"script"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
]
}
}
]
}
3 changes: 2 additions & 1 deletion packages/form-json-schema/src/defs/type.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"separator",
"table",
"iframe",
"expression"
"expression",
"script"
]
}
43 changes: 43 additions & 0 deletions packages/form-json-schema/test/fixtures/js-interval-no-interval.js
Original file line number Diff line number Diff line change
@@ -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'
}
];

67 changes: 67 additions & 0 deletions packages/form-json-schema/test/fixtures/js-no-props.js
Original file line number Diff line number Diff line change
@@ -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'
}
];


13 changes: 9 additions & 4 deletions packages/form-json-schema/test/spec/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

});


Expand All @@ -136,9 +144,6 @@ describe('validation', function() {
testForm('disabled-not-allowed');


testForm('expression-field-expression-required');


testForm('action-not-allowed');


Expand Down

0 comments on commit 5a340ef

Please sign in to comment.