lacerda 2.1.3 → 2.1.4.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fa036be3aa64b8252a1f70c50845b30a3416c91
4
- data.tar.gz: bdf9130ea1129c5d75ad957b0ead7c1415e79872
3
+ metadata.gz: 19b05d38440fd072d0007dea89ce2d9918ceb457
4
+ data.tar.gz: cf090174559cad51fd3fc811feeaba8963b7cef0
5
5
  SHA512:
6
- metadata.gz: 4ecafbf4304cc8c8996872d24473250c5b0160d18ed1570abda7b82f2cb3a74a1c9eb9d835883b0f2fc921efeeea46df51a3e8e0c5054d5b0cdf5c57c9b0c4d8
7
- data.tar.gz: f928393cc76f332f8ca5efed5a714e44cdcdc6ae7bff3ba1a01d715cb6ce637b7a4717c0774a8a82ec3f50924fa3951f64d3f2a6467a55ef2f892c4bf524be95
6
+ metadata.gz: 5d9448fde020aad2ce929c3027f038bfaf66d3cd008c4b33038cc2d24517b43d271340fc6bb7055c0d34511a7b29093044dc8aa84e93ec6826f32761b26d9d62
7
+ data.tar.gz: f2f184248f2a47d2cd7db01fd788a8da85abffa38b68fa4aaa8547f619dc7c98c98646077d679485219e655768ebea358ad23dc683fdcdc5e119a648560fc5a5
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ coverage
8
8
  **/*.gem
9
9
  Gemfile.lock
10
10
  tmp/
11
+ .byebug_history
@@ -1,3 +1,7 @@
1
+ # [2.1.4.beta1] - 2017-09-27
2
+ ### Fixed
3
+ - Fix json schema inclusion for `required` fields
4
+
1
5
  # [2.1.3] - 2017-09-15
2
6
  ### Fixed
3
7
  - Allow Lacerda::Reporter::Rspec to work when RSpec config.disable_monkey_paching! is set.
@@ -125,16 +125,10 @@ module Lacerda
125
125
 
126
126
  # Check all publish types for a compatible consume type
127
127
  publish_types.each do |publish_type|
128
- compatible_consume_type_found = false
129
- consume_types.each do |consume_type|
130
- next unless publish_type == consume_type or
131
- compare_sub_types(publish_type, consume_type, location + [publish_type])
132
- compatible_consume_type_found = true
133
- end
134
-
135
- unless compatible_consume_type_found
136
- return _e(:ERR_MISSING_MULTI_PUBLISH_MULTI_CONSUME, location, publish_type)
128
+ matched = consume_types.any? do |consume_type|
129
+ compare_sub_types(publish_type, consume_type, location + [publish_type])
137
130
  end
131
+ return _e(:ERR_MISSING_MULTI_PUBLISH_MULTI_CONSUME, location, publish_type) if !matched
138
132
  end
139
133
 
140
134
  # Mixed case 1/2:
@@ -175,11 +169,11 @@ module Lacerda
175
169
  end
176
170
 
177
171
  if consume['type'] == 'array'
178
- sorted_publish = publish['items'].sort
179
- consume['items'].sort.each_with_index do |item, i|
180
- # TODO why just compare sorted_publish[i] and not all??
181
- next if schema_contains?(publish: sorted_publish[i], consume: item)
182
- return _e(:ERR_ARRAY_ITEM_MISMATCH, location, nil)
172
+ publish['items'].each do |publish_item|
173
+ matched = consume['items'].any? do |consume_item|
174
+ schema_contains?(publish: publish_item, consume: consume_item)
175
+ end
176
+ return _e(:ERR_ARRAY_ITEM_MISMATCH, location, nil) unless matched
183
177
  end
184
178
  end
185
179
 
@@ -189,24 +183,37 @@ module Lacerda
189
183
  private
190
184
 
191
185
  def properties_contained?
192
- @contained_schema['properties'].each do |property, contained_property|
193
- resolved_contained_property = data_for_pointer(contained_property, @contained_schema)
194
- containing_property = @containing_schema['properties'][property]
195
- if !containing_property
196
- _e(:ERR_MISSING_DEFINITION, [@initial_location, property], "(in publish.mson)")
197
- else
198
- resolved_containing_property = data_for_pointer(
199
- containing_property,
200
- @containing_schema
201
- )
202
- schema_contains?(
203
- publish: resolved_containing_property,
204
- consume: resolved_contained_property,
205
- location: [property]
206
- )
207
- end
186
+ # success is used to ensure we have no errors.
187
+ success = @contained_schema['properties'].map do |name, content|
188
+ property_contained?(name, content)
189
+ end.all? {|is_property_contained| is_property_contained }
190
+ success && @errors.empty?
191
+ end
192
+
193
+ def property_contained?(property_name, content)
194
+ resolved_contained_property = data_for_pointer(content, @contained_schema)
195
+ containing_property = @containing_schema['properties'][property_name]
196
+
197
+ if !containing_property
198
+ return _e(:ERR_MISSING_DEFINITION, [@initial_location, property_name], "(in publish.mson)")
208
199
  end
209
- @errors.empty?
200
+
201
+ # Make sure required properties in consume are required in publish
202
+ publish_required = @containing_schema['required'] || []
203
+ consume_required = @contained_schema['required'] || []
204
+ missing = (consume_required - publish_required)
205
+ return _e(:ERR_MISSING_REQUIRED, [property_name], missing.to_json) unless missing.empty?
206
+
207
+ resolved_containing_property = data_for_pointer(
208
+ containing_property,
209
+ @containing_schema
210
+ )
211
+
212
+ schema_contains?(
213
+ publish: resolved_containing_property,
214
+ consume: resolved_contained_property,
215
+ location: [property_name]
216
+ )
210
217
  end
211
218
 
212
219
  def _e(error, location, extra = nil)
@@ -233,7 +240,7 @@ module Lacerda
233
240
  #
234
241
  def data_for_pointer(data_or_pointer, schema)
235
242
  data = nil
236
- if data_or_pointer['type']
243
+ if data_or_pointer['type'] || data_or_pointer['oneOf']
237
244
  data = data_or_pointer
238
245
  elsif pointer = data_or_pointer['$ref']
239
246
  data = resolve_pointer(pointer, schema)
@@ -259,10 +266,12 @@ module Lacerda
259
266
  # this method wraps them into full schemas, creates a new
260
267
  # instance of self and compares
261
268
  def compare_sub_types(containing, contained, location)
269
+
262
270
  resolved_containing = data_for_pointer(containing, @containing_schema)
263
271
  resolved_contained = data_for_pointer(contained, @contained_schema)
272
+
264
273
  containing_schema = {
265
- 'definitions' => { 'foo' => resolved_containing },
274
+ 'definitions' => { 'foo' => resolved_containing},
266
275
  'properties' => { 'bar' => { '$ref' => '#/definitions/foo' } }
267
276
  }
268
277
  comparator = self.class.new(containing_schema)
@@ -1,3 +1,3 @@
1
1
  module Lacerda
2
- VERSION = '2.1.3'
2
+ VERSION = '2.1.4.beta1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacerda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannis Hermanns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -284,12 +284,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
284
  version: '0'
285
285
  required_rubygems_version: !ruby/object:Gem::Requirement
286
286
  requirements:
287
- - - ">="
287
+ - - ">"
288
288
  - !ruby/object:Gem::Version
289
- version: '0'
289
+ version: 1.3.1
290
290
  requirements: []
291
291
  rubyforge_project:
292
- rubygems_version: 2.6.13
292
+ rubygems_version: 2.5.1
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: Markdown publish/consume contract parser and validator