@cxtms/cx-schema 1.9.11 → 1.9.12
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/package.json
CHANGED
|
@@ -44,25 +44,34 @@
|
|
|
44
44
|
"items": {
|
|
45
45
|
"type": "object",
|
|
46
46
|
"properties": {
|
|
47
|
-
"
|
|
47
|
+
"rule": {
|
|
48
48
|
"type": "string",
|
|
49
|
-
"enum": ["required"
|
|
50
|
-
"description": "
|
|
51
|
-
},
|
|
52
|
-
"expression": {
|
|
53
|
-
"type": "string",
|
|
54
|
-
"description": "Expression to validate (for expression type)"
|
|
49
|
+
"enum": ["required"],
|
|
50
|
+
"description": "Rule type. Use 'required' to check a value is not null or empty"
|
|
55
51
|
},
|
|
56
52
|
"value": {
|
|
53
|
+
"description": "Value to validate (used with rule: required). Typically a template expression e.g. {{ fieldName }}",
|
|
54
|
+
"oneOf": [
|
|
55
|
+
{ "type": "string" },
|
|
56
|
+
{ "type": "number" },
|
|
57
|
+
{ "type": "boolean" },
|
|
58
|
+
{ "type": "object" },
|
|
59
|
+
{ "type": "null" }
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"conditions": {
|
|
57
63
|
"type": "string",
|
|
58
|
-
"description": "
|
|
64
|
+
"description": "NCalc expression evaluated against task variables. Fails when expression is false. Variables use bracket syntax e.g. [orderId] > 0"
|
|
59
65
|
},
|
|
60
66
|
"message": {
|
|
61
67
|
"type": "string",
|
|
62
|
-
"description": "
|
|
68
|
+
"description": "Custom error message returned when validation fails"
|
|
63
69
|
}
|
|
64
70
|
},
|
|
65
|
-
"
|
|
71
|
+
"anyOf": [
|
|
72
|
+
{ "required": ["rule"] },
|
|
73
|
+
{ "required": ["conditions"] }
|
|
74
|
+
]
|
|
66
75
|
}
|
|
67
76
|
}
|
|
68
77
|
},
|
|
@@ -39,20 +39,40 @@ The query result is a dictionary. The `mapping` path extracts from the result. O
|
|
|
39
39
|
|
|
40
40
|
Validates data against rules. Commonly used in Before entity triggers to block invalid changes.
|
|
41
41
|
|
|
42
|
+
Two rule types:
|
|
43
|
+
- **`rule: "required"`** — checks that `value` is not null or empty
|
|
44
|
+
- **Condition expression** — evaluates an NCalc `conditions` expression (no `rule` property needed)
|
|
45
|
+
|
|
42
46
|
```yaml
|
|
43
47
|
- task: "Validation/Validate@1"
|
|
44
48
|
name: ValidateOrder
|
|
45
49
|
inputs:
|
|
46
50
|
rules:
|
|
47
|
-
-
|
|
48
|
-
|
|
51
|
+
- rule: "required"
|
|
52
|
+
value: "{{ Data.GetOrder.order.status? }}"
|
|
53
|
+
message: "Order status is required"
|
|
54
|
+
- conditions: "[Data.GetOrder.order.status] != 'Cancelled'"
|
|
49
55
|
message: "Cannot modify cancelled orders"
|
|
50
|
-
-
|
|
51
|
-
condition: "[Data.GetOrder.order.amount] > 0"
|
|
56
|
+
- conditions: "[Data.GetOrder.order.amount] > 0"
|
|
52
57
|
message: "Amount must be positive"
|
|
53
58
|
```
|
|
54
59
|
|
|
55
|
-
If validation fails, execution stops and
|
|
60
|
+
If validation fails and `continueOnError` is false (default), execution stops and a `ValidationException` is returned. Set `continueOnError: true` to collect errors in the `errors` output instead:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
- task: "Validation/Validate@1"
|
|
64
|
+
name: ValidateOrder
|
|
65
|
+
continueOnError: true
|
|
66
|
+
inputs:
|
|
67
|
+
rules:
|
|
68
|
+
- rule: "required"
|
|
69
|
+
value: "{{ Data.GetOrder.order.status? }}"
|
|
70
|
+
message: "Order status is required"
|
|
71
|
+
- conditions: "[Data.GetOrder.order.amount] > 0"
|
|
72
|
+
message: "Amount must be positive"
|
|
73
|
+
outputs:
|
|
74
|
+
- name: errors
|
|
75
|
+
```
|
|
56
76
|
|
|
57
77
|
## Workflow/Execute
|
|
58
78
|
|