-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateMachines.yml
535 lines (514 loc) · 15.6 KB
/
StateMachines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
openapi: "3.0.3"
info:
title: State Machines Micro-Service
description:
This is the web interface of a state machine micro service. It allows the
creation of new state charts. The start of a state chart, which creates a
state machine. And sending queries to this state machine about its current
state.
State charts are considered as a hierarchy of state-nodes, associated with
attributes (a.k.a. variables) and guarded transitions.
The Ids of state-chart nodes, variables and state-machine-states are defined
URI pathes, which reflects exactly the hierarchy of the state-nodes.
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: "0.1"
# servers:
# - https://state-machine.org/
paths:
/state-chart:
get:
summary: Get the list of all state chart Ids managed by this service.
responses:
'200':
description:
An array with all state-charts managed by this service.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Node'
post:
summary: Creates a new state-chart with the JSON description in the body
of this request.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
responses:
'200':
description:
The state-chart was successfully created.
The id in the provided node is the id, by which a
state-machine can be created.
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
'400':
description:
The state-chart wasn't created. An indication about the problem
will be provided in the text.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/state-chart/{id}:
get:
summary: Get the details of an paritcular state-chart
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description:
Delivers the requested state-chart
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
'404':
description:
The requested state-chart couldn't be found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
summary: Updates the state-chart with the JSON description in the request
body.
parameters:
- name: id
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
responses:
'200':
description:
The state-chart was successfully created.
The id in the provided node is the id, by which a
state-machine can be created.
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
'400':
description:
The state-chart wasn't created. An indication about the problem
will be provided in the text.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description:
The state-chart wasn't found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/action:
get:
summary: Get the list of all actions, provided by this service.
responses:
'200':
description:
The list of the actions, provided by this service.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ActionInfo'
/start/{state-chart-id}:
post:
summary: Creates a new state-machine form the given state-chart
parameters:
- name: state-chart-id
in: path
required: true
schema:
$ref: '#/components/schemas/NodeId'
description:
In contrast to a state-chart, a state machine has active states, with
attributes. A state machine with all attribues will be instantiated.
responses:
'200':
description:
The Id of the new state-machine.
content:
application/json:
schema:
$ref: '#/components/schemas/StateId'
'404':
description:
The requested state-chart couldn't be found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/send/{state-machine-id}/{event-id}:
post:
summary: Send an event to a state machine
description:
A state machine may change the state due to two events.
1. The event on one of the transitions of the current state is fired.
2. The condition on one of the transitions of the current state becomes true.
Sending an event is a way to fire the event.
parameters:
- name: state-machine-id
in: path
required: true
schema:
$ref: '#/components/schemas/StateId'
- name: event-id
in: path
required: true
schema:
$ref: '#/components/schemas/EventId'
responses:
'200':
description:
It was possible to fire the event in the current state of the state machine.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/EventId'
'404':
description:
The requested state-machine-id or event-id couldn't be found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/set-var/{state-machine-id}/{variable-id}:
post:
summary: Set a new value to an existing variable.
description:
A state machine may change the state due to two events.
1. The event on one of the transitions of the current state is fired.
2. The condition on one of the transitions of the current state becomes true.
Setting a variable may trigger a condition.
parameters:
- name: state-machine-id
in: path
required: true
schema:
$ref: '#/components/schemas/StateId'
- name: variable-id
in: path
required: true
schema:
$ref: '#/components/schemas/VariableId'
responses:
'200':
description:
It was possible to change the variable values. A list of the
current valid events is provided as a result.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/EventId'
'404':
description:
The requested state-machine-id or variable-id couldn't be found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
# /state-machine:
# get:
# summary: Provides a list of all state-machines and their current state.
# responses:
# '200':
# description:
# The
# content:
# application/json:
# schema:
# $ref:
components:
schemas:
Node:
# descripton:
# The node may represent a single state or a complete state-chart.
# If it has no child node, it must have a parent node.
# If it has child nodes.
# A start node is identified by the id-end ".../start".
type: object
properties:
id:
$ref: '#/components/schemas/NodeId'
description:
type: string
maxLength: 65536
example: The description and intention of the state-chart.
on-entry:
$ref: '#/components/schemas/ActionCall'
on-exit:
$ref: '#/components/schemas/ActionCall'
start-node:
$ref: '#/components/schemas/NodeId'
out-transitions:
type: array
items:
$ref: '#/components/schemas/Transition'
attributes:
type: array
items:
$ref: '#/components/schemas/VariableDeclaration'
nodes:
type: array
items:
$ref: '#/components/schemas/Node'
required:
- id
VariableDeclaration:
# descripton:
# The declaration of state attributes. Actions may operate on these
# attributes.
type: object
properties:
name:
type: string
pattern: '\w[\w\-_]*'
maxLength: 1024
example: count
type:
# description:
# The scalar type of the variable.
type: string
pattern: '(string|integer|number|boolean)'
maxLength: 7
example: number
value:
# description:
# The required initial value of a particular variable (parameter or
# attribute).
oneOf:
- type: string
- type: integer
- type: number
- type: boolean
required:
- name
- type
- value
Transition:
# description:
# The transition connects a node, where it is associated with, with
# another node. The transition will be guarded by an event or a
# condition. The transition can be connected also with an
# example:
# { guard: { event: "sme:///open", to: "scn:///Bug/in-progress" }
type: object
properties:
guard:
$ref: '#/components/schemas/Guard'
to:
$ref: '#/components/schemas/NodeId'
action:
$ref: '#/components/schemas/ActionCall'
required:
- guard
- to
ActionInfo:
# description:
# This object provides information regarding a particular action.
# It cannot be changed externaly, but is just for information purposes.
# All actions *must* be implemented by the server, providing this
# information.
type: object
properties:
name:
$ref: '#/components/schemas/ActionId'
description:
type: string
maxLength: 65536
parameters:
type: array
maxLength: 1024
items:
$ref: '#/components/schemas/VariableDeclaration'
required:
- name
- description
- parameters
Guard:
# description:
# A guard is checking, if the transition should be fired.
# It will be fired, if the configured event was fired or if the
# configured predicate is true.
# example:
# { event: "sme:///open" }
# { predicate: { name: 'eq', parameters: [ "sdv://4711/Bug/age", "21d" ] } }
properties:
event:
$ref: '#/components/schemas/EventId'
predicate:
$ref: '#/components/schemas/PredicateCall'
ActionCall:
type: object
properties:
name:
$ref: '#/components/schemas/ActionId'
parameters:
type: array
items:
$ref: '#/components/schemas/Parameter'
required:
- name
- parameters
PredicateCall:
# description:
# A predicate, which guards a transition.
# example:
# { name: 'eq', parameters: [ "sdv://4711/Bug/age", "21d" ] }
type: object
properties:
name:
$ref: '#/components/schemas/PredicateId'
parameters:
type: array
maxLength: 128
items:
oneOf:
- $ref: '#/components/schemas/VariableId'
- type: string
- type: integer
- type: number
- type: boolean
required:
- name
- parameters
Parameter:
# description:
# This is the definition of an action parameter.
# example:
# { name="email", value="[email protected]" }
type: object
properties:
name:
$ref: '#/components/schemas/VariableId'
value:
oneOf:
- type: string
maxLength: 1024
- type: integer
- type: number
- type: boolean
required:
- name
- value
StateMachine:
# description:
# The instance of a state-chart with current states and the current
# values of the variables.
type: object
properties:
id:
$ref: '#/components/schemas/StateId'
state-chart:
$ref: '#/components/schemas/Node'
current-state:
$ref: '#/components/schemas/StateId'
required:
- state-chart
- root-state
- current-state
ActionId:
# description:
# example:
type: string
maxLength: 1024
pattern: '^\p{L}[\w\-]*$'
PredicateId:
# description:
# The id of a predicate.
# example:
# equals
# greater
# lesser
type: string
maxLength: 1024
pattern: '^\p{L}[\w\-]*$'
EventId:
# description:
# The id of an event is not directly associated with a state, but with
# the transitions in the state chart. It must not be declared, but will
# be derived from the transitions.
# example:
# sme:///open
# sme:///close
# sme:///assign
type: string
maxLength: 1024
pattern: '^sme:///\p{L}[\w\.\-]*$'
StateId:
# description:
# The id of a state or state diagram.
# example:
# sms:///4711/ - The Id of a state-machine
# sms:///4711/start - The Id of a particular state in this machine
# sms:///4711/in-progress/checking - The Id of a particular sub-state of the machine
type: string
pattern: '^sms:///\w[\w\.\-]*(/\w[\w\.\-]*)*$'
maxLength: 1024
VariableId:
# description
# The id of a variable, constructed from the state id
# smv://{state-machine-id}/{node-id}/{var-name}
# example:
# smv:///4711/assignee - A global state-machine-variable
# smv:///4711/in-progress/since - A local variable of a sub-state.
type: string
pattern: '^smv:///\w[\w\.\-]*(/\w[\w\.\-]*)*$'
maxLength: 1024
NodeId:
# description:
# The id of a node is constructed by the hierarchy of node ids.
# example:
# scn://Bug/created
# scn://Bug/fixing
type: string
maxLength: 1024
pattern: '^scn:///\p{L}[\w\.\-]*(/\w[\w\.\-]*)*$'
Error:
# description:
# A structured way to deliver a error to the client.
# example:
# { id=1000, message: "Inconsistent state-chart definition." }
type: object
properties:
id:
type: integer
message:
type: string
maxLength: 1024
required:
- id
- message
responses:
NotFound:
description:
The requested ressource wasn't found.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"