grape-swagger 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +6 -5
- data/grape-swagger.gemspec +5 -5
- data/lib/grape-swagger/doc_methods/extensions.rb +2 -1
- data/lib/grape-swagger/doc_methods/format_data.rb +2 -2
- data/lib/grape-swagger/doc_methods/move_params.rb +1 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +1 -1
- data/lib/grape-swagger/endpoint.rb +1 -1
- data/lib/grape-swagger/version.rb +1 -1
- metadata +26 -129
- data/.coveralls.yml +0 -1
- data/.github/dependabot.yml +0 -20
- data/.github/workflows/ci.yml +0 -45
- data/.gitignore +0 -45
- data/.rspec +0 -3
- data/.rubocop.yml +0 -136
- data/.rubocop_todo.yml +0 -60
- data/Dangerfile +0 -3
- data/Gemfile +0 -43
- data/Rakefile +0 -20
- data/example/api/endpoints.rb +0 -131
- data/example/api/entities.rb +0 -18
- data/example/config.ru +0 -42
- data/example/example_requests.postman_collection +0 -146
- data/example/splines.png +0 -0
- data/example/swagger-example.png +0 -0
- data/spec/issues/267_nested_namespaces.rb +0 -55
- data/spec/issues/403_versions_spec.rb +0 -124
- data/spec/issues/427_entity_as_string_spec.rb +0 -39
- data/spec/issues/430_entity_definitions_spec.rb +0 -94
- data/spec/issues/532_allow_custom_format_spec.rb +0 -38
- data/spec/issues/533_specify_status_code_spec.rb +0 -78
- data/spec/issues/537_enum_values_spec.rb +0 -50
- data/spec/issues/539_array_post_body_spec.rb +0 -65
- data/spec/issues/542_array_of_type_in_post_body_spec.rb +0 -46
- data/spec/issues/553_align_array_put_post_params_spec.rb +0 -144
- data/spec/issues/572_array_post_body_spec.rb +0 -51
- data/spec/issues/579_align_put_post_parameters_spec.rb +0 -179
- data/spec/issues/582_file_response_spec.rb +0 -55
- data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +0 -26
- data/spec/issues/605_root_route_documentation_spec.rb +0 -23
- data/spec/issues/650_params_array_spec.rb +0 -59
- data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +0 -100
- data/spec/issues/680_keep_204_error_schemas_spec.rb +0 -55
- data/spec/issues/751_deeply_nested_objects_spec.rb +0 -190
- data/spec/issues/776_multiple_presents_spec.rb +0 -59
- data/spec/issues/784_extensions_on_params_spec.rb +0 -38
- data/spec/issues/809_utf8_routes_spec.rb +0 -55
- data/spec/issues/832_array_hash_float_decimal_spec.rb +0 -111
- data/spec/issues/847_route_param_options_spec.rb +0 -37
- data/spec/lib/data_type_spec.rb +0 -111
- data/spec/lib/endpoint/params_parser_spec.rb +0 -124
- data/spec/lib/endpoint_spec.rb +0 -153
- data/spec/lib/extensions_spec.rb +0 -185
- data/spec/lib/format_data_spec.rb +0 -115
- data/spec/lib/model_parsers_spec.rb +0 -104
- data/spec/lib/move_params_spec.rb +0 -444
- data/spec/lib/oapi_tasks_spec.rb +0 -163
- data/spec/lib/operation_id_spec.rb +0 -55
- data/spec/lib/optional_object_spec.rb +0 -47
- data/spec/lib/parse_params_spec.rb +0 -68
- data/spec/lib/path_string_spec.rb +0 -101
- data/spec/lib/produces_consumes_spec.rb +0 -116
- data/spec/lib/tag_name_description_spec.rb +0 -80
- data/spec/lib/version_spec.rb +0 -28
- data/spec/spec_helper.rb +0 -39
- data/spec/support/empty_model_parser.rb +0 -23
- data/spec/support/grape_version.rb +0 -13
- data/spec/support/mock_parser.rb +0 -23
- data/spec/support/model_parsers/entity_parser.rb +0 -334
- data/spec/support/model_parsers/mock_parser.rb +0 -346
- data/spec/support/model_parsers/representable_parser.rb +0 -406
- data/spec/support/namespace_tags.rb +0 -93
- data/spec/support/the_paths_definitions.rb +0 -109
- data/spec/swagger_v2/api_documentation_spec.rb +0 -28
- data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +0 -83
- data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +0 -48
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +0 -36
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +0 -79
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +0 -145
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +0 -137
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +0 -56
- data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +0 -64
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +0 -58
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +0 -57
- data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +0 -103
- data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +0 -48
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +0 -145
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +0 -355
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +0 -217
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +0 -239
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +0 -72
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +0 -143
- data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +0 -135
- data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +0 -216
- data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +0 -55
- data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +0 -153
- data/spec/swagger_v2/api_swagger_v2_spec.rb +0 -237
- data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +0 -93
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +0 -89
- data/spec/swagger_v2/boolean_params_spec.rb +0 -35
- data/spec/swagger_v2/default_api_spec.rb +0 -175
- data/spec/swagger_v2/deprecated_field_spec.rb +0 -25
- data/spec/swagger_v2/description_not_initialized_spec.rb +0 -39
- data/spec/swagger_v2/endpoint_versioned_path_spec.rb +0 -130
- data/spec/swagger_v2/errors_spec.rb +0 -77
- data/spec/swagger_v2/float_api_spec.rb +0 -33
- data/spec/swagger_v2/form_params_spec.rb +0 -67
- data/spec/swagger_v2/grape-swagger_spec.rb +0 -17
- data/spec/swagger_v2/guarded_endpoint_spec.rb +0 -162
- data/spec/swagger_v2/hide_api_spec.rb +0 -147
- data/spec/swagger_v2/host_spec.rb +0 -43
- data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +0 -57
- data/spec/swagger_v2/mount_override_api_spec.rb +0 -58
- data/spec/swagger_v2/mounted_target_class_spec.rb +0 -76
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +0 -122
- data/spec/swagger_v2/namespace_tags_spec.rb +0 -78
- data/spec/swagger_v2/namespaced_api_spec.rb +0 -121
- data/spec/swagger_v2/nicknamed_api_spec.rb +0 -25
- data/spec/swagger_v2/operation_id_api_spec.rb +0 -27
- data/spec/swagger_v2/param_multi_type_spec.rb +0 -77
- data/spec/swagger_v2/param_type_spec.rb +0 -87
- data/spec/swagger_v2/param_values_spec.rb +0 -162
- data/spec/swagger_v2/params_array_collection_format_spec.rb +0 -105
- data/spec/swagger_v2/params_array_spec.rb +0 -203
- data/spec/swagger_v2/params_example_spec.rb +0 -40
- data/spec/swagger_v2/params_hash_spec.rb +0 -71
- data/spec/swagger_v2/params_nested_spec.rb +0 -86
- data/spec/swagger_v2/parent_less_namespace_spec.rb +0 -32
- data/spec/swagger_v2/reference_entity_spec.rb +0 -129
- data/spec/swagger_v2/security_requirement_spec.rb +0 -46
- data/spec/swagger_v2/simple_mounted_api_spec.rb +0 -326
- data/spec/version_spec.rb +0 -10
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'definition names' do
|
6
|
-
before :all do
|
7
|
-
module TestDefinition
|
8
|
-
module DummyEntities
|
9
|
-
module WithVeryLongName
|
10
|
-
module AnotherGroupingModule
|
11
|
-
class Class1
|
12
|
-
class Entity < Grape::Entity
|
13
|
-
expose :first_thing
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Class2
|
18
|
-
class Entities < Grape::Entity
|
19
|
-
expose :second_thing
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Class3
|
24
|
-
class Entity < Grape::Entity
|
25
|
-
expose :third_thing
|
26
|
-
|
27
|
-
def self.entity_name
|
28
|
-
'FooKlass'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Class4
|
34
|
-
class FourthEntity < Grape::Entity
|
35
|
-
expose :fourth_thing
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class Class5
|
40
|
-
class FithEntity < Class4::FourthEntity
|
41
|
-
expose :fith_thing
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Class6
|
46
|
-
class SixthEntity < Grape::Entity
|
47
|
-
expose :sixth_thing
|
48
|
-
|
49
|
-
def self.entity_name
|
50
|
-
'BarKlass'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Class7
|
56
|
-
class SeventhEntity < Class6::SixthEntity
|
57
|
-
expose :seventh_thing
|
58
|
-
|
59
|
-
private_class_method :entity_name
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class NameApi < Grape::API
|
67
|
-
add_swagger_documentation models: [
|
68
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class1::Entity,
|
69
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class2::Entities,
|
70
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class3::Entity,
|
71
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class4::FourthEntity,
|
72
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity,
|
73
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class6::SixthEntity,
|
74
|
-
DummyEntities::WithVeryLongName::AnotherGroupingModule::Class7::SeventhEntity
|
75
|
-
]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
let(:app) { TestDefinition::NameApi }
|
81
|
-
|
82
|
-
subject do
|
83
|
-
get '/swagger_doc'
|
84
|
-
JSON.parse(last_response.body)['definitions']
|
85
|
-
end
|
86
|
-
|
87
|
-
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class1' }
|
88
|
-
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class2' }
|
89
|
-
specify { expect(subject).to include 'FooKlass' }
|
90
|
-
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class4_FourthEntity' }
|
91
|
-
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class5_FithEntity' }
|
92
|
-
specify { expect(subject).to include 'BarKlass' }
|
93
|
-
specify { expect(subject).to include 'TestDefinition_DummyEntities_WithVeryLongName_AnotherGroupingModule_Class7_SeventhEntity' }
|
94
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#532 allow custom format' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :issue_532 do
|
9
|
-
params do
|
10
|
-
requires :logs, type: String, documentation: { format: 'log' }
|
11
|
-
optional :phone_number, type: Integer, documentation: { format: 'phone_number' }
|
12
|
-
end
|
13
|
-
|
14
|
-
post do
|
15
|
-
present params
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
add_swagger_documentation format: :json
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
subject do
|
24
|
-
get '/swagger_doc'
|
25
|
-
JSON.parse(last_response.body)
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:parameters) { subject['paths']['/issue_532']['post']['parameters'] }
|
29
|
-
|
30
|
-
specify do
|
31
|
-
expect(parameters).to eql(
|
32
|
-
[
|
33
|
-
{ 'in' => 'formData', 'name' => 'logs', 'type' => 'string', 'format' => 'log', 'required' => true },
|
34
|
-
{ 'in' => 'formData', 'name' => 'phone_number', 'type' => 'integer', 'format' => 'phone_number', 'required' => false }
|
35
|
-
]
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#533 specify status codes' do
|
6
|
-
include_context "#{MODEL_PARSER} swagger example"
|
7
|
-
|
8
|
-
let(:app) do
|
9
|
-
Class.new(Grape::API) do
|
10
|
-
namespace :issue_533 do
|
11
|
-
desc 'Get a list of stuff',
|
12
|
-
success: { code: 202, model: Entities::UseResponse, message: 'a changed status code' }
|
13
|
-
get do
|
14
|
-
status 202
|
15
|
-
{ foo: 'that is the response' }
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'Post some stuff',
|
19
|
-
success: { code: 202, model: Entities::UseResponse, message: 'a changed status code' }
|
20
|
-
post do
|
21
|
-
status 202
|
22
|
-
{ foo: 'that is the response' }
|
23
|
-
end
|
24
|
-
|
25
|
-
desc 'Post some stuff',
|
26
|
-
success: { code: 204, message: 'a changed status code' }
|
27
|
-
patch do
|
28
|
-
status 204
|
29
|
-
end
|
30
|
-
|
31
|
-
desc 'Delete some stuff',
|
32
|
-
success: { code: 203 }
|
33
|
-
delete do
|
34
|
-
status 203
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
add_swagger_documentation format: :json
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
subject do
|
43
|
-
get '/swagger_doc'
|
44
|
-
JSON.parse(last_response.body)['paths']['/issue_533']
|
45
|
-
end
|
46
|
-
|
47
|
-
let(:get_response) { get '/issue_533' }
|
48
|
-
specify { expect(get_response.status).to eql 202 }
|
49
|
-
let(:get_response_documentation) { subject['get']['responses'] }
|
50
|
-
specify do
|
51
|
-
expect(get_response_documentation.keys.first).to eql '202'
|
52
|
-
expect(get_response_documentation['202']).to include 'schema'
|
53
|
-
end
|
54
|
-
|
55
|
-
let(:post_response) { post '/issue_533' }
|
56
|
-
specify { expect(post_response.status).to eql 202 }
|
57
|
-
let(:post_response_documentation) { subject['post']['responses'] }
|
58
|
-
specify do
|
59
|
-
expect(post_response_documentation.keys.first).to eql '202'
|
60
|
-
expect(post_response_documentation['202']).to include 'schema'
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:patch_response) { patch '/issue_533' }
|
64
|
-
specify { expect(patch_response.status).to eql 204 }
|
65
|
-
let(:patch_response_documentation) { subject['patch']['responses'] }
|
66
|
-
specify do
|
67
|
-
expect(patch_response_documentation.keys.first).to eql '204'
|
68
|
-
expect(patch_response_documentation['204']).not_to include 'schema'
|
69
|
-
end
|
70
|
-
|
71
|
-
let(:delete_response) { delete '/issue_533' }
|
72
|
-
specify { expect(delete_response.status).to eql 203 }
|
73
|
-
let(:delete_response_documentation) { subject['delete']['responses'] }
|
74
|
-
specify do
|
75
|
-
expect(delete_response_documentation.keys.first).to eql '203'
|
76
|
-
expect(delete_response_documentation['203']).not_to include 'schema'
|
77
|
-
end
|
78
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#537 enum values spec' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :issue_537 do
|
9
|
-
class Spec < Grape::Entity
|
10
|
-
expose :enum_property, documentation: { values: %i[foo bar] }
|
11
|
-
expose :enum_property_default, documentation: { values: %w[a b c], default: 'c' }
|
12
|
-
expose :own_format, documentation: { format: 'log' }
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'create account',
|
16
|
-
success: Spec
|
17
|
-
get do
|
18
|
-
{ message: 'hi' }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
add_swagger_documentation format: :json
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
subject do
|
27
|
-
get '/swagger_doc'
|
28
|
-
JSON.parse(last_response.body)
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:property) { subject['definitions']['Spec']['properties']['enum_property'] }
|
32
|
-
specify do
|
33
|
-
expect(property).to include 'enum'
|
34
|
-
expect(property['enum']).to eql %w[foo bar]
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:property_default) { subject['definitions']['Spec']['properties']['enum_property_default'] }
|
38
|
-
specify do
|
39
|
-
expect(property_default).to include 'enum'
|
40
|
-
expect(property_default['enum']).to eql %w[a b c]
|
41
|
-
expect(property_default).to include 'default'
|
42
|
-
expect(property_default['default']).to eql 'c'
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:own_format) { subject['definitions']['Spec']['properties']['own_format'] }
|
46
|
-
specify do
|
47
|
-
expect(own_format).to include 'format'
|
48
|
-
expect(own_format['format']).to eql 'log'
|
49
|
-
end
|
50
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#539 post params given as array' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :issue_539 do
|
9
|
-
class Element < Grape::Entity
|
10
|
-
expose :id
|
11
|
-
expose :description
|
12
|
-
expose :role
|
13
|
-
end
|
14
|
-
|
15
|
-
class ArrayOfElements < Grape::Entity
|
16
|
-
expose :elements,
|
17
|
-
documentation: {
|
18
|
-
type: Element, is_array: true, param_type: 'body', required: true
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'create account',
|
23
|
-
params: ArrayOfElements.documentation
|
24
|
-
post do
|
25
|
-
present params
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
add_swagger_documentation format: :json
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
subject do
|
34
|
-
get '/swagger_doc'
|
35
|
-
JSON.parse(last_response.body)
|
36
|
-
end
|
37
|
-
|
38
|
-
let(:parameters) { subject['paths']['/issue_539']['post']['parameters'] }
|
39
|
-
let(:definitions) { subject['definitions'] }
|
40
|
-
|
41
|
-
specify do
|
42
|
-
expect(parameters).to eql(
|
43
|
-
[
|
44
|
-
{
|
45
|
-
'in' => 'body', 'name' => 'elements', 'required' => true, 'schema' => {
|
46
|
-
'type' => 'array', 'items' => { '$ref' => '#/definitions/Element' }
|
47
|
-
}
|
48
|
-
}
|
49
|
-
]
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
specify do
|
54
|
-
expect(definitions).to eql(
|
55
|
-
'Element' => {
|
56
|
-
'type' => 'object',
|
57
|
-
'properties' => {
|
58
|
-
'id' => { 'type' => 'string' },
|
59
|
-
'description' => { 'type' => 'string' },
|
60
|
-
'role' => { 'type' => 'string' }
|
61
|
-
}
|
62
|
-
}
|
63
|
-
)
|
64
|
-
end
|
65
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#542 array of type in post params' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :issue_542 do
|
9
|
-
params do
|
10
|
-
requires :logs, type: Array[String], documentation: { param_type: 'body' }
|
11
|
-
end
|
12
|
-
|
13
|
-
post do
|
14
|
-
present params
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
add_swagger_documentation format: :json
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
subject do
|
23
|
-
get '/swagger_doc'
|
24
|
-
JSON.parse(last_response.body)
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:parameters) { subject['paths']['/issue_542']['post']['parameters'] }
|
28
|
-
|
29
|
-
specify do
|
30
|
-
expect(parameters).to eql(
|
31
|
-
[
|
32
|
-
{
|
33
|
-
'in' => 'body',
|
34
|
-
'name' => 'logs',
|
35
|
-
'required' => true,
|
36
|
-
'schema' => {
|
37
|
-
'type' => 'array',
|
38
|
-
'items' => {
|
39
|
-
'type' => 'string'
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
]
|
44
|
-
)
|
45
|
-
end
|
46
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#553 array of type in post/put params' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :in_form_data do
|
9
|
-
desc 'create foo'
|
10
|
-
params do
|
11
|
-
requires :guid, type: Array[String]
|
12
|
-
end
|
13
|
-
post do
|
14
|
-
# your code goes here
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'put specific foo'
|
18
|
-
params do
|
19
|
-
requires :id
|
20
|
-
requires :guid, type: Array[String]
|
21
|
-
end
|
22
|
-
put ':id' do
|
23
|
-
# your code goes here
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
namespace :in_body do
|
28
|
-
desc 'create foo'
|
29
|
-
params do
|
30
|
-
requires :guid, type: Array[String], documentation: { param_type: 'body' }
|
31
|
-
end
|
32
|
-
post do
|
33
|
-
# your code goes here
|
34
|
-
end
|
35
|
-
|
36
|
-
desc 'put specific foo'
|
37
|
-
params do
|
38
|
-
requires :id
|
39
|
-
requires :guid, type: Array[String], documentation: { param_type: 'body' }
|
40
|
-
end
|
41
|
-
put ':id' do
|
42
|
-
# your code goes here
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
add_swagger_documentation format: :json
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
subject do
|
51
|
-
get '/swagger_doc'
|
52
|
-
JSON.parse(last_response.body)
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'type for Array specified' do
|
56
|
-
describe 'in formData' do
|
57
|
-
describe 'post request' do
|
58
|
-
let(:params) { subject['paths']['/in_form_data']['post']['parameters'] }
|
59
|
-
|
60
|
-
specify do
|
61
|
-
expect(params).to eql([{
|
62
|
-
'in' => 'formData',
|
63
|
-
'name' => 'guid',
|
64
|
-
'type' => 'array',
|
65
|
-
'items' => { 'type' => 'string' },
|
66
|
-
'required' => true
|
67
|
-
}])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'put request' do
|
72
|
-
let(:params) { subject['paths']['/in_form_data/{id}']['put']['parameters'] }
|
73
|
-
|
74
|
-
specify do
|
75
|
-
expect(params).to eql(
|
76
|
-
[
|
77
|
-
{
|
78
|
-
'in' => 'path',
|
79
|
-
'name' => 'id',
|
80
|
-
'type' => 'string',
|
81
|
-
'required' => true
|
82
|
-
},
|
83
|
-
{
|
84
|
-
'in' => 'formData',
|
85
|
-
'name' => 'guid',
|
86
|
-
'type' => 'array',
|
87
|
-
'items' => { 'type' => 'string' },
|
88
|
-
'required' => true
|
89
|
-
}
|
90
|
-
]
|
91
|
-
)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'in body' do
|
97
|
-
describe 'post request' do
|
98
|
-
let(:params) { subject['paths']['/in_body']['post']['parameters'] }
|
99
|
-
|
100
|
-
specify do
|
101
|
-
expect(params).to eql(
|
102
|
-
[
|
103
|
-
{
|
104
|
-
'in' => 'body',
|
105
|
-
'name' => 'guid',
|
106
|
-
'required' => true,
|
107
|
-
'schema' => {
|
108
|
-
'type' => 'array',
|
109
|
-
'items' => { 'type' => 'string' }
|
110
|
-
}
|
111
|
-
}
|
112
|
-
]
|
113
|
-
)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'put request' do
|
118
|
-
let(:params) { subject['paths']['/in_body/{id}']['put']['parameters'] }
|
119
|
-
|
120
|
-
specify do
|
121
|
-
expect(params).to eql(
|
122
|
-
[
|
123
|
-
{
|
124
|
-
'in' => 'path',
|
125
|
-
'name' => 'id',
|
126
|
-
'type' => 'string',
|
127
|
-
'required' => true
|
128
|
-
},
|
129
|
-
{
|
130
|
-
'in' => 'body',
|
131
|
-
'name' => 'guid',
|
132
|
-
'required' => true,
|
133
|
-
'schema' => {
|
134
|
-
'type' => 'array',
|
135
|
-
'items' => { 'type' => 'string' }
|
136
|
-
}
|
137
|
-
}
|
138
|
-
]
|
139
|
-
)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#572 is_array is applied to all possible responses' do
|
6
|
-
include_context "#{MODEL_PARSER} swagger example"
|
7
|
-
|
8
|
-
let(:app) do
|
9
|
-
Class.new(Grape::API) do
|
10
|
-
namespace :issue_572 do
|
11
|
-
desc 'get issue',
|
12
|
-
is_array: true,
|
13
|
-
success: Entities::UseResponse,
|
14
|
-
failure: [
|
15
|
-
[401, 'BadKittenError', Entities::ApiError],
|
16
|
-
[404, 'NoTreatsError', Entities::ApiError],
|
17
|
-
[429, 'TooManyScratchesError', Entities::ApiError]
|
18
|
-
]
|
19
|
-
|
20
|
-
get
|
21
|
-
end
|
22
|
-
|
23
|
-
add_swagger_documentation format: :json
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
subject do
|
28
|
-
get '/swagger_doc'
|
29
|
-
JSON.parse(last_response.body)
|
30
|
-
end
|
31
|
-
|
32
|
-
let(:codes) { %w[200 401 404 429] }
|
33
|
-
|
34
|
-
let(:responses) { subject['paths']['/issue_572']['get']['responses'] }
|
35
|
-
|
36
|
-
specify { expect(responses.keys.sort).to eq codes }
|
37
|
-
|
38
|
-
specify do
|
39
|
-
expect(responses['200']['schema']).to include 'type'
|
40
|
-
expect(responses['200']['schema']['type']).to eql 'array'
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'no array types' do
|
44
|
-
specify do
|
45
|
-
codes[1..-1].each do |code|
|
46
|
-
expect(responses[code]['schema']).not_to include 'type'
|
47
|
-
expect(responses[code]['schema'].keys).to eql ['$ref']
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|