govuk_schemas 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -0
- data/docs/GovukSchemas/RandomExample.html +31 -16
- data/docs/GovukSchemas/Schema.html +85 -37
- data/docs/GovukSchemas.html +1 -1
- data/docs/_index.html +1 -1
- data/docs/file.README.html +15 -1
- data/docs/index.html +15 -1
- data/docs/top-level-namespace.html +1 -1
- data/lib/govuk_schemas/random.rb +7 -1
- data/lib/govuk_schemas/random_example.rb +4 -3
- data/lib/govuk_schemas/schema.rb +25 -5
- data/lib/govuk_schemas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b6cda522703d0896cf14a762388caa66fbca5c0
|
4
|
+
data.tar.gz: ca5ca470c2662ba182b283584c58ede459465720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761d1a395fcd5c9051f162d68398d9ff88861493cf0947eb50292d333561ca591d37261b7668c52403c7bce3cc8b4b346f659285350291753a41f1a5d01560a0
|
7
|
+
data.tar.gz: 8a11fcaed55550bec45183185789c09a0394db87d2ab9b6656b2b84c29b20c3044002487043ec20aca08af479d7012694a1a3aa89a5f3ad049fc924a2e9f4916
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,11 @@ In your Gemfile:
|
|
10
10
|
gem "govuk_schemas", "~> VERSION"
|
11
11
|
```
|
12
12
|
|
13
|
+
## Limitations
|
14
|
+
|
15
|
+
- The gem doesn't support `patternProperties` yet. On GOV.UK we [use this in the expanded frontend links](https://github.com/alphagov/govuk-content-schemas/blob/bdd97d18c7a9318e66f332f0748a410fddab1141/formats/frontend_links_definition.json#L67-L71).
|
16
|
+
- It's complicated to generate random data for `oneOf` properties. According to the JSON Schema spec a `oneOf` schema is only valid if the data is valid against *only one* of the clauses. To do this properly, we'd have to make sure that the data generated below doesn't validate against the other schemas properties.
|
17
|
+
|
13
18
|
## Usage
|
14
19
|
|
15
20
|
[Read the documentation!](https://alphagov.github.io/govuk_schemas_gem/frames.html)
|
@@ -117,7 +117,7 @@
|
|
117
117
|
<li class="public ">
|
118
118
|
<span class="summary_signature">
|
119
119
|
|
120
|
-
<a href="#for_schema-class_method" title="for_schema (class method)">+ (GovukSchemas::RandomExample) <strong>for_schema</strong>(
|
120
|
+
<a href="#for_schema-class_method" title="for_schema (class method)">+ (GovukSchemas::RandomExample) <strong>for_schema</strong>(schema_key_value) </a>
|
121
121
|
|
122
122
|
|
123
123
|
|
@@ -306,7 +306,7 @@
|
|
306
306
|
<div class="method_details first">
|
307
307
|
<h3 class="signature first" id="for_schema-class_method">
|
308
308
|
|
309
|
-
+ (<tt><span class='object_link'><a href="" title="GovukSchemas::RandomExample (class)">GovukSchemas::RandomExample</a></span></tt>) <strong>for_schema</strong>(
|
309
|
+
+ (<tt><span class='object_link'><a href="" title="GovukSchemas::RandomExample (class)">GovukSchemas::RandomExample</a></span></tt>) <strong>for_schema</strong>(schema_key_value)
|
310
310
|
|
311
311
|
|
312
312
|
|
@@ -319,7 +319,7 @@
|
|
319
319
|
|
320
320
|
<p>For example:</p>
|
321
321
|
|
322
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_generator'>generator</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='
|
322
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_generator'>generator</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='label'>frontend_schema:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
323
323
|
<span class='id identifier rubyid_generator'>generator</span><span class='period'>.</span><span class='id identifier rubyid_payload'>payload</span>
|
324
324
|
<span class='comment'># => {"base_path"=>"/e42dd28e", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
325
325
|
</span></code></pre>
|
@@ -328,7 +328,22 @@
|
|
328
328
|
</div>
|
329
329
|
</div>
|
330
330
|
<div class="tags">
|
331
|
+
<p class="tag_title">Parameters:</p>
|
332
|
+
<ul class="param">
|
333
|
+
|
334
|
+
<li>
|
335
|
+
|
336
|
+
<span class='name'>schema_key_value</span>
|
337
|
+
|
338
|
+
|
339
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
</li>
|
331
344
|
|
345
|
+
</ul>
|
346
|
+
|
332
347
|
<p class="tag_title">Returns:</p>
|
333
348
|
<ul class="return">
|
334
349
|
|
@@ -349,16 +364,16 @@
|
|
349
364
|
<pre class="lines">
|
350
365
|
|
351
366
|
|
352
|
-
31
|
353
367
|
32
|
354
368
|
33
|
355
|
-
34
|
369
|
+
34
|
370
|
+
35</pre>
|
356
371
|
</td>
|
357
372
|
<td>
|
358
|
-
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line
|
373
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 32</span>
|
359
374
|
|
360
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='id identifier
|
361
|
-
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier
|
375
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_key_value'>schema_key_value</span><span class='rparen'>)</span>
|
376
|
+
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_key_value'>schema_key_value</span><span class='rparen'>)</span>
|
362
377
|
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>schema:</span> <span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
363
378
|
<span class='kw'>end</span></pre>
|
364
379
|
</td>
|
@@ -457,7 +472,6 @@ isn't valid against the schema an error will be raised.</p>
|
|
457
472
|
<pre class="lines">
|
458
473
|
|
459
474
|
|
460
|
-
67
|
461
475
|
68
|
462
476
|
69
|
463
477
|
70
|
@@ -466,17 +480,18 @@ isn't valid against the schema an error will be raised.</p>
|
|
466
480
|
73
|
467
481
|
74
|
468
482
|
75
|
469
|
-
76
|
483
|
+
76
|
484
|
+
77</pre>
|
470
485
|
</td>
|
471
486
|
<td>
|
472
|
-
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line
|
487
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 68</span>
|
473
488
|
|
474
489
|
<span class='kw'>def</span> <span class='id identifier rubyid_merge_and_validate'>merge_and_validate</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span>
|
475
490
|
<span class='id identifier rubyid_item'>item</span> <span class='op'>=</span> <span class='id identifier rubyid_payload'>payload</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='const'>Utils</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
476
491
|
<span class='id identifier rubyid_errors'>errors</span> <span class='op'>=</span> <span class='id identifier rubyid_validation_errors_for'>validation_errors_for</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='rparen'>)</span>
|
477
492
|
|
478
493
|
<span class='kw'>if</span> <span class='id identifier rubyid_errors'>errors</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span>
|
479
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>InvalidContentGenerated</span><span class='comma'>,</span> <span class='id identifier rubyid_error_message_custom'>error_message_custom</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='comma'>,</span> <span class='id identifier rubyid_errors'>errors</span><span class='rparen'>)</span>
|
494
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>InvalidContentGenerated</span><span class='comma'>,</span> <span class='id identifier rubyid_error_message_custom'>error_message_custom</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='comma'>,</span> <span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span> <span class='id identifier rubyid_errors'>errors</span><span class='rparen'>)</span>
|
480
495
|
<span class='kw'>end</span>
|
481
496
|
|
482
497
|
<span class='id identifier rubyid_item'>item</span>
|
@@ -536,7 +551,6 @@ isn't valid against the schema an error will be raised.</p>
|
|
536
551
|
<pre class="lines">
|
537
552
|
|
538
553
|
|
539
|
-
44
|
540
554
|
45
|
541
555
|
46
|
542
556
|
47
|
@@ -545,10 +559,11 @@ isn't valid against the schema an error will be raised.</p>
|
|
545
559
|
50
|
546
560
|
51
|
547
561
|
52
|
548
|
-
53
|
562
|
+
53
|
563
|
+
54</pre>
|
549
564
|
</td>
|
550
565
|
<td>
|
551
|
-
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line
|
566
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 45</span>
|
552
567
|
|
553
568
|
<span class='kw'>def</span> <span class='id identifier rubyid_payload'>payload</span>
|
554
569
|
<span class='id identifier rubyid_item'>item</span> <span class='op'>=</span> <span class='ivar'>@random_generator</span><span class='period'>.</span><span class='id identifier rubyid_payload'>payload</span>
|
@@ -570,7 +585,7 @@ isn't valid against the schema an error will be raised.</p>
|
|
570
585
|
</div>
|
571
586
|
|
572
587
|
<div id="footer">
|
573
|
-
Generated on
|
588
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
574
589
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
575
590
|
0.8.7.6 (ruby-2.3.1).
|
576
591
|
</div>
|
@@ -117,7 +117,7 @@
|
|
117
117
|
<li class="public ">
|
118
118
|
<span class="summary_signature">
|
119
119
|
|
120
|
-
<a href="#all-class_method" title="all (class method)">+ (
|
120
|
+
<a href="#all-class_method" title="all (class method)">+ (Array<Hash>) <strong>all</strong>(schema_type: '*') </a>
|
121
121
|
|
122
122
|
|
123
123
|
|
@@ -141,7 +141,7 @@
|
|
141
141
|
<li class="public ">
|
142
142
|
<span class="summary_signature">
|
143
143
|
|
144
|
-
<a href="#find-class_method" title="find (class method)">+ (
|
144
|
+
<a href="#find-class_method" title="find (class method)">+ (Hash) <strong>find</strong>(schema) </a>
|
145
145
|
|
146
146
|
|
147
147
|
|
@@ -165,7 +165,7 @@
|
|
165
165
|
<li class="public ">
|
166
166
|
<span class="summary_signature">
|
167
167
|
|
168
|
-
<a href="#random_schema-class_method" title="random_schema (class method)">+ (
|
168
|
+
<a href="#random_schema-class_method" title="random_schema (class method)">+ (Hash) <strong>random_schema</strong>(schema_type:) </a>
|
169
169
|
|
170
170
|
|
171
171
|
|
@@ -198,7 +198,7 @@
|
|
198
198
|
<div class="method_details first">
|
199
199
|
<h3 class="signature first" id="all-class_method">
|
200
200
|
|
201
|
-
+ (<tt>
|
201
|
+
+ (<tt>Array<Hash></tt>) <strong>all</strong>(schema_type: '*')
|
202
202
|
|
203
203
|
|
204
204
|
|
@@ -234,6 +234,24 @@
|
|
234
234
|
|
235
235
|
</ul>
|
236
236
|
|
237
|
+
<p class="tag_title">Returns:</p>
|
238
|
+
<ul class="return">
|
239
|
+
|
240
|
+
<li>
|
241
|
+
|
242
|
+
|
243
|
+
<span class='type'>(<tt>Array<Hash></tt>)</span>
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
—
|
248
|
+
<div class='inline'>
|
249
|
+
<p>List of JSON schemas as hashes</p>
|
250
|
+
</div>
|
251
|
+
|
252
|
+
</li>
|
253
|
+
|
254
|
+
</ul>
|
237
255
|
|
238
256
|
</div><table class="source_code">
|
239
257
|
<tr>
|
@@ -241,16 +259,16 @@
|
|
241
259
|
<pre class="lines">
|
242
260
|
|
243
261
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
262
|
+
22
|
263
|
+
23
|
264
|
+
24
|
265
|
+
25
|
266
|
+
26
|
267
|
+
27
|
268
|
+
28</pre>
|
251
269
|
</td>
|
252
270
|
<td>
|
253
|
-
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/schema.rb', line
|
271
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/schema.rb', line 22</span>
|
254
272
|
|
255
273
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='lparen'>(</span><span class='label'>schema_type:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>*</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
256
274
|
<span class='id identifier rubyid_schema_type'>schema_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>publisher_v2</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_schema_type'>schema_type</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>publisher</span><span class='tstring_end'>"</span></span>
|
@@ -267,7 +285,7 @@
|
|
267
285
|
<div class="method_details ">
|
268
286
|
<h3 class="signature " id="find-class_method">
|
269
287
|
|
270
|
-
+ (<tt>
|
288
|
+
+ (<tt>Hash</tt>) <strong>find</strong>(schema)
|
271
289
|
|
272
290
|
|
273
291
|
|
@@ -282,62 +300,74 @@
|
|
282
300
|
</div>
|
283
301
|
</div>
|
284
302
|
<div class="tags">
|
285
|
-
|
303
|
+
|
304
|
+
<div class="examples">
|
305
|
+
<p class="tag_title">Examples:</p>
|
306
|
+
|
307
|
+
|
308
|
+
<pre class="example code"><code>
|
309
|
+
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='label'>links_schema:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
310
|
+
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='label'>frontend_schema:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
311
|
+
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='label'>publisher_schema:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
312
|
+
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='label'>notification_schema:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span></code></pre>
|
313
|
+
|
314
|
+
</div>
|
315
|
+
<p class="tag_title">Parameters:</p>
|
286
316
|
<ul class="param">
|
287
317
|
|
288
318
|
<li>
|
289
319
|
|
290
|
-
<span class='name'>
|
320
|
+
<span class='name'>schema</span>
|
291
321
|
|
292
322
|
|
293
|
-
<span class='type'>(<tt>
|
323
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
294
324
|
|
295
325
|
|
296
326
|
|
297
327
|
—
|
298
328
|
<div class='inline'>
|
299
|
-
<p>Name of the schema/format
|
329
|
+
<p>Type => Name of the schema/format:</p>
|
300
330
|
</div>
|
301
331
|
|
302
332
|
</li>
|
303
333
|
|
334
|
+
</ul>
|
335
|
+
|
336
|
+
<p class="tag_title">Returns:</p>
|
337
|
+
<ul class="return">
|
338
|
+
|
304
339
|
<li>
|
305
340
|
|
306
|
-
<span class='name'>schema_type</span>
|
307
|
-
|
308
341
|
|
309
|
-
<span class='type'>(<tt>
|
342
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
310
343
|
|
311
344
|
|
312
345
|
|
313
346
|
—
|
314
347
|
<div class='inline'>
|
315
|
-
<p>
|
348
|
+
<p>the JSON schema as a hash</p>
|
316
349
|
</div>
|
317
350
|
|
318
351
|
</li>
|
319
352
|
|
320
353
|
</ul>
|
321
354
|
|
322
|
-
|
323
355
|
</div><table class="source_code">
|
324
356
|
<tr>
|
325
357
|
<td>
|
326
358
|
<pre class="lines">
|
327
359
|
|
328
360
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
11</pre>
|
361
|
+
13
|
362
|
+
14
|
363
|
+
15
|
364
|
+
16</pre>
|
334
365
|
</td>
|
335
366
|
<td>
|
336
|
-
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/schema.rb', line
|
367
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/schema.rb', line 13</span>
|
337
368
|
|
338
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier
|
339
|
-
<span class='id identifier
|
340
|
-
<span class='id identifier rubyid_file_path'>file_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>CONTENT_SCHEMA_DIR</span><span class='embexpr_end'>}</span><span class='tstring_content'>/dist/formats/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_schema_name'>schema_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_schema_type'>schema_type</span><span class='embexpr_end'>}</span><span class='tstring_content'>/schema.json</span><span class='tstring_end'>"</span></span>
|
369
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
370
|
+
<span class='id identifier rubyid_file_path'>file_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>CONTENT_SCHEMA_DIR</span><span class='embexpr_end'>}</span><span class='tstring_content'>/dist/formats/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_location_for_schema_name'>location_for_schema_name</span><span class='lparen'>(</span><span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
341
371
|
<span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_file_path'>file_path</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
342
372
|
<span class='kw'>end</span></pre>
|
343
373
|
</td>
|
@@ -348,7 +378,7 @@
|
|
348
378
|
<div class="method_details ">
|
349
379
|
<h3 class="signature " id="random_schema-class_method">
|
350
380
|
|
351
|
-
+ (<tt>
|
381
|
+
+ (<tt>Hash</tt>) <strong>random_schema</strong>(schema_type:)
|
352
382
|
|
353
383
|
|
354
384
|
|
@@ -384,6 +414,24 @@
|
|
384
414
|
|
385
415
|
</ul>
|
386
416
|
|
417
|
+
<p class="tag_title">Returns:</p>
|
418
|
+
<ul class="return">
|
419
|
+
|
420
|
+
<li>
|
421
|
+
|
422
|
+
|
423
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
—
|
428
|
+
<div class='inline'>
|
429
|
+
<p>a JSON schema as a hash</p>
|
430
|
+
</div>
|
431
|
+
|
432
|
+
</li>
|
433
|
+
|
434
|
+
</ul>
|
387
435
|
|
388
436
|
</div><table class="source_code">
|
389
437
|
<tr>
|
@@ -391,12 +439,12 @@
|
|
391
439
|
<pre class="lines">
|
392
440
|
|
393
441
|
|
394
|
-
|
395
|
-
|
396
|
-
|
442
|
+
34
|
443
|
+
35
|
444
|
+
36</pre>
|
397
445
|
</td>
|
398
446
|
<td>
|
399
|
-
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/schema.rb', line
|
447
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/schema.rb', line 34</span>
|
400
448
|
|
401
449
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_random_schema'>random_schema</span><span class='lparen'>(</span><span class='label'>schema_type:</span><span class='rparen'>)</span>
|
402
450
|
<span class='id identifier rubyid_all'>all</span><span class='lparen'>(</span><span class='label'>schema_type:</span> <span class='id identifier rubyid_schema_type'>schema_type</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span>
|
@@ -411,7 +459,7 @@
|
|
411
459
|
</div>
|
412
460
|
|
413
461
|
<div id="footer">
|
414
|
-
Generated on
|
462
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
415
463
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
416
464
|
0.8.7.6 (ruby-2.3.1).
|
417
465
|
</div>
|
data/docs/GovukSchemas.html
CHANGED
@@ -111,7 +111,7 @@
|
|
111
111
|
</div>
|
112
112
|
|
113
113
|
<div id="footer">
|
114
|
-
Generated on
|
114
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
115
115
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
116
116
|
0.8.7.6 (ruby-2.3.1).
|
117
117
|
</div>
|
data/docs/_index.html
CHANGED
@@ -131,7 +131,7 @@
|
|
131
131
|
</div>
|
132
132
|
|
133
133
|
<div id="footer">
|
134
|
-
Generated on
|
134
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
135
135
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
136
136
|
0.8.7.6 (ruby-2.3.1).
|
137
137
|
</div>
|
data/docs/file.README.html
CHANGED
@@ -74,6 +74,20 @@ href="https://github.com/alphagov/govuk-content-schemas">govuk-content-schemas</
|
|
74
74
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>govuk_schemas</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>~> VERSION</span><span class='tstring_end'>"</span></span>
|
75
75
|
</code></pre>
|
76
76
|
|
77
|
+
<h2 id="label-Limitations">Limitations</h2>
|
78
|
+
<ul><li>
|
79
|
+
<p>The gem doesn't support <code>patternProperties</code> yet. On GOV.UK
|
80
|
+
we <a
|
81
|
+
href="https://github.com/alphagov/govuk-content-schemas/blob/bdd97d18c7a9318e66f332f0748a410fddab1141/formats/frontend_links_definition.json#L67-L71">use
|
82
|
+
this in the expanded frontend links</a>.</p>
|
83
|
+
</li><li>
|
84
|
+
<p>It's complicated to generate random data for <code>oneOf</code>
|
85
|
+
properties. According to the JSON Schema spec a <code>oneOf</code> schema
|
86
|
+
is only valid if the data is valid against <em>only one</em> of the
|
87
|
+
clauses. To do this properly, we'd have to make sure that the data
|
88
|
+
generated below doesn't validate against the other schemas properties.</p>
|
89
|
+
</li></ul>
|
90
|
+
|
77
91
|
<h2 id="label-Usage">Usage</h2>
|
78
92
|
|
79
93
|
<p><a href="https://alphagov.github.io/govuk_schemas_gem/frames.html">Read the
|
@@ -111,7 +125,7 @@ href="LICENSE.md">MIT License</a>.</p>
|
|
111
125
|
</div></div>
|
112
126
|
|
113
127
|
<div id="footer">
|
114
|
-
Generated on
|
128
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
115
129
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
116
130
|
0.8.7.6 (ruby-2.3.1).
|
117
131
|
</div>
|
data/docs/index.html
CHANGED
@@ -74,6 +74,20 @@ href="https://github.com/alphagov/govuk-content-schemas">govuk-content-schemas</
|
|
74
74
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>govuk_schemas</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>~> VERSION</span><span class='tstring_end'>"</span></span>
|
75
75
|
</code></pre>
|
76
76
|
|
77
|
+
<h2 id="label-Limitations">Limitations</h2>
|
78
|
+
<ul><li>
|
79
|
+
<p>The gem doesn't support <code>patternProperties</code> yet. On GOV.UK
|
80
|
+
we <a
|
81
|
+
href="https://github.com/alphagov/govuk-content-schemas/blob/bdd97d18c7a9318e66f332f0748a410fddab1141/formats/frontend_links_definition.json#L67-L71">use
|
82
|
+
this in the expanded frontend links</a>.</p>
|
83
|
+
</li><li>
|
84
|
+
<p>It's complicated to generate random data for <code>oneOf</code>
|
85
|
+
properties. According to the JSON Schema spec a <code>oneOf</code> schema
|
86
|
+
is only valid if the data is valid against <em>only one</em> of the
|
87
|
+
clauses. To do this properly, we'd have to make sure that the data
|
88
|
+
generated below doesn't validate against the other schemas properties.</p>
|
89
|
+
</li></ul>
|
90
|
+
|
77
91
|
<h2 id="label-Usage">Usage</h2>
|
78
92
|
|
79
93
|
<p><a href="https://alphagov.github.io/govuk_schemas_gem/frames.html">Read the
|
@@ -111,7 +125,7 @@ href="LICENSE.md">MIT License</a>.</p>
|
|
111
125
|
</div></div>
|
112
126
|
|
113
127
|
<div id="footer">
|
114
|
-
Generated on
|
128
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
115
129
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
116
130
|
0.8.7.6 (ruby-2.3.1).
|
117
131
|
</div>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Thu Nov 3 17:31:15 2016 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7.6 (ruby-2.3.1).
|
109
109
|
</div>
|
data/lib/govuk_schemas/random.rb
CHANGED
@@ -47,6 +47,10 @@ module GovukSchemas
|
|
47
47
|
"##{SecureRandom.hex}"
|
48
48
|
end
|
49
49
|
|
50
|
+
def random_identifier(separator:)
|
51
|
+
Utils.parameterize(WORDS.sample(rand(1..10)).join('-')).gsub('-', separator)
|
52
|
+
end
|
53
|
+
|
50
54
|
def string_for_regex(pattern)
|
51
55
|
case pattern.to_s
|
52
56
|
when '^(placeholder|placeholder_.+)$'
|
@@ -62,7 +66,9 @@ module GovukSchemas
|
|
62
66
|
when "^#.+$"
|
63
67
|
anchor
|
64
68
|
when "[a-z-]"
|
65
|
-
|
69
|
+
random_identifier(separator: '-')
|
70
|
+
when "^[a-z_]+$"
|
71
|
+
random_identifier(separator: '_')
|
66
72
|
when "^/(([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})+(/([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)*)?(\\?([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?(#([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?$"
|
67
73
|
base_path
|
68
74
|
when "^https://([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[A-Za-z0-9])?\\.)+campaign\\.gov\\.uk(/(([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})+(/([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)*)?(\\?([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?(#([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?)?$"
|
@@ -23,13 +23,14 @@ module GovukSchemas
|
|
23
23
|
#
|
24
24
|
# For example:
|
25
25
|
#
|
26
|
-
# generator = GovukSchemas::RandomExample.for_schema(
|
26
|
+
# generator = GovukSchemas::RandomExample.for_schema(frontend_schema: "detailed_guide")
|
27
27
|
# generator.payload
|
28
28
|
# # => {"base_path"=>"/e42dd28e", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
29
29
|
#
|
30
|
+
# @param schema_key_value [Hash]
|
30
31
|
# @return [GovukSchemas::RandomExample]
|
31
|
-
def self.for_schema(
|
32
|
-
schema = GovukSchemas::Schema.find(
|
32
|
+
def self.for_schema(schema_key_value)
|
33
|
+
schema = GovukSchemas::Schema.find(schema_key_value)
|
33
34
|
GovukSchemas::RandomExample.new(schema: schema)
|
34
35
|
end
|
35
36
|
|
data/lib/govuk_schemas/schema.rb
CHANGED
@@ -2,17 +2,23 @@ module GovukSchemas
|
|
2
2
|
class Schema
|
3
3
|
# Find a schema by name
|
4
4
|
#
|
5
|
-
# @param
|
6
|
-
# @
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# @param schema [Hash] Type => Name of the schema/format:
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# GovukSchemas::Schema.find(links_schema: "detailed_guide")
|
9
|
+
# GovukSchemas::Schema.find(frontend_schema: "detailed_guide")
|
10
|
+
# GovukSchemas::Schema.find(publisher_schema: "detailed_guide")
|
11
|
+
# GovukSchemas::Schema.find(notification_schema: "detailed_guide")
|
12
|
+
# @return [Hash] the JSON schema as a hash
|
13
|
+
def self.find(schema)
|
14
|
+
file_path = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/#{location_for_schema_name(schema)}"
|
10
15
|
JSON.parse(File.read(file_path))
|
11
16
|
end
|
12
17
|
|
13
18
|
# Return all schemas in a hash, keyed by schema name
|
14
19
|
#
|
15
20
|
# @param schema_type [String] The type: frontend, publisher, notification or links
|
21
|
+
# @return [Array<Hash>] List of JSON schemas as hashes
|
16
22
|
def self.all(schema_type: '*')
|
17
23
|
schema_type = "publisher_v2" if schema_type == "publisher"
|
18
24
|
Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/*/#{schema_type}/*.json").reduce({}) do |hash, file_path|
|
@@ -24,8 +30,22 @@ module GovukSchemas
|
|
24
30
|
# Return a random schema of a certain type
|
25
31
|
#
|
26
32
|
# @param schema_type [String] The type: frontend, publisher, notification or links
|
33
|
+
# @return [Hash] a JSON schema as a hash
|
27
34
|
def self.random_schema(schema_type:)
|
28
35
|
all(schema_type: schema_type).values.sample
|
29
36
|
end
|
37
|
+
|
38
|
+
# @private
|
39
|
+
def self.location_for_schema_name(schema)
|
40
|
+
type, schema_name = schema.to_a.flatten
|
41
|
+
{
|
42
|
+
links_schema: "#{schema_name}/publisher_v2/links.json",
|
43
|
+
frontend_schema: "#{schema_name}/frontend/schema.json",
|
44
|
+
publisher_schema: "#{schema_name}/publisher_v2/schema.json",
|
45
|
+
notification_schema: "#{schema_name}/notification/schema.json",
|
46
|
+
}[type]
|
47
|
+
end
|
48
|
+
|
49
|
+
private_class_method :location_for_schema_name
|
30
50
|
end
|
31
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|