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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f0717cb5ebb1dc03c12f035a91dcf2f45558e27
4
- data.tar.gz: 6ed611cdea54b588141d7c031aaed8e568c46a2a
3
+ metadata.gz: 5b6cda522703d0896cf14a762388caa66fbca5c0
4
+ data.tar.gz: ca5ca470c2662ba182b283584c58ede459465720
5
5
  SHA512:
6
- metadata.gz: 0280cc2e9eaaa76c79442c1ad3fa8bf33cac8c13f4028c8cada49b53f4d2b81a12330be014c5720994e343a45c9658a646cf13e67884b1b0b1b1d6b6f8a12a15
7
- data.tar.gz: feb12a918c28c94a0c1f7ac88a12371be71d8ce4784a0eabd382498cbecc7d1f5ba8709c721cd6280d788f177e83b96e440c88c1114429a1cd954d2166c6e246
6
+ metadata.gz: 761d1a395fcd5c9051f162d68398d9ff88861493cf0947eb50292d333561ca591d37261b7668c52403c7bce3cc8b4b346f659285350291753a41f1a5d01560a0
7
+ data.tar.gz: 8a11fcaed55550bec45183185789c09a0394db87d2ab9b6656b2b84c29b20c3044002487043ec20aca08af479d7012694a1a3aa89a5f3ad049fc924a2e9f4916
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 2.0.0
2
+
3
+ * Change GovukSchemas::Schema.find to take { links_schema: 'detailded_guide' }
4
+ * Add regex for lowercase-underscore strings
5
+
1
6
  # 1.0.0
2
7
 
3
8
  * Add regex for GOV.UK campaign URLs
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>(schema_name, schema_type:) </a>
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>(schema_name, schema_type:)
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='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>frontend</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
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'>&quot;</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>&quot;</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'># =&gt; {&quot;base_path&quot;=&gt;&quot;/e42dd28e&quot;, &quot;title&quot;=&gt;&quot;dolor est...&quot;, &quot;publishing_app&quot;=&gt;&quot;elit&quot;...}
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</pre>
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 31</span>
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 rubyid_schema_name'>schema_name</span><span class='comma'>,</span> <span class='label'>schema_type:</span><span class='rparen'>)</span>
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 rubyid_schema_name'>schema_name</span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='id identifier rubyid_schema_type'>schema_type</span><span class='rparen'>)</span>
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&#39;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&#39;t valid against the schema an error will be raised.</p>
466
480
  73
467
481
  74
468
482
  75
469
- 76</pre>
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 67</span>
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&#39;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&#39;t valid against the schema an error will be raised.</p>
545
559
  50
546
560
  51
547
561
  52
548
- 53</pre>
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 44</span>
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&#39;t valid against the schema an error will be raised.</p>
570
585
  </div>
571
586
 
572
587
  <div id="footer">
573
- Generated on Fri Sep 23 14:26:38 2016 by
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)">+ (Object) <strong>all</strong>(schema_type: &#39;*&#39;) </a>
120
+ <a href="#all-class_method" title="all (class method)">+ (Array&lt;Hash&gt;) <strong>all</strong>(schema_type: &#39;*&#39;) </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)">+ (Object) <strong>find</strong>(schema_name, schema_type:) </a>
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)">+ (Object) <strong>random_schema</strong>(schema_type:) </a>
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>Object</tt>) <strong>all</strong>(schema_type: &#39;*&#39;)
201
+ + (<tt>Array&lt;Hash&gt;</tt>) <strong>all</strong>(schema_type: &#39;*&#39;)
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&lt;Hash&gt;</tt>)</span>
244
+
245
+
246
+
247
+ &mdash;
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
- 16
245
- 17
246
- 18
247
- 19
248
- 20
249
- 21
250
- 22</pre>
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 16</span>
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'>&#39;</span><span class='tstring_content'>*</span><span class='tstring_end'>&#39;</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'>&quot;</span><span class='tstring_content'>publisher_v2</span><span class='tstring_end'>&quot;</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'>&quot;</span><span class='tstring_content'>publisher</span><span class='tstring_end'>&quot;</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>Object</tt>) <strong>find</strong>(schema_name, schema_type:)
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
- <p class="tag_title">Parameters:</p>
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'>&quot;</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>&quot;</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'>&quot;</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>&quot;</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'>&quot;</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>&quot;</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'>&quot;</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>&quot;</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'>schema_name</span>
320
+ <span class='name'>schema</span>
291
321
 
292
322
 
293
- <span class='type'>(<tt>String</tt>)</span>
323
+ <span class='type'>(<tt>Hash</tt>)</span>
294
324
 
295
325
 
296
326
 
297
327
  &mdash;
298
328
  <div class='inline'>
299
- <p>Name of the schema/format</p>
329
+ <p>Type =&gt; 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>String</tt>)</span>
342
+ <span class='type'>(<tt>Hash</tt>)</span>
310
343
 
311
344
 
312
345
 
313
346
  &mdash;
314
347
  <div class='inline'>
315
- <p>The type: frontend, publisher, notification or links</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
- 7
330
- 8
331
- 9
332
- 10
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 7</span>
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 rubyid_schema_name'>schema_name</span><span class='comma'>,</span> <span class='label'>schema_type:</span><span class='rparen'>)</span>
339
- <span class='id identifier rubyid_schema_type'>schema_type</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>publisher_v2</span><span class='tstring_end'>&quot;</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'>&quot;</span><span class='tstring_content'>publisher</span><span class='tstring_end'>&quot;</span></span>
340
- <span class='id identifier rubyid_file_path'>file_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</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'>&quot;</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'>&quot;</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'>&quot;</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>Object</tt>) <strong>random_schema</strong>(schema_type:)
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
+ &mdash;
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
- 27
395
- 28
396
- 29</pre>
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 27</span>
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 Fri Sep 23 14:26:37 2016 by
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>
@@ -111,7 +111,7 @@
111
111
  </div>
112
112
 
113
113
  <div id="footer">
114
- Generated on Fri Sep 23 14:26:37 2016 by
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 Fri Sep 23 14:26:37 2016 by
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>
@@ -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'>&quot;</span><span class='tstring_content'>govuk_schemas</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>~&gt; VERSION</span><span class='tstring_end'>&quot;</span></span>
75
75
  </code></pre>
76
76
 
77
+ <h2 id="label-Limitations">Limitations</h2>
78
+ <ul><li>
79
+ <p>The gem doesn&#39;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&#39;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&#39;d have to make sure that the data
88
+ generated below doesn&#39;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 Fri Sep 23 14:26:37 2016 by
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'>&quot;</span><span class='tstring_content'>govuk_schemas</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>~&gt; VERSION</span><span class='tstring_end'>&quot;</span></span>
75
75
  </code></pre>
76
76
 
77
+ <h2 id="label-Limitations">Limitations</h2>
78
+ <ul><li>
79
+ <p>The gem doesn&#39;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&#39;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&#39;d have to make sure that the data
88
+ generated below doesn&#39;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 Fri Sep 23 14:26:37 2016 by
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 Fri Sep 23 14:26:37 2016 by
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>
@@ -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
- Utils.parameterize(WORDS.sample(rand(1..10)).join('-'))
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("detailed_guide", schema_type: "frontend")
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(schema_name, schema_type:)
32
- schema = GovukSchemas::Schema.find(schema_name, schema_type: schema_type)
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
 
@@ -2,17 +2,23 @@ module GovukSchemas
2
2
  class Schema
3
3
  # Find a schema by name
4
4
  #
5
- # @param schema_name [String] Name of the schema/format
6
- # @param schema_type [String] The type: frontend, publisher, notification or links
7
- def self.find(schema_name, schema_type:)
8
- schema_type = "publisher_v2" if schema_type == "publisher"
9
- file_path = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/#{schema_name}/#{schema_type}/schema.json"
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
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  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: 1.0.0
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-10-06 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema