Skip to content

Commit da68023

Browse files
authored
Merge branch 'master' into fix-array-use-braces-for-body-params
2 parents 89f113b + 204ced4 commit da68023

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* [#757](https://github.com/ruby-grape/grape-swagger/pull/757): Fix `array_use_braces` for nested body params - [@bikolya](https://github.com/bikolya).
10+
* [#756](https://github.com/ruby-grape/grape-swagger/pull/756): Fix reference creation when custom type for documentation is provided - [@bikolya](https://github.com/bikolya).
1011

1112
### 0.33.0 (June 21, 2019)
1213

lib/grape-swagger/endpoint.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ def params_object(route, options, path)
178178
parameters = partition_params(route, options).map do |param, value|
179179
value = { required: false }.merge(value) if value.is_a?(Hash)
180180
_, value = default_type([[param, value]]).first if value == ''
181-
if value[:type]
182-
expose_params(value[:type])
183-
elsif value[:documentation]
181+
if value.dig(:documentation, :type)
184182
expose_params(value[:documentation][:type])
183+
elsif value[:type]
184+
expose_params(value[:type])
185185
end
186186
GrapeSwagger::DocMethods::ParseParams.call(param, value, path, route, @definitions)
187187
end

spec/swagger_v2/endpoint_versioned_path_spec.rb

+33
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,39 @@
5252
expect(subject.first['/v1/item'][:get][:tags]).to eq ['special-item']
5353
end
5454
end
55+
56+
context 'when parameter with a custom type is specified' do
57+
let(:item) do
58+
Class.new(Grape::API) do
59+
Color = Struct.new(:value) do
60+
def self.parse(value)
61+
new(value: value)
62+
end
63+
end
64+
65+
class ColorEntity < Grape::Entity
66+
expose :value
67+
end
68+
69+
version 'v1', using: :path
70+
71+
resource :item do
72+
params do
73+
requires :root, type: Hash do
74+
optional :color, type: Color, documentation: { type: ColorEntity }
75+
end
76+
end
77+
post '/'
78+
end
79+
end
80+
end
81+
82+
it 'creates a reference to the model instead of using the non-existent type' do
83+
color = subject.dig(1, 'postV1Item', :properties, :root, :properties, :color)
84+
expect(color).not_to eq(type: 'ColorEntity')
85+
expect(color).to eq('$ref' => '#/definitions/ColorEntity')
86+
end
87+
end
5588
end
5689

5790
context 'when mounting an API more than once', if: GrapeVersion.satisfy?('>= 1.2.0') do

0 commit comments

Comments
 (0)