-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue 539: corrects exposing of array in post body
- updates README - adds changelog entry
- Loading branch information
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'spec_helper' | ||
require 'grape-entity' | ||
require 'grape-swagger-entity' | ||
|
||
describe '#427 nested entity given as string' do | ||
let(:app) do | ||
Class.new(Grape::API) do | ||
namespace :issue_427 do | ||
class Element < Grape::Entity | ||
expose :id | ||
expose :description | ||
expose :role | ||
end | ||
|
||
class ArrayOfElements < Grape::Entity | ||
expose :elements, | ||
documentation: { | ||
type: ::Element, is_array: true, param_type: 'body', required: true | ||
} | ||
end | ||
|
||
desc 'create account', | ||
params: ArrayOfElements.documentation | ||
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_427']['post']['parameters'] } | ||
let(:definitions) { subject['definitions'] } | ||
|
||
specify do | ||
expect(parameters).to eql( | ||
[ | ||
{ | ||
'in' => 'body', 'name' => 'elements', 'required' => true, 'schema' => { | ||
'type' => 'array', 'items' => { '$ref' => '#/definitions/Element' } | ||
} | ||
} | ||
] | ||
) | ||
|
||
expect(definitions).to eql( | ||
'Element' => { | ||
'type' => 'object', | ||
'properties' => { | ||
'id' => { 'type' => 'string' }, | ||
'description' => { 'type' => 'string' }, | ||
'role' => { 'type' => 'string' } | ||
} | ||
} | ||
) | ||
end | ||
end |