rsmp_schema 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aeef79729314dc2a8440a0697560f02608622a0c46ffaa635d6ec18b7afc3a43
4
- data.tar.gz: 04c0d1bbc1039a924ca63e70bb29bafceb0dbbc5d8a95e54d9a39686f7d34847
3
+ metadata.gz: badefc8cfd4f1df332cad770cd02b9394d19fe327860206cf59ed745b7f051cd
4
+ data.tar.gz: d04eebeede6747cd5b245ef66c83b1d0256c14bd7df21f6f2d94176bfd146536
5
5
  SHA512:
6
- metadata.gz: d8905cc3b11e5fc4aa9721e07a4b4f0de852f872af7e7dc364e9fa63e09720870bbc1e2cd3cb5efd816d35c641e128e829a2ed2b7de079084f7d3aff96b13688
7
- data.tar.gz: efea6b4d539ba3bd686900beb2595cf72b17c890208193204fab0fe040faa671eb49ec67ba0973bc1f7077a8a1be392d6d4f4c281a57c78e633fa2eebd26653d
6
+ metadata.gz: 4ba94206d0fc23153dff5474dc4fea59112d24319a7bf1932ea5ada2bf1f77412b2231913cce74f11f69f9783fa319aff41b0a57cc08a35770ee401e7c01205f
7
+ data.tar.gz: afb8edf5054d2e430b174bb881b149eab1487891ef774239e3cbc9b87419b1afbbc2aa7a6504e35a512c7694480c762c08e42a77c72a84fa673e2d3c3ed9db63
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp_schema (0.1.1)
4
+ rsmp_schema (0.2.0)
5
5
  json_schemer (~> 0.2.21)
6
6
  thor (~> 1.2.1)
7
7
 
@@ -21,67 +21,61 @@ module RSMP
21
21
  JSON.generate(item,@@json_options)
22
22
  end
23
23
 
24
+ # convert a yaml item to json schema
24
25
  def self.build_value item
25
26
  out = {}
27
+ out['description'] = item['description'] if item['description']
26
28
 
27
- if item['description']
28
- out["description"] = item['description']
29
+ if item['type'] =~/_list$/
30
+ handle_string_list item, out
31
+ else
32
+ handle_types item, out
33
+ handle_enum item, out
34
+ handle_pattern item, out
29
35
  end
36
+ wrap_refs out
37
+ end
30
38
 
31
- if item['list']
32
- case item['type']
33
- when "boolean"
34
- out["$ref"] = "../../../core/3.1.1/definitions.json#/boolean_list"
35
- when "integer", "ordinal", "unit", "scale", "long"
36
- out["$ref"] = "../../../core/3.1.1/definitions.json#/integer_list"
37
- when "string"
38
- out["$ref"] = "../../../core/3.1.1/definitions.json#/string_list"
39
- else
40
- raise "Error: List of #{item['type']} is not supported: #{item.inspect}"
41
- end
42
-
43
- if item["values"]
44
- value_list = item["values"].keys.join('|')
45
- out['pattern'] = /(?-mix:^(#{value_list})(?:,(#{value_list}))*$)/
46
- end
47
-
48
- if item["pattern"]
49
- puts "Warning: Pattern not support for lists: #{item.inspect}"
50
- end
39
+ # convert an item which is not a string-list, to json schema
40
+ def self.handle_types item, out
41
+ case item['type']
42
+ when "string", "base64"
43
+ out["type"] = "string"
44
+ when "boolean"
45
+ out["$ref"] = "../../../core/3.1.1/definitions.json#/boolean"
46
+ when "timestamp"
47
+ out["$ref"] = "../../../core/3.1.1/definitions.json#/timestamp"
48
+ when "integer", "ordinal", "unit", "scale", "long"
49
+ out["$ref"] = "../../../core/3.1.1/definitions.json#/integer"
50
+ when 'array' # a json array
51
+ build_json_array item['items'], out
51
52
  else
52
- case item['type']
53
- when "string", "base64"
54
- out["type"] = "string"
55
- when "boolean"
56
- out["$ref"] = "../../../core/3.1.1/definitions.json#/boolean"
57
- when "timestamp"
58
- out["$ref"] = "../../../core/3.1.1/definitions.json#/timestamp"
59
- when "integer", "ordinal", "unit", "scale", "long"
60
- out["$ref"] = "../../../core/3.1.1/definitions.json#/integer"
61
- else
62
- out["type"] = "string"
63
- end
64
-
65
- if item["values"]
66
- case item["values"]
67
- when Hash
68
- out["enum"] = item["values"].keys.sort
69
- when Array
70
- out["enum"] = item["values"].sort
71
- else
72
- raise "Error: Values must be specified as either a Hash or an Array"
73
- end
74
-
75
- end
53
+ out["type"] = "string"
54
+ end
55
+ end
76
56
 
77
- if item["pattern"]
78
- out["pattern"] = item["pattern"]
79
- end
57
+ # convert an yaml item with type: array to json schema
58
+ def self.build_json_array item, out
59
+ required = item.select { |k,v| v['optional'] != true }.keys.sort
60
+ out.merge!({
61
+ "type" => "array",
62
+ "items" => {
63
+ "type" => "object",
64
+ "required" => required,
65
+ "additionalProperties": false
66
+ }
67
+ })
68
+ out["items"]["properties"] = {}
69
+ item.each_pair do |key,v|
70
+ out["items"]["properties"][key] = build_value(v)
80
71
  end
72
+ out
73
+ end
81
74
 
82
- # with draft-07 and older, using a $ref mean all other properties are ignored.
83
- # to avoid this we need to use an allOf.
84
- # this is changed from draft-08, but unfortunately, there is still no Ruby validator for that
75
+ # with draft-07 and older, using a $ref mean all other properties are ignored.
76
+ # to avoid this we need to use an allOf.
77
+ # this is changed from draft-08, but unfortunately, there is still no Ruby validator for that
78
+ def self.wrap_refs out
85
79
  if out.keys.include? '$ref'
86
80
  ref = out.delete '$ref'
87
81
  { "allOf" => [out,{"$ref"=>ref}]}
@@ -90,6 +84,47 @@ module RSMP
90
84
  end
91
85
  end
92
86
 
87
+ # convert a yaml item with list: true to json schema
88
+ def self.handle_string_list item, out
89
+ case item['type']
90
+ when "boolean_list"
91
+ out["$ref"] = "../../../core/3.1.1/definitions.json#/boolean_list"
92
+ when "integer_list"
93
+ out["$ref"] = "../../../core/3.1.1/definitions.json#/integer_list"
94
+ when "string_list"
95
+ out["$ref"] = "../../../core/3.1.1/definitions.json#/string_list"
96
+ else
97
+ raise "Error: List of #{item['type']} is not supported: #{item.inspect}"
98
+ end
99
+
100
+ if item["values"]
101
+ value_list = item["values"].keys.join('|')
102
+ out['pattern'] = /(?-mix:^(#{value_list})(?:,(#{value_list}))*$)/
103
+ end
104
+
105
+ puts "Warning: Pattern not support for lists: #{item.inspect}" if item["pattern"]
106
+ end
107
+
108
+ # convert yaml values to jsons schema enum
109
+ def self.handle_enum item, out
110
+ if item["values"]
111
+ case item["values"]
112
+ when Hash
113
+ out["enum"] = item["values"].keys.sort
114
+ when Array
115
+ out["enum"] = item["values"].sort
116
+ else
117
+ raise "Error: Values must be specified as either a Hash or an Array"
118
+ end
119
+ end
120
+ end
121
+
122
+ # convert yaml pattern to jsons schema
123
+ def self.handle_pattern item, out
124
+ out["pattern"] = item["pattern"] if item["pattern"]
125
+ end
126
+
127
+ # convert yaml alarm/status/command item to corresponding jsons schema
93
128
  def self.build_item item, property_key: 'v'
94
129
  json = { "allOf" => [ { "description" => item['description'] } ] }
95
130
  if item['arguments']
@@ -104,6 +139,7 @@ module RSMP
104
139
  json
105
140
  end
106
141
 
142
+ # convert alarms to json schema
107
143
  def self.output_alarms out, items
108
144
  list = items.keys.sort.map do |key|
109
145
  {
@@ -121,11 +157,13 @@ module RSMP
121
157
  items.each_pair { |key,item| output_alarm out, key, item }
122
158
  end
123
159
 
160
+ # convert an alarm to json schema
124
161
  def self.output_alarm out, key, item
125
162
  json = build_item item
126
163
  out["alarms/#{key}.json"] = output_json json
127
164
  end
128
165
 
166
+ # convert statuses to json schema
129
167
  def self.output_statuses out, items
130
168
  list = [ { "properties" => { "sCI" => { "enum"=> items.keys.sort }}} ]
131
169
  items.keys.sort.each do |key|
@@ -139,11 +177,13 @@ module RSMP
139
177
  items.each_pair { |key,item| output_status out, key, item }
140
178
  end
141
179
 
180
+ # convert a status to json schema
142
181
  def self.output_status out, key, item
143
182
  json = build_item item, property_key:'s'
144
183
  out["statuses/#{key}.json"] = output_json json
145
184
  end
146
185
 
186
+ # convert commands to json schema
147
187
  def self.output_commands out, items
148
188
  list = [ { "properties" => { "cCI" => { "enum"=> items.keys.sort }}} ]
149
189
  items.keys.sort.each do |key|
@@ -164,12 +204,14 @@ module RSMP
164
204
  items.each_pair { |key,item| output_command out, key, item }
165
205
  end
166
206
 
207
+ # convert a command to json schema
167
208
  def self.output_command out, key, item
168
209
  json = build_item item
169
210
  json["allOf"].first["properties"]['cO'] = { "const" => item['command'] }
170
211
  out["commands/#{key}.json"] = output_json json
171
212
  end
172
213
 
214
+ # output the json schema root
173
215
  def self.output_root out, meta
174
216
  json = {
175
217
  "name"=> meta['name'],
@@ -197,6 +239,7 @@ module RSMP
197
239
  out["sxl.json"] = output_json json
198
240
  end
199
241
 
242
+ # generate the json schema from a string containing yaml
200
243
  def self.generate sxl
201
244
  out = {}
202
245
  output_root out, sxl[:meta]
@@ -206,6 +249,7 @@ module RSMP
206
249
  out
207
250
  end
208
251
 
252
+ # convert yaml to json schema and write files to a folder
209
253
  def self.write sxl, folder
210
254
  out = generate sxl
211
255
  out.each_pair do |relative_path,str|
@@ -215,9 +259,7 @@ module RSMP
215
259
  file.puts str
216
260
  end
217
261
  end
218
-
219
262
  end
220
-
221
263
  end
222
264
  end
223
265
  end
@@ -1,5 +1,5 @@
1
1
  module RSMP
2
2
  module Schema
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -177,15 +177,13 @@ objects:
177
177
  During maintenance work the controller might be using dark mode (no output to the signal heads).
178
178
  arguments:
179
179
  intersection:
180
- list: true
181
- type: integer
180
+ type: integer_list
182
181
  description: |-
183
182
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
184
183
  Other value: Intersection number
185
184
  range: "[0-255]"
186
185
  status:
187
- list: true
188
- type: boolean
186
+ type: boolean_list
189
187
  description: |-
190
188
  False: Traffic Light Controller in dark mode
191
189
  True: Traffic Light Controller not in dark mode
@@ -196,15 +194,13 @@ objects:
196
194
  Signal timings is controlled manually by service personnel using the operating panel of the controller.
197
195
  arguments:
198
196
  intersection:
199
- list: true
200
- type: integer
197
+ type: integer_list
201
198
  description: |-
202
199
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
203
200
  Other value: Intersection number
204
201
  range: "[0-255]"
205
202
  status:
206
- list: true
207
- type: boolean
203
+ type: boolean_list
208
204
  description: |-
209
205
  False: Manual control inactive
210
206
  True: Manual control active
@@ -215,15 +211,13 @@ objects:
215
211
  Usually only used in case normal detectors can't be used, e.g. during maintenance work.
216
212
  arguments:
217
213
  intersection:
218
- list: true
219
- type: integer
214
+ type: integer_list
220
215
  description: |-
221
216
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
222
217
  Other value: Intersection number
223
218
  range: "[0-255]"
224
219
  status:
225
- list: true
226
- type: boolean
220
+ type: boolean_list
227
221
  description: |-
228
222
  False: Fixed time control inactive
229
223
  True: Fixed time control active
@@ -234,15 +228,13 @@ objects:
234
228
  Used to determine if the controller is operating independently or operating with other controllers (coordination).
235
229
  arguments:
236
230
  intersection:
237
- list: true
238
- type: integer
231
+ type: integer_list
239
232
  description: |-
240
233
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
241
234
  Other value: Intersection number
242
235
  range: "[0-255]"
243
236
  status:
244
- list: true
245
- type: boolean
237
+ type: boolean_list
246
238
  description: |-
247
239
  False: Isolated control disabled
248
240
  True: Isolated control enabled (Vehicle actuated control or Fixed time control)
@@ -253,15 +245,13 @@ objects:
253
245
  Yellow flash may be used during a serious fault (depending on configuration) or maintenance work. It can also be manually set using M0001.
254
246
  arguments:
255
247
  intersection:
256
- list: true
257
- type: integer
248
+ type: integer_list
258
249
  description: |-
259
250
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
260
251
  Other value: Intersection number
261
252
  range: "[0-255]"
262
253
  status:
263
- list: true
264
- type: boolean
254
+ type: boolean_list
265
255
  description: |-
266
256
  False: Yellow flash disabled
267
257
  True: Yellow flash enabled
@@ -272,15 +262,13 @@ objects:
272
262
  All red can be manually set using the controllers operating panel during maintenance work.
273
263
  arguments:
274
264
  intersection:
275
- list: true
276
- type: integer
265
+ type: integer_list
277
266
  description: |-
278
267
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
279
268
  Other value: Intersection number
280
269
  range: "[0-255]"
281
270
  status:
282
- list: true
283
- type: boolean
271
+ type: boolean_list
284
272
  description: |-
285
273
  False: All red disabled
286
274
  True: All red enabled
@@ -291,15 +279,13 @@ objects:
291
279
  The "police key" is a external control switch present in some controllers that manually switches the controller to either dark mode or yellow flash.
292
280
  arguments:
293
281
  intersection:
294
- list: true
295
- type: integer
282
+ type: integer_list
296
283
  description: |-
297
284
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
298
285
  Other value: Intersection number
299
286
  range: "[0-255]"
300
287
  status:
301
- list: true
302
- type: integer
288
+ type: integer_list
303
289
  values:
304
290
  0: disabled
305
291
  1: dark mode
@@ -367,15 +353,13 @@ objects:
367
353
  Can be used for the management system to check the current control mode (startup, normal, standby, failure, test).
368
354
  arguments:
369
355
  intersection:
370
- list: true
371
- type: integer
356
+ type: integer_list
372
357
  description: |-
373
358
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
374
359
  Other value: Intersection number
375
360
  range: "[0-255]"
376
361
  controlmode:
377
- list: true
378
- type: string
362
+ type: string_list
379
363
  values:
380
364
  startup: Startup mode
381
365
  control: Normal control
@@ -469,29 +453,25 @@ objects:
469
453
  Requires security code 2.
470
454
  arguments:
471
455
  status:
472
- list: true
456
+ type: string_list
473
457
  description: Set operating mode
474
- type: string
475
458
  values:
476
459
  NormalControl: Normal Control
477
460
  YellowFlash: Enables yellow flash
478
461
  Dark: Enables dark mode
479
462
  securityCode:
480
- list: true
463
+ type: string_list
481
464
  description: Security code 2
482
- type: string
483
465
  timeout:
484
- list: true
466
+ type: integer_list
485
467
  description: |-
486
468
  Time in minutes until controller automatically reverts to previous functional position.
487
469
  0=no automatic return
488
- type: integer
489
470
  min: 0
490
471
  max: 1440
491
472
  intersection:
492
- list: true
473
+ type: integer_list
493
474
  description: Intersection number
494
- type: integer
495
475
  min: 0
496
476
  max: 255
497
477
  command: setValue
@@ -177,15 +177,13 @@ objects:
177
177
  During maintenance work the controller might be using dark mode (no output to the signal heads).
178
178
  arguments:
179
179
  intersection:
180
- list: true
181
- type: integer
180
+ type: integer_list
182
181
  description: |-
183
182
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
184
183
  Other value: Intersection number
185
184
  range: "[0-255]"
186
185
  status:
187
- list: true
188
- type: boolean
186
+ type: boolean_list
189
187
  description: |-
190
188
  False: Traffic Light Controller in dark mode
191
189
  True: Traffic Light Controller not in dark mode
@@ -196,15 +194,13 @@ objects:
196
194
  Signal timings is controlled manually by service personnel using the operating panel of the controller.
197
195
  arguments:
198
196
  intersection:
199
- list: true
200
- type: integer
197
+ type: integer_list
201
198
  description: |-
202
199
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
203
200
  Other value: Intersection number
204
201
  range: "[0-255]"
205
202
  status:
206
- list: true
207
- type: boolean
203
+ type: boolean_list
208
204
  description: |-
209
205
  False: Manual control inactive
210
206
  True: Manual control active
@@ -215,15 +211,13 @@ objects:
215
211
  Usually only used in case normal detectors can't be used, e.g. during maintenance work.
216
212
  arguments:
217
213
  intersection:
218
- list: true
219
- type: integer
214
+ type: integer_list
220
215
  description: |-
221
216
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
222
217
  Other value: Intersection number
223
218
  range: "[0-255]"
224
219
  status:
225
- list: true
226
- type: boolean
220
+ type: boolean_list
227
221
  description: |-
228
222
  False: Fixed time control inactive
229
223
  True: Fixed time control active
@@ -234,15 +228,13 @@ objects:
234
228
  Used to determine if the controller is operating independently or operating with other controllers (coordination).
235
229
  arguments:
236
230
  intersection:
237
- list: true
238
- type: integer
231
+ type: integer_list
239
232
  description: |-
240
233
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
241
234
  Other value: Intersection number
242
235
  range: "[0-255]"
243
236
  status:
244
- list: true
245
- type: boolean
237
+ type: boolean_list
246
238
  description: |-
247
239
  False: Isolated control disabled
248
240
  True: Isolated control enabled (Vehicle actuated control or Fixed time control)
@@ -253,15 +245,13 @@ objects:
253
245
  Yellow flash may be used during a serious fault (depending on configuration) or maintenance work. It can also be manually set using M0001.
254
246
  arguments:
255
247
  intersection:
256
- list: true
257
- type: integer
248
+ type: integer_list
258
249
  description: |-
259
250
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
260
251
  Other value: Intersection number
261
252
  range: "[0-255]"
262
253
  status:
263
- list: true
264
- type: boolean
254
+ type: boolean_list
265
255
  description: |-
266
256
  False: Yellow flash disabled
267
257
  True: Yellow flash enabled
@@ -272,15 +262,13 @@ objects:
272
262
  All red can be manually set using the controllers operating panel during maintenance work.
273
263
  arguments:
274
264
  intersection:
275
- list: true
276
- type: integer
265
+ type: integer_list
277
266
  description: |-
278
267
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
279
268
  Other value: Intersection number
280
269
  range: "[0-255]"
281
270
  status:
282
- list: true
283
- type: boolean
271
+ type: boolean_list
284
272
  description: |-
285
273
  False: All red disabled
286
274
  True: All red enabled
@@ -291,15 +279,13 @@ objects:
291
279
  The "police key" is a external control switch present in some controllers that manually switches the controller to either dark mode or yellow flash.
292
280
  arguments:
293
281
  intersection:
294
- list: true
295
- type: integer
282
+ type: integer_list
296
283
  description: |-
297
284
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
298
285
  Other value: Intersection number
299
286
  range: "[0-255]"
300
287
  status:
301
- list: true
302
- type: integer
288
+ type: integer_list
303
289
  values:
304
290
  0: disabled
305
291
  1: dark mode
@@ -367,15 +353,13 @@ objects:
367
353
  Can be used for the management system to check the current control mode (startup, normal, standby, failure, test).
368
354
  arguments:
369
355
  intersection:
370
- list: true
371
- type: integer
356
+ type: integer_list
372
357
  description: |-
373
358
  0: Not applicable (only one intersection exists or applicable for all intersection of the traffic light controller)
374
359
  Other value: Intersection number
375
360
  range: "[0-255]"
376
361
  controlmode:
377
- list: true
378
- type: string
362
+ type: string_list
379
363
  values:
380
364
  startup: Startup mode
381
365
  control: Normal control
@@ -598,29 +582,25 @@ objects:
598
582
  Requires security code 2.
599
583
  arguments:
600
584
  status:
601
- list: true
585
+ type: string_list
602
586
  description: Set operating mode
603
- type: string
604
587
  values:
605
588
  NormalControl: Normal Control
606
589
  YellowFlash: Enables yellow flash
607
590
  Dark: Enables dark mode
608
591
  securityCode:
609
- list: true
592
+ type: string_list
610
593
  description: Security code 2
611
- type: string
612
594
  timeout:
613
- list: true
595
+ type: integer_list
614
596
  description: |-
615
597
  Time in minutes until controller automatically reverts to previous functional position.
616
598
  0=no automatic return
617
- type: integer
618
599
  min: 0
619
600
  max: 1440
620
601
  intersection:
621
- list: true
602
+ type: integer_list
622
603
  description: Intersection number
623
- type: integer
624
604
  min: 0
625
605
  max: 255
626
606
  command: setValue