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,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#776 multiple presents spec' do
|
6
|
-
include_context "#{MODEL_PARSER} swagger example"
|
7
|
-
|
8
|
-
let(:app) do
|
9
|
-
Class.new(Grape::API) do
|
10
|
-
namespace :issue_776 do
|
11
|
-
desc 'Get multiple presents',
|
12
|
-
success: [
|
13
|
-
{ model: Entities::EnumValues, as: :gender },
|
14
|
-
{ model: Entities::Something, as: :somethings, is_array: true, required: true }
|
15
|
-
]
|
16
|
-
|
17
|
-
get do
|
18
|
-
present :gender, { number: 1, gender: 'Male' }, with: Entities::EnumValues
|
19
|
-
present :somethings, [
|
20
|
-
{ id: 1, text: 'element_1', links: %w[link1 link2] },
|
21
|
-
{ id: 2, text: 'element_2', links: %w[link1 link2] }
|
22
|
-
], with: Entities::Something, is_array: true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
add_swagger_documentation format: :json
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
subject do
|
31
|
-
get '/swagger_doc'
|
32
|
-
JSON.parse(last_response.body)
|
33
|
-
end
|
34
|
-
|
35
|
-
let(:definitions) { subject['definitions'] }
|
36
|
-
let(:schema) { subject['paths']['/issue_776']['get']['responses']['200']['schema'] }
|
37
|
-
|
38
|
-
specify { expect(definitions.keys).to include 'EnumValues', 'Something' }
|
39
|
-
|
40
|
-
specify do
|
41
|
-
expect(schema).to eql({
|
42
|
-
'properties' => {
|
43
|
-
'somethings' => {
|
44
|
-
'items' => {
|
45
|
-
'$ref' => '#/definitions/Something'
|
46
|
-
},
|
47
|
-
'type' => 'array'
|
48
|
-
},
|
49
|
-
'gender' => {
|
50
|
-
'$ref' => '#/definitions/EnumValues'
|
51
|
-
}
|
52
|
-
},
|
53
|
-
'type' => 'object',
|
54
|
-
'required' => [
|
55
|
-
'somethings'
|
56
|
-
]
|
57
|
-
})
|
58
|
-
end
|
59
|
-
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_784 do
|
9
|
-
params do
|
10
|
-
requires :logs, type: String, documentation: { format: 'log', x: { name: 'Log' } }
|
11
|
-
optional :phone_number, type: Integer, documentation: { format: 'phone_number', x: { name: 'PhoneNumber' } }
|
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_784']['post']['parameters'] }
|
29
|
-
|
30
|
-
specify do
|
31
|
-
expect(parameters).to eql(
|
32
|
-
[
|
33
|
-
{ 'in' => 'formData', 'name' => 'logs', 'type' => 'string', 'format' => 'log', 'required' => true, 'x-name' => 'Log' },
|
34
|
-
{ 'in' => 'formData', 'name' => 'phone_number', 'type' => 'integer', 'format' => 'phone_number', 'required' => false, 'x-name' => 'PhoneNumber' }
|
35
|
-
]
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#605 root route documentation' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
resource :grunnbeløp do
|
9
|
-
desc 'returnerer grunnbeløp'
|
10
|
-
get do
|
11
|
-
{ message: 'hello world' }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
resource :εσόδων do
|
16
|
-
desc 'εσόδων'
|
17
|
-
get do
|
18
|
-
{ message: 'hello world' }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
resource :数 do
|
23
|
-
desc '数'
|
24
|
-
get do
|
25
|
-
{ message: 'hello world' }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
resource :amount do
|
30
|
-
desc 'returns amount'
|
31
|
-
get do
|
32
|
-
{ message: 'hello world' }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
resource :👍 do
|
37
|
-
desc 'returns 👍'
|
38
|
-
get do
|
39
|
-
{ message: 'hello world' }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
add_swagger_documentation
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
subject do
|
48
|
-
get '/swagger_doc'
|
49
|
-
JSON.parse(last_response.body)['paths']
|
50
|
-
end
|
51
|
-
|
52
|
-
specify do
|
53
|
-
expect(subject.keys).to match_array ['/grunnbeløp', '/amount', '/εσόδων', '/数']
|
54
|
-
end
|
55
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#832 array of objects with nested Float/BigDecimal fields' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
resource :issue_832 do
|
9
|
-
params do
|
10
|
-
requires :array_param, type: Array do
|
11
|
-
requires :float_param, type: Float
|
12
|
-
requires :big_decimal_param, type: BigDecimal
|
13
|
-
requires :object_param, type: Hash do
|
14
|
-
requires :float_param, type: Float
|
15
|
-
requires :big_decimal_param, type: BigDecimal
|
16
|
-
requires :object_param, type: Hash do
|
17
|
-
requires :float_param, type: Float
|
18
|
-
requires :big_decimal_param, type: BigDecimal
|
19
|
-
requires :array_param, type: Array do
|
20
|
-
requires :integer_param, type: Integer
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
post do
|
27
|
-
{ message: 'hello world' }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
add_swagger_documentation
|
32
|
-
end
|
33
|
-
end
|
34
|
-
let(:parameters) { subject['paths']['/issue_832']['post']['parameters'] }
|
35
|
-
|
36
|
-
subject do
|
37
|
-
get '/swagger_doc'
|
38
|
-
JSON.parse(last_response.body)
|
39
|
-
end
|
40
|
-
|
41
|
-
specify do
|
42
|
-
expect(parameters).to eql(
|
43
|
-
[
|
44
|
-
{
|
45
|
-
'in' => 'formData',
|
46
|
-
'name' => 'array_param[float_param]',
|
47
|
-
'type' => 'array',
|
48
|
-
'required' => true,
|
49
|
-
'items' => {
|
50
|
-
'type' => 'number',
|
51
|
-
'format' => 'float'
|
52
|
-
}
|
53
|
-
}, {
|
54
|
-
'in' => 'formData',
|
55
|
-
'name' => 'array_param[big_decimal_param]',
|
56
|
-
'type' => 'array',
|
57
|
-
'required' => true,
|
58
|
-
'items' => {
|
59
|
-
'type' => 'number',
|
60
|
-
'format' => 'double'
|
61
|
-
}
|
62
|
-
}, {
|
63
|
-
'in' => 'formData',
|
64
|
-
'name' => 'array_param[object_param][float_param]',
|
65
|
-
'type' => 'array',
|
66
|
-
'required' => true,
|
67
|
-
'items' => {
|
68
|
-
'type' => 'number',
|
69
|
-
'format' => 'float'
|
70
|
-
}
|
71
|
-
}, {
|
72
|
-
'in' => 'formData',
|
73
|
-
'name' => 'array_param[object_param][big_decimal_param]',
|
74
|
-
'type' => 'array',
|
75
|
-
'required' => true,
|
76
|
-
'items' => {
|
77
|
-
'type' => 'number',
|
78
|
-
'format' => 'double'
|
79
|
-
}
|
80
|
-
}, {
|
81
|
-
'in' => 'formData',
|
82
|
-
'name' => 'array_param[object_param][object_param][float_param]',
|
83
|
-
'type' => 'array',
|
84
|
-
'required' => true,
|
85
|
-
'items' => {
|
86
|
-
'type' => 'number',
|
87
|
-
'format' => 'float'
|
88
|
-
}
|
89
|
-
}, {
|
90
|
-
'in' => 'formData',
|
91
|
-
'name' => 'array_param[object_param][object_param][big_decimal_param]',
|
92
|
-
'type' => 'array',
|
93
|
-
'required' => true,
|
94
|
-
'items' => {
|
95
|
-
'type' => 'number',
|
96
|
-
'format' => 'double'
|
97
|
-
}
|
98
|
-
}, {
|
99
|
-
'in' => 'formData',
|
100
|
-
'name' => 'array_param[object_param][object_param][array_param][integer_param]',
|
101
|
-
'type' => 'array',
|
102
|
-
'required' => true,
|
103
|
-
'items' => {
|
104
|
-
'type' => 'integer',
|
105
|
-
'format' => 'int32'
|
106
|
-
}
|
107
|
-
}
|
108
|
-
]
|
109
|
-
)
|
110
|
-
end
|
111
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#847 route_param type is included in documentation' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
resource :accounts do
|
9
|
-
route_param :account_number, type: String do
|
10
|
-
resource :records do
|
11
|
-
route_param :id do
|
12
|
-
get do
|
13
|
-
{ message: 'hello world' }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
add_swagger_documentation
|
21
|
-
end
|
22
|
-
end
|
23
|
-
let(:parameters) { subject['paths']['/accounts/{account_number}/records/{id}']['get']['parameters'] }
|
24
|
-
|
25
|
-
subject do
|
26
|
-
get '/swagger_doc'
|
27
|
-
JSON.parse(last_response.body)
|
28
|
-
end
|
29
|
-
|
30
|
-
specify do
|
31
|
-
account_number_param = parameters.find { |param| param['name'] == 'account_number' }
|
32
|
-
expect(account_number_param['type']).to eq 'string'
|
33
|
-
id_param = parameters.find { |param| param['name'] == 'id' }
|
34
|
-
# Default is still integer
|
35
|
-
expect(id_param['type']).to eq 'integer'
|
36
|
-
end
|
37
|
-
end
|
data/spec/lib/data_type_spec.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::DocMethods::DataType do
|
6
|
-
subject { described_class.call(value) }
|
7
|
-
|
8
|
-
describe 'standards' do
|
9
|
-
['Boolean', Date, Integer, String, Float].each do |type|
|
10
|
-
specify do
|
11
|
-
data_type = described_class.call(type: type)
|
12
|
-
expect(data_type).to eql type.to_s.downcase
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'Hash' do
|
18
|
-
let(:value) { { type: Hash } }
|
19
|
-
|
20
|
-
it { is_expected.to eq 'object' }
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'Multi types in a string' do
|
24
|
-
let(:value) { { type: '[String, Integer]' } }
|
25
|
-
|
26
|
-
it { is_expected.to eq 'string' }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'Multi types in a string stating with A' do
|
30
|
-
let(:value) { { type: '[Apple, Orange]' } }
|
31
|
-
|
32
|
-
it { is_expected.to eq 'Apple' }
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'Multi types in array' do
|
36
|
-
let(:value) { { type: [String, Integer] } }
|
37
|
-
|
38
|
-
it { is_expected.to eq 'string' }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'Types in array with entity_name' do
|
42
|
-
before do
|
43
|
-
stub_const 'MyEntity', Class.new
|
44
|
-
allow(MyEntity).to receive(:entity_name).and_return 'MyInteger'
|
45
|
-
end
|
46
|
-
|
47
|
-
let(:value) { { type: '[MyEntity]' } }
|
48
|
-
|
49
|
-
it { is_expected.to eq 'MyInteger' }
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'Types in array with inherited entity_name' do
|
53
|
-
before do
|
54
|
-
stub_const 'EntityBase', Class.new
|
55
|
-
allow(EntityBase).to receive(:entity_name).and_return 'MyInteger'
|
56
|
-
stub_const 'MyEntity', Class.new(EntityBase)
|
57
|
-
end
|
58
|
-
|
59
|
-
let(:value) { { type: '[MyEntity]' } }
|
60
|
-
|
61
|
-
it { is_expected.to eq 'MyInteger' }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe 'Rack::Multipart::UploadedFile' do
|
65
|
-
let(:value) { { type: Rack::Multipart::UploadedFile } }
|
66
|
-
|
67
|
-
it { is_expected.to eq 'file' }
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'Grape::API::Boolean' do
|
71
|
-
let(:value) { { type: Grape::API::Boolean } }
|
72
|
-
|
73
|
-
it { is_expected.to eq 'boolean' }
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'BigDecimal' do
|
77
|
-
let(:value) { { type: BigDecimal } }
|
78
|
-
|
79
|
-
it { is_expected.to eq 'double' }
|
80
|
-
end
|
81
|
-
|
82
|
-
describe 'DateTime' do
|
83
|
-
let(:value) { { type: DateTime } }
|
84
|
-
|
85
|
-
it { is_expected.to eq 'dateTime' }
|
86
|
-
end
|
87
|
-
|
88
|
-
describe 'Numeric' do
|
89
|
-
let(:value) { { type: Numeric } }
|
90
|
-
|
91
|
-
it { is_expected.to eq 'long' }
|
92
|
-
end
|
93
|
-
|
94
|
-
describe 'Symbol' do
|
95
|
-
let(:value) { { type: Symbol } }
|
96
|
-
|
97
|
-
it { is_expected.to eq 'string' }
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '[String]' do
|
101
|
-
let(:value) { { type: '[String]' } }
|
102
|
-
|
103
|
-
it { is_expected.to eq('string') }
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '[Integer]' do
|
107
|
-
let(:value) { { type: '[Integer]' } }
|
108
|
-
|
109
|
-
it { is_expected.to eq('integer') }
|
110
|
-
end
|
111
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe GrapeSwagger::Endpoint::ParamsParser do
|
6
|
-
let(:settings) { {} }
|
7
|
-
let(:params) { [] }
|
8
|
-
let(:endpoint) { nil }
|
9
|
-
|
10
|
-
let(:parser) { described_class.new(params, settings, endpoint) }
|
11
|
-
|
12
|
-
describe '#parse_request_params' do
|
13
|
-
subject(:parse_request_params) { parser.parse_request_params }
|
14
|
-
|
15
|
-
context 'when param is of array type' do
|
16
|
-
let(:params) { [['param_1', { type: 'Array[String]' }]] }
|
17
|
-
|
18
|
-
it 'adds is_array option' do
|
19
|
-
expect(parse_request_params['param_1']).to eq(type: 'Array[String]', is_array: true)
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'and array_use_braces setting set to true' do
|
23
|
-
let(:settings) { { array_use_braces: true } }
|
24
|
-
|
25
|
-
it 'adds braces to the param key' do
|
26
|
-
expect(parse_request_params.keys.first).to eq 'param_1[]'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when param is of simple type' do
|
32
|
-
let(:params) { [['param_1', { type: 'String' }]] }
|
33
|
-
|
34
|
-
it 'does not change options' do
|
35
|
-
expect(parse_request_params['param_1']).to eq(type: 'String')
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'and array_use_braces setting set to true' do
|
39
|
-
let(:settings) { { array_use_braces: true } }
|
40
|
-
|
41
|
-
it 'does not add braces to the param key' do
|
42
|
-
expect(parser.parse_request_params.keys.first).to eq 'param_1'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when param is nested in a param of array type' do
|
48
|
-
let(:params) { [['param_1', { type: 'Array' }], ['param_1[param_2]', { type: 'String' }]] }
|
49
|
-
|
50
|
-
context 'and array_use_braces setting set to true' do
|
51
|
-
let(:settings) { { array_use_braces: true } }
|
52
|
-
|
53
|
-
it 'adds braces to the param key' do
|
54
|
-
expect(parse_request_params.keys.last).to eq 'param_1[param_2]'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'when param is nested in a param of hash type' do
|
60
|
-
let(:params) { [param_1, param_2] }
|
61
|
-
let(:param_1) { ['param_1', { type: 'Hash' }] }
|
62
|
-
let(:param_2) { ['param_1[param_2]', { type: 'String' }] }
|
63
|
-
|
64
|
-
context 'and array_use_braces setting set to true' do
|
65
|
-
let(:settings) { { array_use_braces: true } }
|
66
|
-
|
67
|
-
context 'and param is of simple type' do
|
68
|
-
it 'does not add braces to the param key' do
|
69
|
-
expect(parse_request_params.keys.last).to eq 'param_1[param_2]'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'and param is of array type' do
|
74
|
-
let(:param_2) { ['param_1[param_2]', { type: 'Array[String]' }] }
|
75
|
-
|
76
|
-
it 'adds braces to the param key' do
|
77
|
-
expect(parse_request_params.keys.last).to eq 'param_1[param_2][]'
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'and `param_type` option is set to body' do
|
81
|
-
let(:param_2) do
|
82
|
-
['param_1[param_2]', { type: 'Array[String]', documentation: { param_type: 'body' } }]
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'does not add braces to the param key' do
|
86
|
-
expect(parse_request_params.keys.last).to eq 'param_1[param_2]'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'and `in` option is set to body' do
|
91
|
-
let(:param_2) do
|
92
|
-
['param_1[param_2]', { type: 'Array[String]', documentation: { in: 'body' } }]
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'does not add braces to the param key' do
|
96
|
-
expect(parse_request_params.keys.last).to eq 'param_1[param_2]'
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'and hash `param_type` option is set to body' do
|
101
|
-
let(:param_1) { ['param_1', { type: 'Hash', documentation: { param_type: 'body' } }] }
|
102
|
-
|
103
|
-
it 'does not add braces to the param key' do
|
104
|
-
expect(parse_request_params.keys.last).to eq 'param_1[param_2]'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '#param_type_is_array?' do
|
113
|
-
it 'returns true if the value passed represents an array' do
|
114
|
-
expect(parser.send(:param_type_is_array?, 'Array')).to be_truthy
|
115
|
-
expect(parser.send(:param_type_is_array?, '[String]')).to be_truthy
|
116
|
-
expect(parser.send(:param_type_is_array?, 'Array[Integer]')).to be_truthy
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'returns false if the value passed does not represent an array' do
|
120
|
-
expect(parser.send(:param_type_is_array?, 'String')).to be_falsey
|
121
|
-
expect(parser.send(:param_type_is_array?, '[String, Integer]')).to be_falsey
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/spec/lib/endpoint_spec.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Grape::Endpoint do
|
6
|
-
subject do
|
7
|
-
described_class.new(Grape::Util::InheritableSetting.new, path: '/', method: :get)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '.content_types_for' do
|
11
|
-
describe 'defined on target_class' do
|
12
|
-
let(:own_json) { 'text/own-json' }
|
13
|
-
let(:own_xml) { 'text/own-xml' }
|
14
|
-
let(:content_types) do
|
15
|
-
{
|
16
|
-
own_json: own_json,
|
17
|
-
own_xml: own_xml
|
18
|
-
}
|
19
|
-
end
|
20
|
-
let(:target_class) { OpenStruct.new(content_types: content_types) }
|
21
|
-
|
22
|
-
let(:object) { subject.content_types_for(target_class) }
|
23
|
-
specify do
|
24
|
-
expect(object).to eql [own_json, own_xml]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'not defined' do
|
29
|
-
describe 'format given' do
|
30
|
-
let(:format) { :json }
|
31
|
-
let(:target_class) { OpenStruct.new(format: format) }
|
32
|
-
let(:object) { subject.content_types_for(target_class) }
|
33
|
-
specify do
|
34
|
-
expect(object).to eql ['application/json']
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'format not given' do
|
38
|
-
let(:target_class) { OpenStruct.new }
|
39
|
-
let(:object) { subject.content_types_for(target_class) }
|
40
|
-
|
41
|
-
specify do
|
42
|
-
expect(object).to eql %w[application/xml application/json text/plain]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'parse_request_params' do
|
50
|
-
let(:subject) { GrapeSwagger::Endpoint::ParamsParser }
|
51
|
-
before do
|
52
|
-
subject.send(:parse_request_params, params, {}, nil)
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when params do not contain an array' do
|
56
|
-
let(:params) do
|
57
|
-
[
|
58
|
-
['id', { required: true, type: 'String' }],
|
59
|
-
['description', { required: false, type: 'String' }]
|
60
|
-
]
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:expected_params) do
|
64
|
-
[
|
65
|
-
['id', { required: true, type: 'String' }],
|
66
|
-
['description', { required: false, type: 'String' }]
|
67
|
-
]
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'parses params correctly' do
|
71
|
-
expect(params).to eq expected_params
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'when params contain a simple array' do
|
76
|
-
let(:params) do
|
77
|
-
[
|
78
|
-
['id', { required: true, type: 'String' }],
|
79
|
-
['description', { required: false, type: 'String' }],
|
80
|
-
['stuffs', { required: true, type: 'Array[String]' }]
|
81
|
-
]
|
82
|
-
end
|
83
|
-
|
84
|
-
let(:expected_params) do
|
85
|
-
[
|
86
|
-
['id', { required: true, type: 'String' }],
|
87
|
-
['description', { required: false, type: 'String' }],
|
88
|
-
['stuffs', { required: true, type: 'Array[String]', is_array: true }]
|
89
|
-
]
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'parses params correctly and adds is_array to the array' do
|
93
|
-
expect(params).to eq expected_params
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when params contain a complex array' do
|
98
|
-
let(:params) do
|
99
|
-
[
|
100
|
-
['id', { required: true, type: 'String' }],
|
101
|
-
['description', { required: false, type: 'String' }],
|
102
|
-
['stuffs', { required: true, type: 'Array' }],
|
103
|
-
['stuffs[id]', { required: true, type: 'String' }]
|
104
|
-
]
|
105
|
-
end
|
106
|
-
|
107
|
-
let(:expected_params) do
|
108
|
-
[
|
109
|
-
['id', { required: true, type: 'String' }],
|
110
|
-
['description', { required: false, type: 'String' }],
|
111
|
-
['stuffs', { required: true, type: 'Array', is_array: true }],
|
112
|
-
['stuffs[id]', { required: true, type: 'String' }]
|
113
|
-
]
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'parses params correctly and adds is_array to the array and all elements' do
|
117
|
-
expect(params).to eq expected_params
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when array params are not contiguous with parent array' do
|
121
|
-
let(:params) do
|
122
|
-
[
|
123
|
-
['id', { required: true, type: 'String' }],
|
124
|
-
['description', { required: false, type: 'String' }],
|
125
|
-
['stuffs', { required: true, type: 'Array' }],
|
126
|
-
['stuffs[owners]', { required: true, type: 'Array' }],
|
127
|
-
['stuffs[creators]', { required: true, type: 'Array' }],
|
128
|
-
['stuffs[owners][id]', { required: true, type: 'String' }],
|
129
|
-
['stuffs[creators][id]', { required: true, type: 'String' }],
|
130
|
-
['stuffs_and_things', { required: true, type: 'String' }]
|
131
|
-
]
|
132
|
-
end
|
133
|
-
|
134
|
-
let(:expected_params) do
|
135
|
-
[
|
136
|
-
['id', { required: true, type: 'String' }],
|
137
|
-
['description', { required: false, type: 'String' }],
|
138
|
-
['stuffs', { required: true, type: 'Array', is_array: true }],
|
139
|
-
['stuffs[owners]', { required: true, type: 'Array', is_array: true }],
|
140
|
-
['stuffs[creators]', { required: true, type: 'Array', is_array: true }],
|
141
|
-
['stuffs[owners][id]', { required: true, type: 'String' }],
|
142
|
-
['stuffs[creators][id]', { required: true, type: 'String' }],
|
143
|
-
['stuffs_and_things', { required: true, type: 'String' }]
|
144
|
-
]
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'parses params correctly and adds is_array to the array and all elements' do
|
148
|
-
expect(params).to eq expected_params
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|