-
Notifications
You must be signed in to change notification settings - Fork 471
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 300572e
Showing
4 changed files
with
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use_nix |
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,9 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
let | ||
pkgs = import (builtins.fetchTarball { | ||
url = "https://github.com/NixOS/nixpkgs/archive/9957cd48326fe8dbd52fdc50dd2502307f188b0d.tar.gz"; | ||
}) {}; | ||
in | ||
pkgs.mkShell { | ||
nativeBuildInputs = with pkgs.buildPackages; [ pkgs.ruby_3_3 ]; | ||
} |
69 changes: 69 additions & 0 deletions
69
spec/swagger_v2/api_swagger_v2_response_with_models_and_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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'response' do | ||
include_context "#{MODEL_PARSER} swagger example" | ||
|
||
before :all do | ||
module TheApi | ||
class ResponseApiModelsAndPrimitiveTypes < Grape::API | ||
format :json | ||
|
||
desc 'This returns something', | ||
success: [ | ||
{ type: 'Integer', as: :integer_response }, | ||
{ model: Entities::UseResponse, as: :user_response }, | ||
{ type: 'String', as: :string_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::ResponseApiModelsAndPrimitiveTypes | ||
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' }, | ||
'string_response' => { 'type' => 'string' } | ||
} | ||
} | ||
}, | ||
'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 |