Skip to content

Commit d836e90

Browse files
author
Tihomir Surdilovic
authored
Events definition update - add convenience way to define multiple events that share properties (#139)
Signed-off-by: Tihomir Surdilovic <[email protected]>
1 parent 578caf0 commit d836e90

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

schema/events.json

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
"description": "Unique event name",
2121
"minLength": 1
2222
},
23+
"names": {
24+
"type": "array",
25+
"description": "List of unique event names that share the rest of the properties (source, type, kind, default)",
26+
"items": {
27+
"type": "string"
28+
},
29+
"minItems": 2,
30+
"uniqueItems": true
31+
},
2332
"source": {
2433
"type": "string",
2534
"description": "CloudEvent source"
@@ -59,16 +68,37 @@
5968
}
6069
},
6170
"then": {
62-
"required": [
63-
"name",
64-
"source",
65-
"type"
71+
"oneOf": [
72+
{
73+
"required": [
74+
"name",
75+
"source",
76+
"type"
77+
]
78+
},
79+
{
80+
"required": [
81+
"names",
82+
"source",
83+
"type"
84+
]
85+
}
6686
]
6787
},
6888
"else": {
69-
"required": [
70-
"name",
71-
"type"
89+
"oneOf": [
90+
{
91+
"required": [
92+
"name",
93+
"type"
94+
]
95+
},
96+
{
97+
"required": [
98+
"names",
99+
"type"
100+
]
101+
}
72102
]
73103
}
74104
},

schema/functions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"items": {
1111
"type": "object",
1212
"$ref": "#/definitions/function"
13-
}
13+
},
14+
"minLength": 1
1415
},
1516
"function": {
1617
"type": "object",

schema/workflow.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"$ref": "#/definitions/callbackstate"
9090
}
9191
]
92-
}
92+
},
93+
"minLength": 1
9394
}
9495
},
9596
"required": [

specification.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ defined via the `parameters` property of [function definitions](#FunctionRef-Def
365365

366366
| Parameter | Description | Type | Required |
367367
| --- | --- | --- | --- |
368-
| name | Unique event name | string | yes |
368+
| name | Unique event name | string | yes if `names` is not used |
369+
| names | List of unique event names that share the rest of the properties (source, type, kind, ...) | array | yes if `name` is not used |
369370
| source | CloudEvent source | string | yes if kind is set to "consumed", otherwise no |
370371
| type | CloudEvent type | string | yes |
371372
| kind | Defines the event is either `consumed` or `produced` by the workflow. Default is `consumed` | enum | no |
@@ -420,9 +421,62 @@ Used to define events and their correlations. These events can be either consume
420421
The Serverless Workflow specification mandates that all events conform to the [CloudEvents](https://github.com/cloudevents/spec) specification.
421422
This is to assure consistency and portability of the events format used.
422423

423-
The `name` property defines the name of the event that is unique inside the workflow definition. This event name can be
424+
The `name` property defines a single name of the event that is unique inside the workflow definition. This event name can be
424425
then referenced within [function](#Function-Definition) and [state](#State-Definition) definitions.
425426

427+
The `names` property can be used instead of `name` when you want to define multiple events that share
428+
the same `source`, `type`, `kind`, and correlation rules.
429+
To give an example, the following two events definitions are considered to be equal:
430+
431+
<table>
432+
<tr>
433+
<th>(1)</th>
434+
<th>(2)</th>
435+
</tr>
436+
<tr>
437+
<td valign="top">
438+
439+
```json
440+
{
441+
"events": [
442+
{
443+
"name": "Event1",
444+
"type": "org.events",
445+
"source": "eventssource"
446+
},
447+
{
448+
"name": "Event2",
449+
"type": "org.events",
450+
"source": "eventssource"
451+
},
452+
{
453+
"name": "Event3",
454+
"type": "org.events",
455+
"source": "eventssource"
456+
}
457+
]
458+
}
459+
```
460+
461+
</td>
462+
<td valign="top">
463+
464+
```json
465+
{
466+
"events": [
467+
{
468+
"names": ["Event1", "Event2", "Event3"],
469+
"type": "org.events",
470+
"source": "eventssource"
471+
}
472+
]
473+
}
474+
```
475+
476+
</td>
477+
</tr>
478+
</table>
479+
426480
The `source` property matches this event definition with the [source](https://github.com/cloudevents/spec/blob/master/spec.md#source-1)
427481
property of the CloudEvent required attributes.
428482

0 commit comments

Comments
 (0)