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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b196457b3ec8a0f254c64d245c32f11448f60215
4
- data.tar.gz: 0dff37d3dd84f07932c3297e8d6477a8d9bfe16a
3
+ metadata.gz: 345030ceca3637693cb97b1f7ae278a95998880a
4
+ data.tar.gz: 4b2bfb4865a81442d7ec8c18acbf83b394c2a58e
5
5
  SHA512:
6
- metadata.gz: 6231f2bc473bbaf6ca90d67a2b960c7340b7dbf8c23b9b4140cb7b074c69cdbe83b4818a8fda1dba782cf2ecff7fc124dc42f4cfc10ec7b91fdb551902c30bd2
7
- data.tar.gz: de370e426b29552afa89b8ebb41db9cd423136fe389af51404858648bd5bceb8fa516640c262a9f0542c41f066a3a6c2f71ee1f9ca6aa0edfeedd9225e565dd0
6
+ metadata.gz: 41557290549c44945a885bfaea6ad72cba73fef4050a9a7d1c23f89fa56a13925a598580362dfee42ff7b066664b2e018173234b4c7b120ad5dc567741e7140c
7
+ data.tar.gz: 5af51d7f613812c5385f4294195dcf7fcc3184abdd85c78051d47c6654e3a7a1b0e155e84d51619cab0f15dce6d78607736f96dd4c239c118b4dd0d235f3389c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 3.3.0
2
+
3
+ * Support generating objects with an `oneOf` property.
4
+
1
5
  # 3.2.0
2
6
 
3
7
  * Add `GovukSchemas::DocumentTypes.valid_document_types` (PR #48)
@@ -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", "~> 1.2.1"
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
- if subschema['required'].to_a.include?(attribute_name) || subschema['minProperties'] || Random.bool
94
- document[attribute_name] = generate_value(attribute_properties)
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
 
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "3.2.0".freeze
3
+ VERSION = "3.3.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: 3.2.0
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: 2018-07-23 00:00:00.000000000 Z
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: 1.2.1
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: 1.2.1
82
+ version: '3.11'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: yard
85
85
  requirement: !ruby/object:Gem::Requirement