swagger-diff 1.1.1 → 2.0.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
- SHA1:
3
- metadata.gz: ddac5fb36158431f343142208ecd61a858bd66cf
4
- data.tar.gz: 74fab6bd47f4cf4c52865451bb25dc0fa082591b
2
+ SHA256:
3
+ metadata.gz: 77e08e6693a59f44f05a4e2afad7ac7e6050d7b3991e5321ab600562676850ad
4
+ data.tar.gz: 5637e276a82f0db237e75cef473115016992303d5d80e1f369428bd1be3e4050
5
5
  SHA512:
6
- metadata.gz: b23daecdda524a3181d6c321a73ddabcd6a1431320caccebd1fee8a17ff33c4cd5bc74385e1a97b268f7d2c02faecc87573ed1d8c60310076b707722b9db466b
7
- data.tar.gz: 2213e486e794349ea51a0dc38fcd4d3f03748285a40050b0e1c4a070b75e22ffc65ad842742c44b1ce31576d2e3a558399dfe05238108167ec05e2887fc4aae4
6
+ metadata.gz: 35005cdb5e4fd49a87573d18609cbc6dbdbd7ddcd3f7034fa54ef2fd259ad08ebaba9927adfc066afb9e2d5908461110ef4664d4df8adf30fea3062ed1bab9f3
7
+ data.tar.gz: 3b84d0a98e462afc139976b855bbfde692bf96cc5bbb54e186d4e2d7f57cc3de2892a6d0d117769924a5953118d53f0f621c2731a2d5a1ef739db01163540331
data/.rubocop.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
3
4
 
4
- Layout/IndentHeredoc:
5
+ Layout/HeredocIndentation:
5
6
  Enabled: false
6
7
 
7
8
  Metrics/AbcSize:
@@ -15,7 +16,7 @@ Metrics/BlockLength:
15
16
  Metrics/ClassLength:
16
17
  Max: 250
17
18
 
18
- Metrics/LineLength:
19
+ Layout/LineLength:
19
20
  Max: 120
20
21
 
21
22
  Metrics/MethodLength:
@@ -31,7 +32,7 @@ Security/YAMLLoad:
31
32
  Style/Documentation:
32
33
  Enabled: false
33
34
 
34
- Style/FileName:
35
+ Naming/FileName:
35
36
  Enabled: false
36
37
 
37
38
  Style/FrozenStringLiteralComment:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 3.2.1
data/.travis.yml CHANGED
@@ -1,11 +1,10 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.0
5
- - 2.1.10
6
- - 2.2.7
7
- - 2.3.4
8
- - 2.4.1
4
+ - 2.7.7
5
+ - 3.0.5
6
+ - 3.1.3
7
+ - 3.2.1
9
8
  before_install:
10
9
  - gem update --system
11
10
  - rvm @global do gem install bundler
data/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.0.0]
9
+
10
+ ### Changed
11
+
12
+ * Bumped the Ruby version for development to 2.7.7
13
+ * Bumped the RuboCop version for development to 1.48.0
14
+ * Bumped the Travis matrix to 2.7.7, 3.0.5, 3.1.3, 3.2.1
15
+ * Bumped the Pry version for development to 0.14.1
16
+ * Bumped the VCR version for development to 6.1
17
+ * RuboCop fixes
18
+
19
+ ## [1.1.2] - 2017-09-13
20
+
21
+ ### Fixed
22
+
23
+ * [#56](https://github.com/civisanalytics/swagger-diff/pull/56)
24
+ recursively parse non-ref response schemas (`properties` and `items`)
25
+
8
26
  ## [1.1.1] - 2017-08-23
9
27
 
10
28
  ### Added
@@ -97,7 +115,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
97
115
 
98
116
  * Initial Release
99
117
 
100
- [Unreleased]: https://github.com/civisanalytics/swagger-diff/compare/v1.1.1...HEAD
118
+ [2.0.0]: https://github.com/civisanalytics/swagger-diff/compare/v1.1.2...v2.0.0
119
+ [1.1.2]: https://github.com/civisanalytics/swagger-diff/compare/v1.1.1...v1.1.2
101
120
  [1.1.1]: https://github.com/civisanalytics/swagger-diff/compare/v1.1.0...v1.1.1
102
121
  [1.1.0]: https://github.com/civisanalytics/swagger-diff/compare/v1.0.5...v1.1.0
103
122
  [1.0.5]: https://github.com/civisanalytics/swagger-diff/compare/v1.0.4...v1.0.5
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/civisanalytics/swagger-diff.svg?branch=master)](https://travis-ci.org/civisanalytics/swagger-diff)
4
4
  [![Gem Version](https://badge.fury.io/rb/swagger-diff.svg)](http://badge.fury.io/rb/swagger-diff)
5
- [![Dependency Status](https://gemnasium.com/civisanalytics/swagger-diff.svg)](https://gemnasium.com/civisanalytics/swagger-diff)
6
5
 
7
6
  ![Swagger::Diff in action](swagger-diff.gif)
8
7
 
@@ -31,7 +30,7 @@ Specifications are considered backwards compatible if:
31
30
  It can also be used to enumerate all changes between two specifications (*i.e.*,
32
31
  to generate a changelog).
33
32
 
34
- Read more on the [Civis Analytics blog](https://civisanalytics.com/blog/engineering/2015/10/02/using-swagger-to-detect-breaking-api-changes/).
33
+ Read more on the [Civis Analytics blog](https://www.civisanalytics.com/blog/if-it-loses-its-quack-does-it-still-talk-like-a-duck-using-swagger-to-detect-breaking-api-changes/).
35
34
 
36
35
  ## Installation
37
36
 
@@ -133,6 +133,7 @@ module Swagger
133
133
  def new_child?(req, old)
134
134
  idx = req.rindex('/')
135
135
  return false unless idx
136
+
136
137
  key = req[0..idx]
137
138
  old.none? { |param| param.start_with?(key) }
138
139
  end
@@ -142,8 +143,10 @@ module Swagger
142
143
  from.request_params.each do |key, old_params|
143
144
  new_params = to.request_params[key]
144
145
  next if new_params.nil?
146
+
145
147
  (new_params[:required] - old_params[:required]).each do |req|
146
148
  next if new_child?(req, old_params[:all])
149
+
147
150
  yielder << [key, format(req_msg, req: req)]
148
151
  end
149
152
  (old_params[:all] - new_params[:all]).each do |req|
@@ -181,7 +184,8 @@ module Swagger
181
184
  from.response_attributes.each do |key, old_attributes|
182
185
  new_attributes = to.response_attributes[key]
183
186
  next if new_attributes.nil?
184
- old_attributes.keys.each do |code|
187
+
188
+ old_attributes.each_key do |code|
185
189
  if new_attributes.key?(code)
186
190
  (old_attributes[code] - new_attributes[code]).each do |resp|
187
191
  yielder << [key, format(attr_msg, code: code, resp: resp)]
@@ -14,46 +14,48 @@ module Swagger
14
14
 
15
15
  def request_params
16
16
  @request_params ||= begin
17
- ret = {}
18
- @endpoint_hash.each do |key, endpoint|
19
- ret[key] = request_params_inner(params_or_nil(endpoint))
20
- end
21
- ret
22
- end
17
+ ret = {}
18
+ @endpoint_hash.each do |key, endpoint|
19
+ ret[key] = request_params_inner(params_or_nil(endpoint))
20
+ end
21
+ ret
22
+ end
23
23
  end
24
24
 
25
25
  def response_attributes
26
26
  @response_attributes ||= begin
27
- ret = {}
28
- @endpoint_hash.each do |key, endpoint|
29
- ret[key] = response_attributes_inner(endpoint)
30
- end
31
- ret
32
- end
27
+ ret = {}
28
+ @endpoint_hash.each do |key, endpoint|
29
+ ret[key] = response_attributes_inner(endpoint)
30
+ end
31
+ ret
32
+ end
33
33
  end
34
34
 
35
35
  private
36
36
 
37
- def merge_refs!(h1, h2)
38
- h2.each do |k, v|
39
- if h1.include?(k)
40
- h1[k] += h1[k].merge(v)
37
+ def merge_refs!(hash1, hash2)
38
+ hash2.each do |k, v|
39
+ if hash1.include?(k)
40
+ hash1[k] += hash1[k].merge(v)
41
41
  else
42
- h1[k] = v
42
+ hash1[k] = v
43
43
  end
44
44
  end
45
45
  end
46
46
 
47
47
  def params_or_nil(endpoint)
48
- endpoint && endpoint['parameters'] || nil
48
+ (endpoint && endpoint['parameters']) || nil
49
49
  end
50
50
 
51
51
  def parse_swagger(swagger)
52
52
  if swagger.is_a? Hash
53
53
  swagger
54
54
  else
55
- if File.exist?(swagger) || swagger[0..7] =~ %r{^https?://}
56
- swagger = open(swagger).read
55
+ if File.exist?(swagger)
56
+ swagger = File.read(swagger)
57
+ elsif swagger[0..7] =~ %r{^https?://}
58
+ swagger = URI.parse(swagger).read
57
59
  end
58
60
  begin
59
61
  JSON.parse(swagger)
@@ -104,7 +106,7 @@ module Swagger
104
106
  {}
105
107
  end
106
108
  idx = ref.rindex('/')
107
- key = ref[idx + 1..-1]
109
+ key = ref[idx + 1..]
108
110
  schema(defs.fetch(key, {}), prefix)
109
111
  end
110
112
 
@@ -150,7 +152,7 @@ module Swagger
150
152
  # rubocop:enable Metrics/CyclomaticComplexity
151
153
  # rubocop:enable Metrics/AbcSize
152
154
 
153
- def nested(ref, prefix, name, list = false)
155
+ def nested(ref, prefix, name, list: false)
154
156
  # Check for cycles by testing whether name was already added to
155
157
  # prefix.
156
158
  key = "#{prefix}#{name}#{'[]' if list}"
@@ -172,19 +174,24 @@ module Swagger
172
174
  properties_for_ref(prefix, definition['name'], definition, required)
173
175
  end
174
176
 
175
- def properties_for_ref(prefix, name, schema, required, list = false)
177
+ # rubocop:disable Metrics/ParameterLists
178
+ def add_property(ret, prefix, name, schema, required, list)
176
179
  key = "#{prefix}#{name}"
180
+ ret[:required].add(key) if required&.include?(name)
181
+ loc = schema['in'] || 'body'
182
+ ret[:all].add("#{key} (in: #{loc}, type: #{schema['type']}#{'[]' if list})")
183
+ end
184
+ # rubocop:enable Metrics/ParameterLists
185
+
186
+ def properties_for_ref(prefix, name, schema, required, list: false)
177
187
  ret = { required: Set.new, all: Set.new }
178
- if schema.key?('$ref')
179
- merge_refs!(ret, nested(schema['$ref'], prefix, name, list))
188
+ if schema['$ref']
189
+ merge_refs!(ret, nested(schema['$ref'], prefix, name, list: list))
190
+ elsif schema['properties']
191
+ prefix = "#{name}#{'[]' if list}/"
192
+ merge_refs!(ret, properties(schema['properties'], schema['required'], prefix))
180
193
  else
181
- ret[:required].add(key) if required && required.include?(name)
182
- loc = if schema['in']
183
- schema['in']
184
- else
185
- 'body'
186
- end
187
- ret[:all].add("#{key} (in: #{loc}, type: #{schema['type']}#{'[]' if list})")
194
+ add_property(ret, prefix, name, schema, required, list)
188
195
  end
189
196
  ret
190
197
  end
@@ -211,16 +218,15 @@ module Swagger
211
218
  "#{key} (in: body, type: Hash[string, #{type}])"
212
219
  end
213
220
 
214
- # rubocop:disable Metrics/CyclomaticComplexity
215
221
  def properties(properties, required, prefix = '')
216
222
  ret = { required: Set.new, all: Set.new }
217
223
  properties.each do |name, schema|
218
224
  if schema['type'] == 'array'
219
- merge_refs!(ret, properties_for_ref(prefix, name, schema['items'], required, true))
220
- elsif schema['type'] == 'object'
225
+ merge_refs!(ret, properties_for_ref(prefix, name, schema['items'], required, list: true))
226
+ elsif schema['type'] == 'object' || schema['properties']
221
227
  if schema['allOf']
222
228
  # TODO: handle nested allOfs.
223
- elsif schema['type'] && schema['type'] == 'object' && schema['properties']
229
+ elsif schema['properties']
224
230
  merge_refs!(ret, properties(schema['properties'], required, "#{prefix}#{name}/"))
225
231
  else
226
232
  ret[:all].add(hash_property(schema, prefix, name))
@@ -231,11 +237,11 @@ module Swagger
231
237
  end
232
238
  ret
233
239
  end
234
- # rubocop:enable Metrics/CyclomaticComplexity
235
240
 
236
241
  def request_params_inner(params)
237
242
  ret = { required: Set.new, all: Set.new }
238
243
  return ret if params.nil?
244
+
239
245
  params.each do |param|
240
246
  if param['in'] == 'body'
241
247
  merge_refs!(ret, schema(param['schema']))
@@ -280,6 +286,7 @@ module Swagger
280
286
  JSON::Validator.add_schema(json_schema)
281
287
  errors = JSON::Validator.fully_validate(schema_for('oai'), JSON.dump(@parsed))
282
288
  return if errors.empty?
289
+
283
290
  spec = if @spec.to_s.length > 80
284
291
  "#{@spec.to_s[0..74]} ..."
285
292
  else
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Diff
3
- VERSION = '1.1.1'.freeze
3
+ VERSION = '2.0.0'.freeze
4
4
  end
5
5
  end
data/swagger-diff.gemspec CHANGED
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'swagger/diff/version'
6
4
 
@@ -27,15 +25,16 @@ Gem::Specification.new do |spec|
27
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
26
  spec.require_paths = ['lib']
29
27
 
30
- spec.required_ruby_version = '~> 2.0'
28
+ spec.required_ruby_version = '>= 2.7'
31
29
 
32
- spec.add_dependency 'json-schema', '~> 2.6'
30
+ spec.add_dependency 'json-schema', '~> 3.0'
33
31
  spec.add_dependency 'rspec-expectations', '~> 3.3'
34
- spec.add_development_dependency 'bundler', '~> 1.9'
35
- spec.add_development_dependency 'rake', '~> 11.1'
32
+ spec.add_development_dependency 'bundler', '~> 2.4.9'
33
+ spec.add_development_dependency 'pry', '~> 0.14.1'
34
+ spec.add_development_dependency 'rake', '~> 12.3'
36
35
  spec.add_development_dependency 'rspec', '~> 3.3'
37
- spec.add_development_dependency 'pry', '~> 0.10.1'
38
- spec.add_development_dependency 'rubocop', '~> 0.49.0'
39
- spec.add_development_dependency 'vcr', '~> 3.0'
36
+ spec.add_development_dependency 'rubocop', '~> 1.48.1'
37
+ spec.add_development_dependency 'vcr', '~> 6.1'
40
38
  spec.add_development_dependency 'webmock', '~> 3.0'
39
+ spec.metadata['rubygems_mfa_required'] = 'true'
41
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Cousens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-23 00:00:00.000000000 Z
11
+ date: 2023-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.6'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-expectations
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,84 +44,84 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.9'
47
+ version: 2.4.9
48
48
  type: :development
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: '1.9'
54
+ version: 2.4.9
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '11.1'
61
+ version: 0.14.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '11.1'
68
+ version: 0.14.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.3'
75
+ version: '12.3'
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: '3.3'
82
+ version: '12.3'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.10.1
89
+ version: '3.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.10.1
96
+ version: '3.3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.49.0
103
+ version: 1.48.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.49.0
110
+ version: 1.48.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: vcr
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.0'
117
+ version: '6.1'
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: '3.0'
124
+ version: '6.1'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: webmock
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -176,24 +176,24 @@ files:
176
176
  homepage: https://github.com/civisanalytics/swagger-diff
177
177
  licenses:
178
178
  - BSD 3-Clause
179
- metadata: {}
179
+ metadata:
180
+ rubygems_mfa_required: 'true'
180
181
  post_install_message:
181
182
  rdoc_options: []
182
183
  require_paths:
183
184
  - lib
184
185
  required_ruby_version: !ruby/object:Gem::Requirement
185
186
  requirements:
186
- - - "~>"
187
+ - - ">="
187
188
  - !ruby/object:Gem::Version
188
- version: '2.0'
189
+ version: '2.7'
189
190
  required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  requirements:
191
192
  - - ">="
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubyforge_project:
196
- rubygems_version: 2.6.11
196
+ rubygems_version: 3.4.6
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Utility for comparing two OAI (fka Swagger) specifications.