lacerda 2.1.3 → 2.1.4.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.markdown +4 -0
- data/lib/lacerda/compare/json_schema.rb +42 -33
- data/lib/lacerda/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b05d38440fd072d0007dea89ce2d9918ceb457
|
4
|
+
data.tar.gz: cf090174559cad51fd3fc811feeaba8963b7cef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9448fde020aad2ce929c3027f038bfaf66d3cd008c4b33038cc2d24517b43d271340fc6bb7055c0d34511a7b29093044dc8aa84e93ec6826f32761b26d9d62
|
7
|
+
data.tar.gz: f2f184248f2a47d2cd7db01fd788a8da85abffa38b68fa4aaa8547f619dc7c98c98646077d679485219e655768ebea358ad23dc683fdcdc5e119a648560fc5a5
|
data/.gitignore
CHANGED
data/CHANGELOG.markdown
CHANGED
@@ -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
|
-
|
129
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
-
|
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' =>
|
274
|
+
'definitions' => { 'foo' => resolved_containing},
|
266
275
|
'properties' => { 'bar' => { '$ref' => '#/definitions/foo' } }
|
267
276
|
}
|
268
277
|
comparator = self.class.new(containing_schema)
|
data/lib/lacerda/version.rb
CHANGED
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.
|
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-
|
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:
|
289
|
+
version: 1.3.1
|
290
290
|
requirements: []
|
291
291
|
rubyforge_project:
|
292
|
-
rubygems_version: 2.
|
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
|