govuk_schemas 3.2.0 → 3.3.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 +4 -0
- data/govuk_schemas.gemspec +1 -1
- data/lib/govuk_schemas/random_item_generator.rb +16 -3
- data/lib/govuk_schemas/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 345030ceca3637693cb97b1f7ae278a95998880a
|
4
|
+
data.tar.gz: 4b2bfb4865a81442d7ec8c18acbf83b394c2a58e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41557290549c44945a885bfaea6ad72cba73fef4050a9a7d1c23f89fa56a13925a598580362dfee42ff7b066664b2e018173234b4c7b120ad5dc567741e7140c
|
7
|
+
data.tar.gz: 5af51d7f613812c5385f4294195dcf7fcc3184abdd85c78051d47c6654e3a7a1b0e155e84d51619cab0f15dce6d78607736f96dd4c239c118b4dd0d235f3389c
|
data/CHANGELOG.md
CHANGED
data/govuk_schemas.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.4"
|
27
27
|
spec.add_development_dependency "pry-byebug"
|
28
|
-
spec.add_development_dependency "govuk-lint", "~>
|
28
|
+
spec.add_development_dependency "govuk-lint", "~> 3.11"
|
29
29
|
spec.add_development_dependency "yard", "~> 0.8"
|
30
30
|
|
31
31
|
spec.required_ruby_version = ">= 2.3.1"
|
@@ -49,7 +49,7 @@ module GovukSchemas
|
|
49
49
|
|
50
50
|
if props['anyOf']
|
51
51
|
generate_value(props['anyOf'].sample)
|
52
|
-
elsif props['oneOf']
|
52
|
+
elsif props['oneOf'] && type != 'object'
|
53
53
|
# FIXME: Generating valid data for a `oneOf` schema is quite interesting.
|
54
54
|
# According to the JSON Schema spec a `oneOf` schema is only valid if
|
55
55
|
# the data is valid against *only one* of the clauses. To do this
|
@@ -85,13 +85,26 @@ module GovukSchemas
|
|
85
85
|
def generate_random_object(subschema)
|
86
86
|
document = {}
|
87
87
|
|
88
|
+
one_of_sample = subschema.fetch('oneOf', []).sample || {}
|
89
|
+
|
88
90
|
(subschema['properties'] || {}).each do |attribute_name, attribute_properties|
|
89
91
|
# TODO: When the schema contains `subschema['minProperties']` we always
|
90
92
|
# populate all of the keys in the hash. This isn't quite random, but I
|
91
93
|
# haven't found a nice way yet to ensure there's at least n elements in
|
92
94
|
# the hash.
|
93
|
-
|
94
|
-
|
95
|
+
should_generate_value = Random.bool \
|
96
|
+
|| subschema['required'].to_a.include?(attribute_name) \
|
97
|
+
|| (one_of_sample['required'] || {}).to_a.include?(attribute_name) \
|
98
|
+
|| (one_of_sample['properties'] || {}).keys.include?(attribute_name) \
|
99
|
+
|| subschema['minProperties'] \
|
100
|
+
|
101
|
+
if should_generate_value
|
102
|
+
one_of_properties = (one_of_sample['properties'] || {})[attribute_name]
|
103
|
+
document[attribute_name] = if one_of_properties
|
104
|
+
generate_value(one_of_properties)
|
105
|
+
else
|
106
|
+
generate_value(attribute_properties)
|
107
|
+
end
|
95
108
|
end
|
96
109
|
end
|
97
110
|
|
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: 3.
|
4
|
+
version: 3.3.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:
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '3.11'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '3.11'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: yard
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|