-
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.
WIP: Add support for primitive data types in responses
- Loading branch information
1 parent
ecafd1f
commit 129e7d7
Showing
2 changed files
with
84 additions
and
2 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
67 changes: 67 additions & 0 deletions
67
spec/swagger_v2/api_swagger_v2_response_with_primitive_types_spec.rb
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,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'response' do | ||
include_context "#{MODEL_PARSER} swagger example" | ||
|
||
before :all do | ||
module TheApi | ||
class ResponseApiModels < Grape::API | ||
format :json | ||
|
||
desc 'This returns something', | ||
success: [ | ||
{ model: Entities::UseResponse, as: :user_response }, | ||
{ type: 'Integer', as: :integer_response } | ||
], | ||
failure: [ | ||
{ code: 400, message: 'NotFound', model: '' }, | ||
{ code: 404, message: 'BadRequest', model: Entities::ApiError } | ||
], | ||
default_response: { message: 'Error', model: Entities::ApiError } | ||
get '/use-response' do | ||
{ 'declared_params' => declared(params) } | ||
end | ||
|
||
add_swagger_documentation | ||
end | ||
end | ||
end | ||
|
||
def app | ||
TheApi::ResponseApiModels | ||
end | ||
|
||
describe 'uses entity as response object implicitly with route name' do | ||
subject do | ||
get '/swagger_doc/use-response' | ||
JSON.parse(last_response.body) | ||
end | ||
|
||
specify do | ||
expect(subject['paths']['/use-response']['get']).to eql( | ||
'description' => 'This returns something', | ||
'produces' => ['application/json'], | ||
'responses' => { | ||
'200' => { | ||
'description' => 'This returns something', | ||
'schema' => { | ||
'type' => 'object', | ||
'properties' => { | ||
'user_response' => { '$ref' => '#/definitions/UseResponse' }, | ||
'integer_response' => { 'type' => 'integer' } | ||
} | ||
} | ||
}, | ||
'400' => { 'description' => 'NotFound' }, | ||
'404' => { 'description' => 'BadRequest', 'schema' => { '$ref' => '#/definitions/ApiError' } }, | ||
'default' => { 'description' => 'Error', 'schema' => { '$ref' => '#/definitions/ApiError' } } | ||
}, | ||
'tags' => ['use-response'], | ||
'operationId' => 'getUseResponse' | ||
) | ||
expect(subject['definitions']).to eql(swagger_entity_as_response_object) | ||
end | ||
end | ||
end |