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,179 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#579 put / post parameters spec' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :issue_579 do
|
9
|
-
class BodySpec < Grape::Entity
|
10
|
-
expose :guid, documentation: { type: String, format: 'guid', in: 'body' }
|
11
|
-
expose :name, documentation: { type: String, in: 'body' }
|
12
|
-
expose :content, documentation: { type: String, in: 'body' }
|
13
|
-
end
|
14
|
-
|
15
|
-
class Spec < Grape::Entity
|
16
|
-
expose :guid, documentation: { type: String, format: 'guid' }
|
17
|
-
expose :name, documentation: { type: String }
|
18
|
-
expose :content, documentation: { type: String }
|
19
|
-
end
|
20
|
-
|
21
|
-
namespace :implicit do
|
22
|
-
namespace :body_parameter do
|
23
|
-
desc 'update spec',
|
24
|
-
success: BodySpec,
|
25
|
-
params: BodySpec.documentation
|
26
|
-
put ':guid' do
|
27
|
-
# your code goes here
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
namespace :form_parameter do
|
32
|
-
desc 'update spec',
|
33
|
-
success: Spec,
|
34
|
-
params: Spec.documentation
|
35
|
-
put ':guid' do
|
36
|
-
# your code goes here
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
namespace :explicit do
|
42
|
-
namespace :body_parameter do
|
43
|
-
desc 'update spec',
|
44
|
-
success: BodySpec,
|
45
|
-
params: BodySpec.documentation
|
46
|
-
params do
|
47
|
-
requires :guid
|
48
|
-
end
|
49
|
-
put ':guid' do
|
50
|
-
# your code goes here
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
namespace :form_parameter do
|
55
|
-
desc 'update spec',
|
56
|
-
success: Spec,
|
57
|
-
params: Spec.documentation
|
58
|
-
params do
|
59
|
-
requires :guid
|
60
|
-
end
|
61
|
-
put ':guid' do
|
62
|
-
# your code goes here
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
namespace :namespace_param do
|
68
|
-
route_param :guid do
|
69
|
-
namespace :body_parameter do
|
70
|
-
desc 'update spec',
|
71
|
-
success: BodySpec,
|
72
|
-
params: BodySpec.documentation
|
73
|
-
put do
|
74
|
-
# your code goes here
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
namespace :form_parameter do
|
79
|
-
desc 'update spec',
|
80
|
-
success: Spec,
|
81
|
-
params: Spec.documentation
|
82
|
-
put do
|
83
|
-
# your code goes here
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
add_swagger_documentation format: :json
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
subject do
|
95
|
-
get '/swagger_doc'
|
96
|
-
JSON.parse(last_response.body)
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'implicit path param given' do
|
100
|
-
let(:body_parameters) { subject['paths']['/issue_579/implicit/body_parameter/{guid}']['put']['parameters'] }
|
101
|
-
specify do
|
102
|
-
expect(body_parameters).to eql(
|
103
|
-
[
|
104
|
-
{ 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
|
105
|
-
{
|
106
|
-
'name' => 'putIssue579ImplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
|
107
|
-
'$ref' => '#/definitions/putIssue579ImplicitBodyParameterGuid'
|
108
|
-
}
|
109
|
-
}
|
110
|
-
]
|
111
|
-
)
|
112
|
-
end
|
113
|
-
|
114
|
-
let(:form_parameters) { subject['paths']['/issue_579/implicit/form_parameter/{guid}']['put']['parameters'] }
|
115
|
-
specify do
|
116
|
-
expect(form_parameters).to eql(
|
117
|
-
[
|
118
|
-
{ 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
|
119
|
-
{ 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
|
120
|
-
{ 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
|
121
|
-
]
|
122
|
-
)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe 'explicit path param given' do
|
127
|
-
let(:body_parameters) { subject['paths']['/issue_579/explicit/body_parameter/{guid}']['put']['parameters'] }
|
128
|
-
specify do
|
129
|
-
expect(body_parameters).to eql(
|
130
|
-
[
|
131
|
-
{ 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
|
132
|
-
{
|
133
|
-
'name' => 'putIssue579ExplicitBodyParameterGuid', 'in' => 'body', 'required' => true, 'schema' => {
|
134
|
-
'$ref' => '#/definitions/putIssue579ExplicitBodyParameterGuid'
|
135
|
-
}
|
136
|
-
}
|
137
|
-
]
|
138
|
-
)
|
139
|
-
end
|
140
|
-
|
141
|
-
let(:form_parameters) { subject['paths']['/issue_579/explicit/form_parameter/{guid}']['put']['parameters'] }
|
142
|
-
specify do
|
143
|
-
expect(form_parameters).to eql(
|
144
|
-
[
|
145
|
-
{ 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
|
146
|
-
{ 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
|
147
|
-
{ 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
|
148
|
-
]
|
149
|
-
)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe 'explicit as route param given' do
|
154
|
-
let(:body_parameters) { subject['paths']['/issue_579/namespace_param/{guid}/body_parameter']['put']['parameters'] }
|
155
|
-
specify do
|
156
|
-
expect(body_parameters).to eql(
|
157
|
-
[
|
158
|
-
{ 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
|
159
|
-
{
|
160
|
-
'name' => 'putIssue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
|
161
|
-
'$ref' => '#/definitions/putIssue579NamespaceParamGuidBodyParameter'
|
162
|
-
}
|
163
|
-
}
|
164
|
-
]
|
165
|
-
)
|
166
|
-
end
|
167
|
-
|
168
|
-
let(:form_parameters) { subject['paths']['/issue_579/namespace_param/{guid}/form_parameter']['put']['parameters'] }
|
169
|
-
specify do
|
170
|
-
expect(form_parameters).to eql(
|
171
|
-
[
|
172
|
-
{ 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
|
173
|
-
{ 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
|
174
|
-
{ 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
|
175
|
-
]
|
176
|
-
)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#582 respond with a file' do
|
6
|
-
include_context "#{MODEL_PARSER} swagger example"
|
7
|
-
|
8
|
-
let(:app) do
|
9
|
-
Class.new(Grape::API) do
|
10
|
-
namespace :issue_582 do
|
11
|
-
desc 'produces given',
|
12
|
-
success: File,
|
13
|
-
produces: ['application/pdf', 'text/csv']
|
14
|
-
get '/produces_given' do
|
15
|
-
'responds a file'
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'automatic produces',
|
19
|
-
success: 'file'
|
20
|
-
get '/automatic_produces' do
|
21
|
-
'responds a file'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
add_swagger_documentation format: :json
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
subject do
|
30
|
-
get '/swagger_doc'
|
31
|
-
JSON.parse(last_response.body)
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'produces given' do
|
35
|
-
let(:produces) { subject['paths']['/issue_582/produces_given']['get']['produces'] }
|
36
|
-
let(:response) { subject['paths']['/issue_582/produces_given']['get']['responses']['200'] }
|
37
|
-
|
38
|
-
specify do
|
39
|
-
expect(produces).to eql ['application/pdf', 'text/csv']
|
40
|
-
expect(response).to include 'schema'
|
41
|
-
expect(response['schema']).to eql 'type' => 'file'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'automatic_produces' do
|
46
|
-
let(:produces) { subject['paths']['/issue_582/automatic_produces']['get']['produces'] }
|
47
|
-
let(:response) { subject['paths']['/issue_582/automatic_produces']['get']['responses']['200'] }
|
48
|
-
|
49
|
-
specify do
|
50
|
-
expect(produces).to eql ['application/octet-stream']
|
51
|
-
expect(response).to include 'schema'
|
52
|
-
expect(response['schema']).to eql 'type' => 'file'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#587 process route with parameters delimited by dash' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :range_parameter do
|
9
|
-
desc 'Get a array with range'
|
10
|
-
get '/range/:range_start-:range_end' do
|
11
|
-
present []
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
add_swagger_documentation format: :json
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
subject do
|
20
|
-
get '/swagger_doc'
|
21
|
-
JSON.parse(last_response.body)['paths']
|
22
|
-
end
|
23
|
-
|
24
|
-
specify { expect(subject.keys).to include '/range_parameter/range/{range_start}-{range_end}' }
|
25
|
-
specify { expect(subject['/range_parameter/range/{range_start}-{range_end}']['get']['operationId']).to eql 'getRangeParameterRangeRangeStart-RangeEnd' }
|
26
|
-
end
|
@@ -1,23 +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
|
-
get do
|
9
|
-
{ message: 'hello world' }
|
10
|
-
end
|
11
|
-
|
12
|
-
add_swagger_documentation format: :json
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
subject do
|
17
|
-
get '/swagger_doc'
|
18
|
-
JSON.parse(last_response.body)['paths']
|
19
|
-
end
|
20
|
-
|
21
|
-
specify { expect(app.combined_routes.keys).to include '/' }
|
22
|
-
specify { expect(subject.keys).to include '/' }
|
23
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#605 Group Params as Array' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
params do
|
9
|
-
requires :array_of_range_string, type: [String], values: %w[a b c]
|
10
|
-
requires :array_of_range_integer, type: [Integer], values: [1, 2, 3]
|
11
|
-
end
|
12
|
-
post '/array_of_range' do
|
13
|
-
{ 'declared_params' => declared(params) }
|
14
|
-
end
|
15
|
-
|
16
|
-
params do
|
17
|
-
requires :array_with_default_string, type: [String], default: 'abc'
|
18
|
-
requires :array_with_default_integer, type: Array[Integer], default: 123
|
19
|
-
end
|
20
|
-
post '/array_with_default' do
|
21
|
-
{ 'declared_params' => declared(params) }
|
22
|
-
end
|
23
|
-
|
24
|
-
add_swagger_documentation
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'retrieves the documentation for typed group range parameters' do
|
29
|
-
subject do
|
30
|
-
get '/swagger_doc/array_of_range'
|
31
|
-
JSON.parse(last_response.body)
|
32
|
-
end
|
33
|
-
|
34
|
-
specify do
|
35
|
-
expect(subject['paths']['/array_of_range']['post']['parameters']).to eql(
|
36
|
-
[
|
37
|
-
{ 'in' => 'formData', 'name' => 'array_of_range_string', 'type' => 'array', 'items' => { 'type' => 'string', 'enum' => %w[a b c] }, 'required' => true },
|
38
|
-
{ 'in' => 'formData', 'name' => 'array_of_range_integer', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'enum' => [1, 2, 3] }, 'required' => true }
|
39
|
-
]
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'retrieves the documentation for typed group parameters with default' do
|
45
|
-
subject do
|
46
|
-
get '/swagger_doc/array_with_default'
|
47
|
-
JSON.parse(last_response.body)
|
48
|
-
end
|
49
|
-
|
50
|
-
specify do
|
51
|
-
expect(subject['paths']['/array_with_default']['post']['parameters']).to eql(
|
52
|
-
[
|
53
|
-
{ 'in' => 'formData', 'name' => 'array_with_default_string', 'type' => 'array', 'items' => { 'type' => 'string', 'default' => 'abc' }, 'required' => true },
|
54
|
-
{ 'in' => 'formData', 'name' => 'array_with_default_integer', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'default' => 123 }, 'required' => true }
|
55
|
-
]
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#677 consumes and produces options are included in add_swagger_documentation options' do
|
6
|
-
describe 'no override' do
|
7
|
-
let(:app) do
|
8
|
-
Class.new(Grape::API) do
|
9
|
-
resource :accounts do
|
10
|
-
route_param :account_number, type: String do
|
11
|
-
resource :records do
|
12
|
-
route_param :id do
|
13
|
-
post do
|
14
|
-
{ message: 'hello world' }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
add_swagger_documentation \
|
22
|
-
format: :json
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
subject do
|
27
|
-
get '/swagger_doc'
|
28
|
-
JSON.parse(last_response.body)
|
29
|
-
end
|
30
|
-
|
31
|
-
specify do
|
32
|
-
expect(subject['paths']['/accounts/{account_number}/records/{id}']['post']['produces']).to eq ['application/json']
|
33
|
-
expect(subject['paths']['/accounts/{account_number}/records/{id}']['post']['consumes']).to eq ['application/json']
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'override produces' do
|
38
|
-
let(:app) do
|
39
|
-
Class.new(Grape::API) do
|
40
|
-
resource :accounts do
|
41
|
-
route_param :account_number, type: String do
|
42
|
-
resource :records do
|
43
|
-
route_param :id do
|
44
|
-
post do
|
45
|
-
{ message: 'hello world' }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
add_swagger_documentation \
|
53
|
-
format: :json,
|
54
|
-
produces: ['text/plain']
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
subject do
|
59
|
-
get '/swagger_doc'
|
60
|
-
JSON.parse(last_response.body)
|
61
|
-
end
|
62
|
-
|
63
|
-
specify do
|
64
|
-
expect(subject['paths']['/accounts/{account_number}/records/{id}']['post']['produces']).to eq ['text/plain']
|
65
|
-
expect(subject['paths']['/accounts/{account_number}/records/{id}']['post']['consumes']).to eq ['application/json']
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'override consumes' do
|
70
|
-
let(:app) do
|
71
|
-
Class.new(Grape::API) do
|
72
|
-
resource :accounts do
|
73
|
-
route_param :account_number, type: String do
|
74
|
-
resource :records do
|
75
|
-
route_param :id do
|
76
|
-
post do
|
77
|
-
{ message: 'hello world' }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
add_swagger_documentation \
|
85
|
-
format: :json, \
|
86
|
-
consumes: ['application/json', 'application/x-www-form-urlencoded']
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
subject do
|
91
|
-
get '/swagger_doc'
|
92
|
-
JSON.parse(last_response.body)
|
93
|
-
end
|
94
|
-
|
95
|
-
specify do
|
96
|
-
expect(subject['paths']['/accounts/{account_number}/records/{id}']['post']['produces']).to eq ['application/json']
|
97
|
-
expect(subject['paths']['/accounts/{account_number}/records/{id}']['post']['consumes']).to eq ['application/json', 'application/x-www-form-urlencoded']
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'when the main endpoint response is a 204 all error schemas are lost' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
namespace :issue_680 do
|
9
|
-
desc 'delete something',
|
10
|
-
is_array: true,
|
11
|
-
success: { status: 204 },
|
12
|
-
failure: [
|
13
|
-
[401, 'Unauthorized', Entities::ApiError],
|
14
|
-
[403, 'Forbidden', Entities::ApiError],
|
15
|
-
[404, 'Not Found', Entities::ApiError]
|
16
|
-
]
|
17
|
-
|
18
|
-
delete do
|
19
|
-
status 204
|
20
|
-
end
|
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
|
-
context 'when an endpoint can return a 204' do
|
33
|
-
let(:responses) { subject['paths']['/issue_680']['delete']['responses'] }
|
34
|
-
|
35
|
-
it 'returns the description but not a schema for a 204 response' do
|
36
|
-
expect(responses['204']['description']).to eq('delete something')
|
37
|
-
expect(responses['204']['schema']).to be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns a description AND a schema for a 401 response' do
|
41
|
-
expect(responses['401']['description']).to eq('Unauthorized')
|
42
|
-
expect(responses['401']['schema']).to_not be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns a description AND a schema for a 403 response' do
|
46
|
-
expect(responses['403']['description']).to eq('Forbidden')
|
47
|
-
expect(responses['403']['schema']).to_not be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns a description AND a schema for a 404 response' do
|
51
|
-
expect(responses['404']['description']).to eq('Not Found')
|
52
|
-
expect(responses['404']['schema']).to_not be_nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,190 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '751 deeply nested objects' do
|
6
|
-
let(:app) do
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
content_type :json, 'application/json; charset=UTF-8'
|
9
|
-
default_format :json
|
10
|
-
class Vrp < Grape::API
|
11
|
-
def self.vrp_request_timewindow(this)
|
12
|
-
this.optional(:start, types: [String, Float, Integer])
|
13
|
-
this.optional(:end, types: [String, Float, Integer])
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.vrp_request_point(this)
|
17
|
-
this.requires(:id, type: String, allow_blank: false)
|
18
|
-
this.optional(:matrix_index, type: Integer)
|
19
|
-
this.optional(:location, type: Hash) do
|
20
|
-
requires(:lat, type: Float, allow_blank: false)
|
21
|
-
requires(:lon, type: Float, allow_blank: false)
|
22
|
-
end
|
23
|
-
this.at_least_one_of :matrix_index, :location
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.vrp_request_activity(this)
|
27
|
-
this.optional(:duration, types: [String, Float, Integer])
|
28
|
-
this.requires(:point_id, type: String, allow_blank: false)
|
29
|
-
this.optional(:timewindows, type: Array) do
|
30
|
-
Vrp.vrp_request_timewindow(self)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.vrp_request_service(this)
|
35
|
-
this.requires(:id, type: String, allow_blank: false)
|
36
|
-
this.optional(:skills, type: Array[String])
|
37
|
-
|
38
|
-
this.optional(:activity, type: Hash) do
|
39
|
-
Vrp.vrp_request_activity(self)
|
40
|
-
end
|
41
|
-
this.optional(:activities, type: Array) do
|
42
|
-
Vrp.vrp_request_activity(self)
|
43
|
-
end
|
44
|
-
this.mutually_exclusive :activity, :activities
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
namespace :vrp do
|
49
|
-
resource :submit do
|
50
|
-
desc 'Submit Problems', nickname: 'vrp'
|
51
|
-
params do
|
52
|
-
optional(:vrp, type: Hash, documentation: { param_type: 'body' }) do
|
53
|
-
optional(:points, type: Array) do
|
54
|
-
Vrp.vrp_request_point(self)
|
55
|
-
end
|
56
|
-
|
57
|
-
optional(:services, type: Array) do
|
58
|
-
Vrp.vrp_request_service(self)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
post do
|
63
|
-
{ vrp: params[:vrp] }.to_json
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
add_swagger_documentation format: :json
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
subject do
|
73
|
-
get '/swagger_doc'
|
74
|
-
JSON.parse(last_response.body)
|
75
|
-
end
|
76
|
-
|
77
|
-
describe 'Correctness of vrp Points' do
|
78
|
-
let(:get_points_response) { subject['definitions']['vrp']['properties']['vrp']['properties']['points'] }
|
79
|
-
specify do
|
80
|
-
expect(get_points_response).to eql(
|
81
|
-
'type' => 'array',
|
82
|
-
'items' => {
|
83
|
-
'type' => 'object',
|
84
|
-
'properties' => {
|
85
|
-
'id' => {
|
86
|
-
'type' => 'string'
|
87
|
-
},
|
88
|
-
'matrix_index' => {
|
89
|
-
'type' => 'integer',
|
90
|
-
'format' => 'int32'
|
91
|
-
},
|
92
|
-
'location' => {
|
93
|
-
'type' => 'object',
|
94
|
-
'properties' => {
|
95
|
-
'lat' => {
|
96
|
-
'type' => 'number',
|
97
|
-
'format' => 'float'
|
98
|
-
},
|
99
|
-
'lon' => {
|
100
|
-
'type' => 'number',
|
101
|
-
'format' => 'float'
|
102
|
-
}
|
103
|
-
},
|
104
|
-
'required' => %w[lat lon]
|
105
|
-
}
|
106
|
-
},
|
107
|
-
'required' => ['id']
|
108
|
-
}
|
109
|
-
)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe 'Correctness of vrp Services' do
|
114
|
-
let(:get_service_response) { subject['definitions']['vrp']['properties']['vrp']['properties']['services'] }
|
115
|
-
specify do
|
116
|
-
expect(get_service_response).to include(
|
117
|
-
'type' => 'array',
|
118
|
-
'items' => {
|
119
|
-
'type' => 'object',
|
120
|
-
'properties' => {
|
121
|
-
'id' => {
|
122
|
-
'type' => 'string'
|
123
|
-
},
|
124
|
-
'skills' => {
|
125
|
-
'type' => 'array',
|
126
|
-
'items' => {
|
127
|
-
'type' => 'string'
|
128
|
-
}
|
129
|
-
},
|
130
|
-
'activity' => {
|
131
|
-
'type' => 'object',
|
132
|
-
'properties' => {
|
133
|
-
'duration' => {
|
134
|
-
'type' => 'string'
|
135
|
-
},
|
136
|
-
'point_id' => {
|
137
|
-
'type' => 'string'
|
138
|
-
},
|
139
|
-
'timewindows' => {
|
140
|
-
'type' => 'array',
|
141
|
-
'items' => {
|
142
|
-
'type' => 'object',
|
143
|
-
'properties' => {
|
144
|
-
'start' => {
|
145
|
-
'type' => 'string'
|
146
|
-
},
|
147
|
-
'end' => {
|
148
|
-
'type' => 'string'
|
149
|
-
}
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
},
|
154
|
-
'required' => ['point_id']
|
155
|
-
}, 'activities' => {
|
156
|
-
'type' => 'array',
|
157
|
-
'items' => {
|
158
|
-
'type' => 'object',
|
159
|
-
'properties' => {
|
160
|
-
'duration' => {
|
161
|
-
'type' => 'string'
|
162
|
-
},
|
163
|
-
'point_id' => {
|
164
|
-
'type' => 'string'
|
165
|
-
},
|
166
|
-
'timewindows' => {
|
167
|
-
'type' => 'array',
|
168
|
-
'items' => {
|
169
|
-
'type' => 'object',
|
170
|
-
'properties' => {
|
171
|
-
'start' => {
|
172
|
-
'type' => 'string'
|
173
|
-
},
|
174
|
-
'end' => {
|
175
|
-
'type' => 'string'
|
176
|
-
}
|
177
|
-
}
|
178
|
-
}
|
179
|
-
}
|
180
|
-
},
|
181
|
-
'required' => ['point_id']
|
182
|
-
}
|
183
|
-
}
|
184
|
-
},
|
185
|
-
'required' => ['id']
|
186
|
-
}
|
187
|
-
)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|