|
95 | 95 | { 'declared_params' => declared(params) }
|
96 | 96 | end
|
97 | 97 |
|
| 98 | + helpers do |
| 99 | + params :common_params do |
| 100 | + requires :array_of_string, type: Array[String] |
| 101 | + requires :array_of_integer, type: Array[Integer] |
| 102 | + end |
| 103 | + end |
| 104 | + |
| 105 | + params do |
| 106 | + use :common_params |
| 107 | + end |
| 108 | + get '/endpoint_with_common_params' do |
| 109 | + { 'declared_params' => declared(params) } |
| 110 | + end |
| 111 | + |
| 112 | + params do |
| 113 | + use :common_params |
| 114 | + end |
| 115 | + post '/endpoint_with_common_params' do |
| 116 | + { 'declared_params' => declared(params) } |
| 117 | + end |
| 118 | + |
98 | 119 | add_swagger_documentation array_use_braces: array_use_braces
|
99 | 120 | end
|
100 | 121 | end
|
|
220 | 241 | expect(subject['paths']['/array_of_entities']['post']['parameters']).to eql(parameters)
|
221 | 242 | end
|
222 | 243 | end
|
| 244 | + |
| 245 | + describe 'retrieves the documentation for parameters shared between GET and POST endpoints' do |
| 246 | + subject do |
| 247 | + get '/swagger_doc/endpoint_with_common_params' |
| 248 | + JSON.parse(last_response.body) |
| 249 | + end |
| 250 | + |
| 251 | + describe 'for non-body parameters' do |
| 252 | + specify do |
| 253 | + expect(subject['paths']['/endpoint_with_common_params']['get']['parameters']).to eql( |
| 254 | + [ |
| 255 | + { 'in' => 'query', 'name' => "array_of_string#{braces}", 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true }, |
| 256 | + { 'in' => 'query', 'name' => "array_of_integer#{braces}", 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32' }, 'required' => true } |
| 257 | + ] |
| 258 | + ) |
| 259 | + end |
| 260 | + end |
| 261 | + |
| 262 | + describe 'for body parameters' do |
| 263 | + specify do |
| 264 | + expect(subject['paths']['/endpoint_with_common_params']['post']['parameters']).to eql( |
| 265 | + [ |
| 266 | + { 'in' => 'body', 'name' => 'postEndpointWithCommonParams', 'schema' => { '$ref' => '#/definitions/postEndpointWithCommonParams' }, 'required' => true } |
| 267 | + ] |
| 268 | + ) |
| 269 | + expect(subject['definitions']['postEndpointWithCommonParams']).to eql( |
| 270 | + 'type' => 'object', |
| 271 | + 'properties' => { |
| 272 | + 'array_of_string' => { # no braces, even if array_use_braces is true |
| 273 | + 'type' => 'array', |
| 274 | + 'items' => { |
| 275 | + 'type' => 'string' |
| 276 | + } |
| 277 | + }, |
| 278 | + 'array_of_integer' => { # no braces, even if array_use_braces is true |
| 279 | + 'type' => 'array', |
| 280 | + 'items' => { |
| 281 | + 'type' => 'integer', |
| 282 | + 'format' => 'int32' |
| 283 | + } |
| 284 | + } |
| 285 | + }, |
| 286 | + 'required' => %w[array_of_string array_of_integer] |
| 287 | + ) |
| 288 | + end |
| 289 | + end |
| 290 | + end |
223 | 291 | end
|
224 | 292 | end
|
225 | 293 | end
|
0 commit comments