Skip to content

Commit

Permalink
feat: disallow condition depending on the containing property
Browse files Browse the repository at this point in the history
Closes #125
  • Loading branch information
barmac committed Jan 19, 2024
1 parent 34db754 commit 2ce41dd
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,20 @@
"property": "missing property name for condition"
}
}
},
{
"path": [
"definitions",
"properties",
"allOf",
0,
"items",
"allOf",
1,
"allOf",
0,
"then"
],
"errorMessage": "Invalid condition.property, must be different than property.id"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,56 @@
]
}
},
"allOf": [
{
"$comment": "property#condition should not depend on property#id",
"if": {
"required": [
"id",
"condition"
],
"properties": {
"condition": {
"anyOf": [
{
"required": [
"property"
],
"properties": {
"property": {
"const": {
"$data": "2/id"
}
}
}
},
{
"required": [
"allMatch"
],
"allMatch": {
"contains": {
"properties": {
"property": {
"const": {
"$data": "2/id"
}
}
}
}
}
}
]
}
}
},
"then": {
"not": {
"required": [ "condition" ]
}
}
}
],
"properties": {
"id": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function createValidator(schema, errors) {

const ajv = new Ajv({
allErrors: true,
strict: false
strict: false,
$data: true
});

AjvErrors(ajv);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export const template = {
'name': 'Condition',
'id': 'example.com.condition',
'appliesTo': [
'bpmn:ServiceTask'
],
'properties': [
{
'id': 'myId',
'label': 'input 1',
'type': 'String',
'binding': {
'type': 'property',
'name': 'input1'
},
'condition': {
'allMatch': [
{
'type': 'simple',
property: 'myId',
equals: 'text'
}
]
}
}
]
};

export const errors = [
{
keyword: 'errorMessage',
dataPath: '/properties/0',
schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/errorMessage',
params: {
errors: [
{
keyword: 'not',
dataPath: '/properties/0',
schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/not',
params: {},
message: 'should NOT be valid',
emUsed: true
}
]
},
message: 'Invalid condition.property, must be different than property.id'
},
{
keyword: 'if',
dataPath: '/properties/0',
schemaPath: '#/allOf/0/items/allOf/1/allOf/0/if',
params: { failingKeyword: 'then' },
message: 'should match "then" schema'
},
{
keyword: 'type',
dataPath: '',
schemaPath: '#/oneOf/1/type',
params: { type: 'array' },
message: 'should be array'
},
{
keyword: 'oneOf',
dataPath: '',
schemaPath: '#/oneOf',
params: { passingSchemas: null },
message: 'should match exactly one schema in oneOf'
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export const template = {
'name': 'Condition',
'id': 'example.com.condition',
'appliesTo': [
'bpmn:ServiceTask'
],
'properties': [
{
'id': 'myId',
'label': 'input 1',
'type': 'String',
'binding': {
'type': 'property',
'name': 'input1'
},
'condition': {
property: 'myId',
equals: 'text'
}
}
]
};

export const errors = [
{
keyword: 'errorMessage',
dataPath: '/properties/0',
schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/errorMessage',
params: {
errors: [
{
keyword: 'not',
dataPath: '/properties/0',
schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/not',
params: {},
message: 'should NOT be valid',
emUsed: true
}
]
},
message: 'Invalid condition.property, must be different than property.id'
},
{
keyword: 'if',
dataPath: '/properties/0',
schemaPath: '#/allOf/0/items/allOf/1/allOf/0/if',
params: { failingKeyword: 'then' },
message: 'should match "then" schema'
},
{
keyword: 'type',
dataPath: '',
schemaPath: '#/oneOf/1/type',
params: { type: 'array' },
message: 'should be array'
},
{
keyword: 'oneOf',
dataPath: '',
schemaPath: '#/oneOf',
params: { passingSchemas: null },
message: 'should match exactly one schema in oneOf'
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const template = {
}
},
{
'id': 'someId',
'label': 'default condition type',
'type': 'String',
'condition': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ describe('validation', function() {


testTemplate('condition-dropdown-choices-invalid');


testTemplate('condition-on-itself');


testTemplate('condition-allMatch-on-itself');
});


Expand Down

0 comments on commit 2ce41dd

Please sign in to comment.