Skip to content

Commit 5236e5b

Browse files
committed
issue 572: is_array should only be applied to success
- updates travis - adds changelog entry
1 parent df001e4 commit 5236e5b

File tree

6 files changed

+78
-26
lines changed

6 files changed

+78
-26
lines changed

.rubocop.yml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ AllCops:
55

66
inherit_from: .rubocop_todo.yml
77

8+
Metrics/BlockLength:
9+
Exclude:
10+
- spec/**/*
11+
812
Metrics/LineLength:
913
Exclude:
1014
- spec/**/*

.travis.yml

+21-22
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@ language: ruby
33
sudo: false
44

55
before_install:
6+
- gem update --system
67
- gem install bundler
78

89
after_success:
10+
- bundle exec danger
911
- coveralls
1012

13+
rvm:
14+
- 2.4.0
15+
- 2.3.3
16+
17+
env:
18+
- MODEL_PARSER=grape-swagger-entity
19+
- MODEL_PARSER=grape-swagger-representable
20+
- GRAPE_VERSION=0.16.2
21+
- GRAPE_VERSION=0.17.0
22+
- GRAPE_VERSION=0.18.0
23+
- GRAPE_VERSION=0.19.1
24+
- GRAPE_VERSION=HEAD
25+
1126
matrix:
1227
fast_finish: true
28+
1329
include:
14-
- rvm: 2.4.0
15-
script:
16-
- bundle exec danger
17-
- rvm: 2.4.0
18-
env: MODEL_PARSER=grape-swagger-entity
19-
- rvm: 2.4.0
20-
env: MODEL_PARSER=grape-swagger-representable
21-
- rvm: 2.4.0
22-
env: GRAPE_VERSION=0.16.2
23-
- rvm: 2.4.0
24-
env: GRAPE_VERSION=0.17.0
25-
- rvm: 2.4.0
26-
env: GRAPE_VERSION=0.18.0
27-
- rvm: 2.4.0
28-
env: GRAPE_VERSION=0.19.0
29-
- rvm: 2.4.0
30-
env: GRAPE_VERSION=HEAD
31-
- rvm: 2.3.3
32-
env: MODEL_PARSER=grape-swagger-entity
33-
- rvm: 2.3.3
34-
env: MODEL_PARSER=grape-swagger-representable
35-
- rvm: 2.3.3
3630
- rvm: 2.2.6
31+
env:
3732
- rvm: ruby-head
33+
env:
3834
- rvm: jruby-head
35+
env:
3936
- rvm: rbx-2
37+
env:
38+
4039
allow_failures:
4140
- rvm: ruby-head
4241
- rvm: jruby-head

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#### Fixes
1212

1313
* [#562](https://github.com/ruby-grape/grape-swagger/pull/562): The guard method should allow regular object methods as arguments - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
14+
* [#574](https://github.com/ruby-grape/grape-swagger/pull/574): Issue #572: is_array should only be applied to success - [@LeFnord](https://github.com/LeFnord).
1415

1516
* Your contribution here.
1617

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ group :development, :test do
2323
gem 'rake'
2424
gem 'rdoc'
2525
gem 'rspec', '~> 3.0'
26-
gem 'rubocop', '~> 0.40'
26+
gem 'rubocop', '~> 0.46'
2727
end
2828
group :test do
2929
gem 'coveralls', require: false

lib/grape-swagger/endpoint.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,12 @@ def response_object(route)
195195
end
196196

197197
next if memo.key?(204)
198-
next unless !response_model.start_with?('Swagger_doc') &&
199-
((@definitions[response_model] && value[:code].to_s.start_with?('2')) || value[:model])
198+
next unless !response_model.start_with?('Swagger_doc') && (@definitions[response_model] || value[:model])
200199

201200
@definitions[response_model][:description] = description_object(route)
202201
# TODO: proof that the definition exist, if model isn't specified
203202
reference = { '$ref' => "#/definitions/#{response_model}" }
204-
memo[value[:code]][:schema] = if route.options[:is_array]
203+
memo[value[:code]][:schema] = if route.options[:is_array] && value[:code] < 300
205204
{ 'type' => 'array', 'items' => reference }
206205
else
207206
reference
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'spec_helper'
2+
3+
describe '#572 is_array is applied to all possible responses' do
4+
include_context "#{MODEL_PARSER} swagger example"
5+
6+
let(:app) do
7+
Class.new(Grape::API) do
8+
namespace :issue_572 do
9+
desc 'get issue',
10+
is_array: true,
11+
success: Entities::UseResponse,
12+
failure: [
13+
[401, 'BadKittenError', Entities::ApiError],
14+
[404, 'NoTreatsError', Entities::ApiError],
15+
[429, 'TooManyScratchesError', Entities::ApiError]
16+
]
17+
18+
get
19+
end
20+
21+
add_swagger_documentation format: :json
22+
end
23+
end
24+
25+
subject do
26+
get '/swagger_doc'
27+
JSON.parse(last_response.body)
28+
end
29+
30+
let(:codes) { %w(200 401 404 429) }
31+
32+
let(:responses) { subject['paths']['/issue_572']['get']['responses'] }
33+
34+
specify { expect(responses.keys.sort).to eq codes }
35+
36+
specify do
37+
expect(responses['200']['schema']).to include 'type'
38+
expect(responses['200']['schema']['type']).to eql 'array'
39+
end
40+
41+
describe 'no array types' do
42+
specify do
43+
codes[1..-1].each do |code|
44+
expect(responses[code]['schema']).not_to include 'type'
45+
expect(responses[code]['schema'].keys).to eql ['$ref']
46+
end
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)