Skip to content

Commit dc7f062

Browse files
committed
Merge pull request #10 from civisanalytics/check_param_in_has_not_changed
Detect if a parameter's location (*i.e.*, `in` value) changes
2 parents 840cead + 3d7d46e commit dc7f062

File tree

5 files changed

+135
-132
lines changed

5 files changed

+135
-132
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
* [#8](https://github.com/civisanalytics/swagger-diff/pull/8)
1313
fixed parsing of header and formData parameters
14+
* [#10](https://github.com/civisanalytics/swagger-diff/pull/10)
15+
detect if a parameter's location (*i.e.*, `in` value) changes
1416

1517
## 1.0.2 (2015-10-08)
1618

lib/swagger/diff/specification.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def nested(ref, prefix, name, list = false)
111111
if prefix == "#{name}/" || prefix =~ %r{/#{name}(\[\])?/}
112112
# Anonymizing the reference in case the name changed (e.g.,
113113
# generated Swagger).
114-
{ all: ["#{key} (type: reference)"] }
114+
{ all: ["#{key} (in: body, type: reference)"] }
115115
else
116116
refs(ref, "#{key}/")
117117
end
@@ -124,7 +124,7 @@ def properties_for_ref(prefix, name, schema, required, list = false)
124124
merge_refs!(ret, nested(schema['$ref'], prefix, name, list))
125125
else
126126
ret[:required].add(key) if required && required.include?(name)
127-
ret[:all].add("#{key} (type: #{schema.type}#{'[]' if list})")
127+
ret[:all].add("#{key} (in: body, type: #{schema.type}#{'[]' if list})")
128128
end
129129
ret
130130
end
@@ -148,7 +148,7 @@ def properties(properties, required, prefix = '')
148148
else
149149
'*'
150150
end
151-
ret[:all].add("#{prefix}#{name} (type: Hash[string, #{type}])")
151+
ret[:all].add("#{prefix}#{name} (in: body, type: Hash[string, #{type}])")
152152
end
153153
else
154154
merge_refs!(ret, properties_for_ref(prefix, name, schema, required))
@@ -165,7 +165,7 @@ def request_params_inner(params)
165165
merge_refs!(ret, refs(param.schema['$ref']))
166166
else
167167
ret[:required].add(param.name) if param.required
168-
ret[:all].add("#{param.name} (type: #{param.type})")
168+
ret[:all].add("#{param.name} (in: #{param.in}, type: #{param.type})")
169169
end
170170
end
171171
ret

spec/swagger/diff/diff_spec.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
expect(incompat_diff.incompatibilities)
2424
.to eq(endpoints: ['post /b/', 'put /a/{}'],
2525
request_params: {
26-
'get /a/' => ['missing request param: limit (type: integer)'],
26+
'get /a/' => ['missing request param: limit (in: query, type: integer)'],
2727
'post /a/' => ['new required request param: extra'],
28-
'patch /a/{}' => ['missing request param: name (type: ["string", "null"])',
29-
'missing request param: obj/thing (type: integer)',
30-
'missing request param: str (type: string)'
28+
'patch /a/{}' => ['missing request param: name (in: body, type: ["string", "null"])',
29+
'missing request param: obj/thing (in: body, type: integer)',
30+
'missing request param: str (in: body, type: string)'
3131
],
3232
'put /b/{}' => ['new required request param: extra'],
3333
'post /c/' => ['new required request param: existing/b'] },
3434
response_attributes: {
35-
'post /a/' => ['missing attribute from 200 response: description (type: string)'],
36-
'get /a/{}' => ['missing attribute from 200 response: description (type: string)'],
37-
'patch /a/{}' => ['missing attribute from 200 response: obj/thing (type: integer)',
38-
'missing attribute from 200 response: objs[]/thing (type: integer)'],
39-
'put /b/{}' => ['missing attribute from 200 response: description (type: string)'],
40-
'get /c/' => ['missing attribute from 200 response: []/name (type: string)',
35+
'post /a/' => ['missing attribute from 200 response: description (in: body, type: string)'],
36+
'get /a/{}' => ['missing attribute from 200 response: description (in: body, type: string)'],
37+
'patch /a/{}' => ['missing attribute from 200 response: obj/thing (in: body, type: integer)',
38+
'missing attribute from 200 response: objs[]/thing (in: body, type: integer)'],
39+
'put /b/{}' => ['missing attribute from 200 response: description (in: body, type: string)'],
40+
'get /c/' => ['missing attribute from 200 response: []/name (in: body, type: string)',
4141
'missing 201 response'] })
4242
end
4343

@@ -48,11 +48,11 @@
4848
- put /a/{}
4949
- incompatible request params
5050
- get /a/
51-
- missing request param: limit (type: integer)
51+
- missing request param: limit (in: query, type: integer)
5252
- patch /a/{}
53-
- missing request param: name (type: ["string", "null"])
54-
- missing request param: obj/thing (type: integer)
55-
- missing request param: str (type: string)
53+
- missing request param: name (in: body, type: ["string", "null"])
54+
- missing request param: obj/thing (in: body, type: integer)
55+
- missing request param: str (in: body, type: string)
5656
- post /a/
5757
- new required request param: extra
5858
- post /c/
@@ -61,17 +61,17 @@
6161
- new required request param: extra
6262
- incompatible response attributes
6363
- get /a/{}
64-
- missing attribute from 200 response: description (type: string)
64+
- missing attribute from 200 response: description (in: body, type: string)
6565
- get /c/
66-
- missing attribute from 200 response: []/name (type: string)
66+
- missing attribute from 200 response: []/name (in: body, type: string)
6767
- missing 201 response
6868
- patch /a/{}
69-
- missing attribute from 200 response: obj/thing (type: integer)
70-
- missing attribute from 200 response: objs[]/thing (type: integer)
69+
- missing attribute from 200 response: obj/thing (in: body, type: integer)
70+
- missing attribute from 200 response: objs[]/thing (in: body, type: integer)
7171
- post /a/
72-
- missing attribute from 200 response: description (type: string)
72+
- missing attribute from 200 response: description (in: body, type: string)
7373
- put /b/{}
74-
- missing attribute from 200 response: description (type: string)
74+
- missing attribute from 200 response: description (in: body, type: string)
7575
'
7676
end
7777

spec/swagger/diff/rspec_matchers_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
- put /a/{}
2121
- incompatible request params
2222
- get /a/
23-
- missing request param: limit (type: integer)
23+
- missing request param: limit (in: query, type: integer)
2424
- patch /a/{}
25-
- missing request param: name (type: ["string", "null"])
26-
- missing request param: obj/thing (type: integer)
27-
- missing request param: str (type: string)
25+
- missing request param: name (in: body, type: ["string", "null"])
26+
- missing request param: obj/thing (in: body, type: integer)
27+
- missing request param: str (in: body, type: string)
2828
- post /a/
2929
- new required request param: extra
3030
- post /c/
@@ -33,17 +33,17 @@
3333
- new required request param: extra
3434
- incompatible response attributes
3535
- get /a/{}
36-
- missing attribute from 200 response: description (type: string)
36+
- missing attribute from 200 response: description (in: body, type: string)
3737
- get /c/
38-
- missing attribute from 200 response: []/name (type: string)
38+
- missing attribute from 200 response: []/name (in: body, type: string)
3939
- missing 201 response
4040
- patch /a/{}
41-
- missing attribute from 200 response: obj/thing (type: integer)
42-
- missing attribute from 200 response: objs[]/thing (type: integer)
41+
- missing attribute from 200 response: obj/thing (in: body, type: integer)
42+
- missing attribute from 200 response: objs[]/thing (in: body, type: integer)
4343
- post /a/
44-
- missing attribute from 200 response: description (type: string)
44+
- missing attribute from 200 response: description (in: body, type: string)
4545
- put /b/{}
46-
- missing attribute from 200 response: description (type: string)
46+
- missing attribute from 200 response: description (in: body, type: string)
4747
EOM
4848
expect do
4949
expect('spec/fixtures/dummy.v2.json')

0 commit comments

Comments
 (0)