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 17, 2024
1 parent 4d6aa3b commit 85ad313
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 78 deletions.
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 @@ -24,13 +24,12 @@
"choices"
]
}
},
{
"$ref": "condition.json"
}
],
"properties": {
"id": {
"type": "string",
"description": "Unique identifier of the property."
},
"value": {
"$id": "#/properties/property/value",
"type": [
Expand Down Expand Up @@ -143,9 +142,6 @@
"$id": "#/properties/property/group",
"type": "string",
"description": "The custom group of a control field."
},
"condition": {
"$ref": "condition.json"
}
}
}
Expand Down
195 changes: 125 additions & 70 deletions packages/element-templates-json-schema-shared/src/defs/condition.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,149 @@
{
"$id": "#/condition",
"type": "object",
"description": "Condition(s) to activate the binding.",
"allOf": [
{
"$ref": "examples.json#/condition"
"if": {
"required": [
"id",
"condition"
]
},
"then": {
"not": {
"properties": {
"condition": {
"anyOf": [
{
"required": [
"property"
],
"properties": {
"property": {
"const": {
"$data": "2/id"
}
}
}
},
{
"required": [
"allMatch"
],
"allMatch": {
"contains": {
"properties": {
"property": {
"const": {
"$data": "2/id"
}
}
}
}
}
}
]
}
}
}
}
}
],
"definitions": {
"properties": {
"id": {
"type": "string",
"description": "Unique identifier of the property."
},
"condition": {
"type": "object",
"required": [
"property"
],
"properties": {
"type": {
"$id": "#/condition/type",
"const": "simple",
"description": "The type of the condition.",
"default": "simple"
},
"property": {
"$id": "#/condition/property",
"type": "string",
"description": "The id of the property to check."
}
},
"oneOf": [
"description": "Condition(s) to activate the binding.",
"allOf": [
{
"$ref": "examples.json#/condition"
}
],
"definitions": {
"condition": {
"type": "object",
"required": [
"property"
],
"properties": {
"equals": {
"type": [
"string",
"number",
"boolean"
]
"type": {
"$id": "#/condition/type",
"const": "simple",
"description": "The type of the condition.",
"default": "simple"
},
"property": {
"$id": "#/condition/property",
"type": "string",
"description": "The id of the property to check."
}
},
"required": [
"equals"
"oneOf": [
{
"properties": {
"equals": {
"type": [
"string",
"number",
"boolean"
]
}
},
"required": [
"equals"
]
},
{
"properties": {
"oneOf": {
"type": "array",
"items": {
"type": [
"string",
"number"
]
}
}
},
"required": [
"oneOf"
]
},
{
"properties": {
"isActive": {
"type": "boolean",
"description": "For `true`, activates the property when given property is active"
}
},
"required": [
"isActive"
]
}
]
}
},
"oneOf": [
{
"$ref": "#/properties/condition/definitions/condition"
},
{
"properties": {
"oneOf": {
"allMatch": {
"$id": "#/allMatch",
"type": "array",
"items": {
"type": [
"string",
"number"
]
}
"$ref": "#/properties/condition/definitions/condition"
},
"minItems": 1
}
},
"required": [
"oneOf"
]
},
{
"properties": {
"isActive": {
"type": "boolean",
"description": "For `true`, activates the property when given property is active"
}
},
"required": [
"isActive"
"allMatch"
]
}
]
}
},
"oneOf": [
{
"$ref": "#/definitions/condition"
},
{
"properties": {
"allMatch": {
"$id": "#/allMatch",
"type": "array",
"items": {
"$ref": "#/definitions/condition"
},
"minItems": 1
}
},
"required": [
"allMatch"
]
}
]
}
}
}
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'
}
];
Loading

0 comments on commit 85ad313

Please sign in to comment.