swagger-diff 1.0.3 → 1.0.4
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 +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +9 -0
- data/README.md +6 -6
- data/lib/swagger/diff/patch.rb +14 -0
- data/lib/swagger/diff/specification.rb +54 -31
- data/lib/swagger/diff/version.rb +1 -1
- data/swagger-diff.gemspec +2 -2
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8152e95fa05dcd25376b7f726edab41888836072
|
4
|
+
data.tar.gz: 752d5db3f0c6410341336930e1b70a28ac524862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e70c465faaf5936d41ff58e6765ad841dd36c10037050fd3b6e274bf7c8cad23ad302400cf21468b8bb747eaaef0cf13e63831b72689a2e6ae34643fb6c0f4
|
7
|
+
data.tar.gz: d6456a1a767e7bcace9da7cda0f8de1b0c1542ab93b24ee977a846e5d2441f5c1ae43e680f540f9e9cc2d3a8e6d96bd0271fa2a2c36207d140f07877f20f8bf7
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.0.4 (2015-11-11)
|
4
|
+
|
5
|
+
### Bugs Fixed
|
6
|
+
|
7
|
+
* [#14](https://github.com/civisanalytics/swagger-diff/pull/14)
|
8
|
+
allow schema definitions without properties
|
9
|
+
* [#15](https://github.com/civisanalytics/swagger-diff/pull/15)
|
10
|
+
parse non-ref response schemas (`allOf`, `properties`, and `items`)
|
11
|
+
|
3
12
|
## 1.0.3 (2015-11-04)
|
4
13
|
|
5
14
|
### Changes
|
data/README.md
CHANGED
@@ -57,8 +57,8 @@ Specifications can be any
|
|
57
57
|
`http://host.domain/swagger.yml`)
|
58
58
|
- a Hash containing a parsed Swagger specification (*e.g.*, the output of
|
59
59
|
`JSON.parse`)
|
60
|
-
- a string of JSON containing Swagger specification
|
61
|
-
- a string of YAML containing Swagger specification
|
60
|
+
- a string of JSON containing a Swagger specification
|
61
|
+
- a string of YAML containing a Swagger specification
|
62
62
|
|
63
63
|
### RSpec
|
64
64
|
|
@@ -85,14 +85,14 @@ request parameters, and response attributes; *e.g.*,
|
|
85
85
|
```ruby
|
86
86
|
{ endpoints: ['put /a/{}'],
|
87
87
|
request_params: {
|
88
|
-
'get /a/' => ['missing request param: limit (type: integer)'],
|
88
|
+
'get /a/' => ['missing request param: limit (in: query, type: integer)'],
|
89
89
|
'post /a/' => ['new required request param: extra'],
|
90
90
|
'put /b/{}' => ['new required request param: extra']
|
91
91
|
},
|
92
92
|
response_attributes: {
|
93
|
-
'post /a/' => ['missing attribute from 200 response: description (type: string)'],
|
94
|
-
'get /a/{}' => ['missing attribute from 200 response: description (type: string)'],
|
95
|
-
'put /b/{}' => ['missing attribute from 200 response: description (type: string)']
|
93
|
+
'post /a/' => ['missing attribute from 200 response: description (in: body, type: string)'],
|
94
|
+
'get /a/{}' => ['missing attribute from 200 response: description (in: body, type: string)'],
|
95
|
+
'put /b/{}' => ['missing attribute from 200 response: description (in: body, type: string)']
|
96
96
|
}
|
97
97
|
}
|
98
98
|
```
|
data/lib/swagger/diff/patch.rb
CHANGED
@@ -13,3 +13,17 @@ OAUTH2_PARAMS = [:flow, :authorizationUrl, :scopes]
|
|
13
13
|
Swagger::V2::SecurityScheme.required_properties.reject! do |k, _|
|
14
14
|
OAUTH2_PARAMS.include?(k)
|
15
15
|
end
|
16
|
+
|
17
|
+
# Workaround for Swagger::V2::Operation[1] not including deprecated. Patching
|
18
|
+
# pending a merge/release of #11[2].
|
19
|
+
#
|
20
|
+
# [1] https://github.com/swagger-rb/swagger-rb/blob/master/lib/swagger/v2/operation.rb
|
21
|
+
# [2] https://github.com/swagger-rb/swagger-rb/pull/12/files
|
22
|
+
|
23
|
+
module Swagger
|
24
|
+
module V2
|
25
|
+
class Operation
|
26
|
+
field :deprecated, String
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -84,22 +84,40 @@ module Swagger
|
|
84
84
|
# parameter definitions (i.e., all parameters, including nested
|
85
85
|
# parameters, are included in a single set).
|
86
86
|
def refs(ref, prefix = '')
|
87
|
-
definitions = @parsed.definitions
|
88
87
|
idx = ref.rindex('/')
|
89
88
|
key = ref[idx + 1..-1]
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
schema(@parsed.definitions[key], prefix)
|
90
|
+
end
|
91
|
+
|
92
|
+
def all_of!(definitions, prefix, ret)
|
93
|
+
definitions.each do |s|
|
94
|
+
if s['$ref']
|
95
|
+
merge_refs!(ret, refs(s['$ref'], prefix))
|
96
|
+
else
|
97
|
+
merge_refs!(ret, schema(s, prefix))
|
98
98
|
end
|
99
|
-
|
99
|
+
end
|
100
|
+
ret
|
101
|
+
end
|
102
|
+
|
103
|
+
def array?(definition)
|
104
|
+
definition.type && definition.type == 'array' && definition.items
|
105
|
+
end
|
106
|
+
|
107
|
+
def schema(definition, prefix = '')
|
108
|
+
ret = { required: Set.new, all: Set.new }
|
109
|
+
if definition.allOf
|
110
|
+
all_of!(definition.allOf, prefix, ret)
|
111
|
+
elsif definition['$ref']
|
112
|
+
merge_refs!(ret, refs(definition['$ref'], prefix))
|
113
|
+
elsif definition.properties
|
100
114
|
merge_refs!(ret,
|
101
|
-
properties(
|
102
|
-
|
115
|
+
properties(definition.properties,
|
116
|
+
definition.required, prefix))
|
117
|
+
elsif array?(definition)
|
118
|
+
merge_refs!(ret, schema(definition.items, "#{prefix}[]/"))
|
119
|
+
elsif definition.type == 'object'
|
120
|
+
ret[:all].add(hash_property(definition, prefix))
|
103
121
|
end
|
104
122
|
ret
|
105
123
|
end
|
@@ -129,6 +147,28 @@ module Swagger
|
|
129
147
|
ret
|
130
148
|
end
|
131
149
|
|
150
|
+
def hash_property(definition, prefix, name = '')
|
151
|
+
# Swagger 2.0 doesn't appear to support non-string keys[1]. If
|
152
|
+
# this changes, this will need to be updated.
|
153
|
+
# [1] https://github.com/swagger-api/swagger-spec/issues/299
|
154
|
+
# TODO: this doesn't handle hashes of objects.
|
155
|
+
key = if name == ''
|
156
|
+
# Remove the trailing slash, if present and no name was
|
157
|
+
# specified (a prefix will always either be blank or end in a
|
158
|
+
# trailing slash).
|
159
|
+
prefix[0..-2]
|
160
|
+
else
|
161
|
+
"#{prefix}#{name}"
|
162
|
+
end
|
163
|
+
type = if definition.additionalProperties &&
|
164
|
+
definition.additionalProperties.type
|
165
|
+
definition.additionalProperties.type
|
166
|
+
else
|
167
|
+
'*'
|
168
|
+
end
|
169
|
+
"#{key} (in: body, type: Hash[string, #{type}])"
|
170
|
+
end
|
171
|
+
|
132
172
|
def properties(properties, required, prefix = '')
|
133
173
|
ret = { required: Set.new, all: Set.new }
|
134
174
|
properties.each do |name, schema|
|
@@ -138,17 +178,7 @@ module Swagger
|
|
138
178
|
if schema.allOf
|
139
179
|
# TODO: handle nested allOfs.
|
140
180
|
else
|
141
|
-
|
142
|
-
# this changes, this will need to be updated.
|
143
|
-
# [1] https://github.com/swagger-api/swagger-spec/issues/299
|
144
|
-
# TODO: this doesn't handle hashes of objects.
|
145
|
-
type = if schema.additionalProperties &&
|
146
|
-
schema.additionalProperties.type
|
147
|
-
schema.additionalProperties.type
|
148
|
-
else
|
149
|
-
'*'
|
150
|
-
end
|
151
|
-
ret[:all].add("#{prefix}#{name} (in: body, type: Hash[string, #{type}])")
|
181
|
+
ret[:all].add(hash_property(schema, prefix, name))
|
152
182
|
end
|
153
183
|
else
|
154
184
|
merge_refs!(ret, properties_for_ref(prefix, name, schema, required))
|
@@ -175,14 +205,7 @@ module Swagger
|
|
175
205
|
ret = {}
|
176
206
|
endpoint.responses.each do |code, response|
|
177
207
|
if response.schema
|
178
|
-
|
179
|
-
ref = response.schema.items['$ref']
|
180
|
-
prefix = '[]/'
|
181
|
-
else
|
182
|
-
ref = response.schema['$ref']
|
183
|
-
prefix = ''
|
184
|
-
end
|
185
|
-
ret[code] = refs(ref, prefix)[:all]
|
208
|
+
ret[code] = schema(response.schema)[:all]
|
186
209
|
else
|
187
210
|
ret[code] = Set.new
|
188
211
|
end
|
data/lib/swagger/diff/version.rb
CHANGED
data/swagger-diff.gemspec
CHANGED
@@ -28,7 +28,7 @@ and helper functions that can be used directly.'
|
|
28
28
|
spec.add_development_dependency 'rake', '~> 10.4'
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.3'
|
30
30
|
spec.add_development_dependency 'pry', '~> 0.10.1'
|
31
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
32
|
-
spec.add_development_dependency 'vcr', '~>
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.35.0'
|
32
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
33
33
|
spec.add_development_dependency 'webmock', '~> 1.21'
|
34
34
|
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.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Cousens
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: swagger-core
|
@@ -100,28 +100,28 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.35.0
|
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.
|
110
|
+
version: 0.35.0
|
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: '
|
117
|
+
version: '3.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: '3.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: webmock
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,4 +195,3 @@ signing_key:
|
|
195
195
|
specification_version: 4
|
196
196
|
summary: Utility for comparing two Swagger specifications.
|
197
197
|
test_files: []
|
198
|
-
has_rdoc:
|