Skip to content

fixes #539 and #542; not all of 530 was commited #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
* Your contribution here.


### 0.25.2 (November 30, 2016)

#### Fixes

* [#544](https://github.com/ruby-grape/grape-swagger/pull/544): Fixes #539 and #542; not all of 530 was commited - [@LeFnord](https://github.com/LeFnord).

### 0.25.1 (November 29, 2016)

#### Features
Expand Down
2 changes: 2 additions & 0 deletions lib/grape-swagger/doc_methods/move_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def should_correct_array?(param)

def correct_array_param(param)
param.first[:schema] = { type: param.first.delete(:type), items: param.first.delete(:items) }

param
end

def parent_definition_of_params(params, route)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require 'grape-entity'
require 'grape-swagger-entity'

describe '#427 nested entity given as string' do
describe '#539 post params given as array' do
let(:app) do
Class.new(Grape::API) do
namespace :issue_427 do
namespace :issue_539 do
class Element < Grape::Entity
expose :id
expose :description
Expand Down Expand Up @@ -35,7 +35,7 @@ class ArrayOfElements < Grape::Entity
JSON.parse(last_response.body)
end

let(:parameters) { subject['paths']['/issue_427']['post']['parameters'] }
let(:parameters) { subject['paths']['/issue_539']['post']['parameters'] }
let(:definitions) { subject['definitions'] }

specify do
Expand All @@ -48,7 +48,9 @@ class ArrayOfElements < Grape::Entity
}
]
)
end

specify do
expect(definitions).to eql(
'Element' => {
'type' => 'object',
Expand Down
46 changes: 46 additions & 0 deletions spec/issues/542_array_of_type_in_post_body_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'
require 'grape-entity'
require 'grape-swagger-entity'

describe '#542 array of type in post params' do
let(:app) do
Class.new(Grape::API) do
namespace :issue_542 do
params do
requires :logs, type: Array[String], documentation: { param_type: 'body' }
end

post do
present params
end
end

add_swagger_documentation format: :json
end
end

subject do
get '/swagger_doc'
JSON.parse(last_response.body)
end

let(:parameters) { subject['paths']['/issue_542']['post']['parameters'] }

specify do
expect(parameters).to eql(
[
{
'in' => 'body',
'name' => 'logs',
'required' => true,
'schema' => {
'type' => 'array',
'items' => {
'type' => 'string'
}
}
}
]
)
end
end