lacerda 0.13.2 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.markdown +4 -0
- data/circle.yml +1 -1
- data/lacerda.gemspec +7 -8
- data/lib/lacerda/compare/json_schema.rb +34 -10
- data/lib/lacerda/conversion.rb +2 -10
- data/lib/lacerda/conversion/data_structure.rb +2 -1
- data/lib/lacerda/object_description.rb +7 -0
- data/lib/lacerda/specification.rb +2 -1
- data/lib/lacerda/version.rb +1 -1
- metadata +29 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02a819a552f7641904455f8f4a49343054018444
|
4
|
+
data.tar.gz: d0be854811c7f1c4ddd85d3c1249397a4c7d9f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b045f882e73febac8073f10095865a4ba3b81b3bf7202d8c18be9a8ca61fc853eeab730ecd5057cde6950117129fd16b3ab02b24f0fd13d7a59d9544e9edaac
|
7
|
+
data.tar.gz: 3724646f4afba1c1b6523b819aa8e184174940f159d9e27047742e22bac22b1c2fc3a486bb25a890d4fd78be6ee39bae7fac32022782581bfe63b11c86efb5e2
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2
|
1
|
+
2.3.0
|
data/CHANGELOG.markdown
CHANGED
data/circle.yml
CHANGED
data/lacerda.gemspec
CHANGED
@@ -22,8 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "activesupport"
|
23
23
|
spec.add_runtime_dependency "rake", ["~> 10.2"]
|
24
24
|
|
25
|
-
|
26
|
-
spec.add_runtime_dependency "json-schema", ["~> 2.5.1"]
|
25
|
+
spec.add_runtime_dependency "json-schema", ["~> 2.6.2"]
|
27
26
|
|
28
27
|
spec.add_runtime_dependency "redsnow", ["~> 0.4.3"]
|
29
28
|
spec.add_runtime_dependency "colorize"
|
@@ -32,12 +31,12 @@ Gem::Specification.new do |spec|
|
|
32
31
|
# Tins 1.7.0 is ruby 2.0 only
|
33
32
|
spec.add_runtime_dependency "tins", ["~> 1.6.0"]
|
34
33
|
|
35
|
-
spec.add_development_dependency "bundler"
|
36
|
-
spec.add_development_dependency "guard-bundler"
|
37
|
-
spec.add_development_dependency "guard-ctags-bundler"
|
38
|
-
spec.add_development_dependency "guard-rspec"
|
39
|
-
spec.add_development_dependency "rspec"
|
40
|
-
spec.add_development_dependency "coveralls"
|
34
|
+
spec.add_development_dependency "bundler"
|
35
|
+
spec.add_development_dependency "guard-bundler"
|
36
|
+
spec.add_development_dependency "guard-ctags-bundler"
|
37
|
+
spec.add_development_dependency "guard-rspec"
|
38
|
+
spec.add_development_dependency "rspec"
|
39
|
+
spec.add_development_dependency "coveralls"
|
41
40
|
spec.add_development_dependency "codeclimate-test-reporter"
|
42
41
|
spec.add_development_dependency 'pry'
|
43
42
|
# spec.add_development_dependency 'pry-byebug'
|
@@ -16,6 +16,7 @@ module Lacerda
|
|
16
16
|
|
17
17
|
def initialize(containing_schema)
|
18
18
|
@containing_schema = containing_schema
|
19
|
+
@errors = []
|
19
20
|
end
|
20
21
|
|
21
22
|
def contains?(contained_schema, initial_location = nil)
|
@@ -29,6 +30,7 @@ module Lacerda
|
|
29
30
|
publish = options[:publish]
|
30
31
|
consume = options[:consume]
|
31
32
|
location = options[:location] || []
|
33
|
+
return false unless publish and consume
|
32
34
|
|
33
35
|
# We can only compare types and $refs, so let's make
|
34
36
|
# sure they're there
|
@@ -87,7 +89,8 @@ module Lacerda
|
|
87
89
|
|
88
90
|
# We already know that publish and consume's type are equal
|
89
91
|
# but if they're objects, we need to do some recursion
|
90
|
-
|
92
|
+
isnt_a_primitive = [consume['type']].flatten.include?('object') || consume['oneOf'] || publish['oneOf']
|
93
|
+
if isnt_a_primitive
|
91
94
|
|
92
95
|
# An object can either be described by its properties
|
93
96
|
# like this:
|
@@ -122,16 +125,16 @@ module Lacerda
|
|
122
125
|
|
123
126
|
# Check all publish types for a compatible consume type
|
124
127
|
publish_types.each do |publish_type|
|
125
|
-
original_errors = @errors
|
126
|
-
@errors = []
|
127
128
|
compatible_consume_type_found = false
|
128
129
|
consume_types.each do |consume_type|
|
129
|
-
next unless publish_type == consume_type or
|
130
|
-
|
130
|
+
next unless publish_type == consume_type or
|
131
|
+
compare_sub_types(publish_type, consume_type, location + [publish_type])
|
131
132
|
compatible_consume_type_found = true
|
132
133
|
end
|
133
|
-
|
134
|
-
|
134
|
+
|
135
|
+
unless compatible_consume_type_found
|
136
|
+
return _e(:ERR_MISSING_MULTI_PUBLISH_MULTI_CONSUME, location, publish_type)
|
137
|
+
end
|
135
138
|
end
|
136
139
|
|
137
140
|
# Mixed case 1/2:
|
@@ -145,7 +148,9 @@ module Lacerda
|
|
145
148
|
compatible_consume_type_found = true
|
146
149
|
end
|
147
150
|
@errors = original_errors
|
148
|
-
|
151
|
+
unless compatible_consume_type_found
|
152
|
+
return _e(:ERR_MISSING_SINGLE_PUBLISH_MULTI_CONSUME, location, publish['type'])
|
153
|
+
end
|
149
154
|
|
150
155
|
# Mixed case 2/2:
|
151
156
|
elsif consume['properties'] and publish['oneOf']
|
@@ -158,7 +163,9 @@ module Lacerda
|
|
158
163
|
incompatible_publish_type = publish_type
|
159
164
|
end
|
160
165
|
@errors = original_errors
|
161
|
-
|
166
|
+
if incompatible_publish_type
|
167
|
+
return _e(:ERR_MISSING_MULTI_PUBLISH_SINGLE_CONSUME, location, incompatible_publish_type)
|
168
|
+
end
|
162
169
|
|
163
170
|
# We don't know how to handle this 😳
|
164
171
|
# an object can either have "properties" or "oneOf", if the schema has anything else, we break
|
@@ -170,6 +177,7 @@ module Lacerda
|
|
170
177
|
if consume['type'] == 'array'
|
171
178
|
sorted_publish = publish['items'].sort
|
172
179
|
consume['items'].sort.each_with_index do |item, i|
|
180
|
+
# TODO why just compare sorted_publish[i] and not all??
|
173
181
|
next if schema_contains?(publish: sorted_publish[i], consume: item)
|
174
182
|
return _e(:ERR_ARRAY_ITEM_MISMATCH, location, nil)
|
175
183
|
end
|
@@ -182,7 +190,7 @@ module Lacerda
|
|
182
190
|
|
183
191
|
def properties_contained?
|
184
192
|
@contained_schema['properties'].each do |property, contained_property|
|
185
|
-
resolved_contained_property = data_for_pointer(
|
193
|
+
resolved_contained_property = data_for_pointer(contained_property, @contained_schema)
|
186
194
|
containing_property = @containing_schema['properties'][property]
|
187
195
|
if !containing_property
|
188
196
|
_e(:ERR_MISSING_DEFINITION, [@initial_location, property], "(in publish.mson)")
|
@@ -242,6 +250,22 @@ module Lacerda
|
|
242
250
|
return false unless type
|
243
251
|
schema['definitions'][type]
|
244
252
|
end
|
253
|
+
|
254
|
+
# If you just want to compare two json objects/types,
|
255
|
+
# this method wraps them into full schemas, creates a new
|
256
|
+
# instance of self and compares
|
257
|
+
def compare_sub_types(containing, contained, location)
|
258
|
+
resolved_containing = data_for_pointer(containing, @containing_schema)
|
259
|
+
resolved_contained = data_for_pointer(contained, @contained_schema)
|
260
|
+
containing_schema = {
|
261
|
+
'definitions' => { 'foo' => resolved_containing },
|
262
|
+
'properties' => { 'bar' => { '$ref' => '#/definitions/foo' } }
|
263
|
+
}
|
264
|
+
comparator = self.class.new(containing_schema)
|
265
|
+
# TODO we need errorrs to bubble up here
|
266
|
+
result = comparator.schema_contains?(publish: resolved_containing, consume: resolved_contained)
|
267
|
+
result
|
268
|
+
end
|
245
269
|
end
|
246
270
|
end
|
247
271
|
end
|
data/lib/lacerda/conversion.rb
CHANGED
@@ -44,16 +44,8 @@ module Lacerda
|
|
44
44
|
"properties" => {},
|
45
45
|
}
|
46
46
|
|
47
|
-
# The scope for the data structure is the name of the service
|
48
|
-
# publishing the object. So if we're parsing a 'consume' schema,
|
49
|
-
# the containing objects are alredy scoped (because a consume
|
50
|
-
# schema says 'i consume object X from service Y'.
|
51
47
|
basename = File.basename(filename)
|
52
|
-
if basename.end_with?("publish.mson")
|
53
|
-
data_structure_autoscope = service_scope
|
54
|
-
elsif basename.end_with?("consume.mson")
|
55
|
-
data_structure_autoscope = nil
|
56
|
-
else
|
48
|
+
if !basename.end_with?("publish.mson") and !basename.end_with?("consume.mson")
|
57
49
|
raise Error, "Invalid filename #{basename}, can't tell if it's a publish or consume schema"
|
58
50
|
end
|
59
51
|
|
@@ -90,7 +82,7 @@ module Lacerda
|
|
90
82
|
#
|
91
83
|
data_structures.each do |data|
|
92
84
|
id = data['name']['literal']
|
93
|
-
json= DataStructure.new(id, data,
|
85
|
+
json= DataStructure.new(id, data, nil).to_json
|
94
86
|
member = json.delete('title')
|
95
87
|
schema['definitions'][member] = json
|
96
88
|
schema['properties'][member] = {"$ref" => "#/definitions/#{member}"}
|
@@ -81,7 +81,8 @@ module Lacerda
|
|
81
81
|
# If it's an array, we need to pluck out the item types
|
82
82
|
if type == 'array'
|
83
83
|
nestedTypes = type_definition['typeSpecification']['nestedTypes']
|
84
|
-
|
84
|
+
# Passing false here, because an empty array is still an array
|
85
|
+
spec['items'] = nestedTypes.map{|t| primitive_or_reference(t, false) }
|
85
86
|
|
86
87
|
# If it's an object, we need recursion
|
87
88
|
elsif type == 'object'
|
@@ -25,12 +25,19 @@ module Lacerda
|
|
25
25
|
@scoped_name = scoped_name
|
26
26
|
@name = remove_service_from_scoped_name(scoped_name)
|
27
27
|
@schema = schema.with_indifferent_access
|
28
|
+
@schema['$schema'] ||= 'http://json-schema.org/draft-04/schema#'
|
28
29
|
end
|
29
30
|
|
30
31
|
def validate_data!(data)
|
31
32
|
JSON::Validator.validate!(@schema, data)
|
32
33
|
end
|
33
34
|
|
35
|
+
def validate_data(data)
|
36
|
+
JSON::Validator.validate!(@schema, data)
|
37
|
+
rescue JSON::Schema::ValidationError
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
34
41
|
private
|
35
42
|
|
36
43
|
def remove_service_from_scoped_name(n)
|
@@ -14,8 +14,9 @@ module Lacerda
|
|
14
14
|
def objects
|
15
15
|
return [] unless @schema[:definitions]
|
16
16
|
@schema[:definitions].map do |scoped_name, schema|
|
17
|
+
next if !scoped_name.index(SCOPE_SEPARATOR)
|
17
18
|
object_description_class.new(service, scoped_name, schema)
|
18
|
-
end
|
19
|
+
end.compact
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
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: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jannis Hermanns
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 2.6.2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 2.6.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: redsnow
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,86 +112,86 @@ dependencies:
|
|
112
112
|
name: bundler
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: guard-bundler
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: guard-ctags-bundler
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: guard-rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
173
|
+
version: '0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
180
|
+
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: coveralls
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '0
|
187
|
+
version: '0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '0
|
194
|
+
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: codeclimate-test-reporter
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
version: '0'
|
282
282
|
requirements: []
|
283
283
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.4
|
284
|
+
rubygems_version: 2.6.4
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Markdown publish/consume contract parser and validator
|