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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e1b8aebb10149b3485dfc1ad6346f244d741152
4
- data.tar.gz: f6e2768f844519bc0a3a25d560ae7ede128b893f
3
+ metadata.gz: 02a819a552f7641904455f8f4a49343054018444
4
+ data.tar.gz: d0be854811c7f1c4ddd85d3c1249397a4c7d9f28
5
5
  SHA512:
6
- metadata.gz: c453a2af7d5fd37035ffeba7ff87aa9b6c02324427a68a9762c1b8dc23fda6bb115e151ee51a866462a3e6de79c341ad0de82642e6440872eda1d2235557b062
7
- data.tar.gz: f9c0d1a30e79eac870d879b4808ada927848dace4bea3198c032b4dbf4ccc93228d0cbfde7ef2e45e3112e8474c67ae73ca68da739cdc8f53c3127a11be32ddf
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
@@ -1,3 +1,7 @@
1
+ # 0.14.0
2
+ - FIX: a required array property may contain an empty array
3
+ - don't expose local definitions as published objects
4
+
1
5
  # 0.13.1
2
6
  - don't choke on schemas without local definitions
3
7
 
data/circle.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  machine:
2
2
  ruby:
3
- version: '1.9'
3
+ version: '2.3.0'
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
- # json-schema 2.6.0 validates differently than 2.5.1
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", ["~> 1"]
36
- spec.add_development_dependency "guard-bundler", ["~> 2.1"]
37
- spec.add_development_dependency "guard-ctags-bundler", ["~> 1.4"]
38
- spec.add_development_dependency "guard-rspec", ["~> 4.6"]
39
- spec.add_development_dependency "rspec", ["~> 3.3"]
40
- spec.add_development_dependency "coveralls", ["~> 0.8"]
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
- if [consume['type']].flatten.include?('object')
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 # Because null types are stripped in schema_contains
130
- schema_contains?(publish: publish_type, consume: consume_type, location: location + [publish_type])
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
- @errors = original_errors
134
- return _e(:ERR_MISSING_MULTI_PUBLISH_MULTI_CONSUME, location, publish_type) unless compatible_consume_type_found
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
- return _e(:ERR_MISSING_SINGLE_PUBLISH_MULTI_CONSUME, location, publish['type']) unless compatible_consume_type_found
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
- return _e(:ERR_MISSING_MULTI_PUBLISH_SINGLE_CONSUME, location, incompatible_publish_type) if incompatible_publish_type
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(property, @contained_schema)
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
@@ -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, data_structure_autoscope).to_json
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
- spec['items'] = nestedTypes.map{|t| primitive_or_reference(t, is_required) }
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
@@ -1,3 +1,3 @@
1
1
  module Lacerda
2
- VERSION = '0.13.2'
2
+ VERSION = '0.14.0'
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: 0.13.2
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-03-10 00:00:00.000000000 Z
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.5.1
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.5.1
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: '1'
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: '1'
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: '2.1'
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: '2.1'
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: '1.4'
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: '1.4'
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: '4.6'
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: '4.6'
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: '3.3'
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: '3.3'
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.8'
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.8'
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.8
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