grape-swagger 1.6.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +1 -0
- data/grape-swagger.gemspec +5 -5
- data/lib/grape-swagger/doc_methods/extensions.rb +2 -1
- data/lib/grape-swagger/doc_methods/move_params.rb +1 -0
- 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 -120
- data/.gitignore +0 -45
- data/.rspec +0 -3
- data/.rubocop.yml +0 -136
- data/.rubocop_todo.yml +0 -45
- 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 -82
- 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 -26
- 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,105 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'Group Array Params, using collection format' do
|
|
6
|
-
def app
|
|
7
|
-
Class.new(Grape::API) do
|
|
8
|
-
format :json
|
|
9
|
-
|
|
10
|
-
params do
|
|
11
|
-
optional :array_of_strings, type: Array[String], desc: 'array in csv collection format'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
get '/array_of_strings_without_collection_format' do
|
|
15
|
-
{ 'declared_params' => declared(params) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
params do
|
|
19
|
-
optional :array_of_strings, type: Array[String], desc: 'array in multi collection format', documentation: { collectionFormat: 'multi' }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
get '/array_of_strings_multi_collection_format' do
|
|
23
|
-
{ 'declared_params' => declared(params) }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
params do
|
|
27
|
-
optional :array_of_strings, type: Array[String], documentation: { collectionFormat: 'foo' }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
get '/array_of_strings_invalid_collection_format' do
|
|
31
|
-
{ 'declared_params' => declared(params) }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
params do
|
|
35
|
-
optional :array_of_strings, type: Array[String], desc: 'array in brackets collection format', documentation: { collectionFormat: 'brackets' }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
get '/array_of_strings_brackets_collection_format' do
|
|
39
|
-
{ 'declared_params' => declared(params) }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
add_swagger_documentation
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe 'documentation for array parameter in default csv collectionFormat' do
|
|
47
|
-
subject do
|
|
48
|
-
get '/swagger_doc/array_of_strings_without_collection_format'
|
|
49
|
-
JSON.parse(last_response.body)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
specify do
|
|
53
|
-
expect(subject['paths']['/array_of_strings_without_collection_format']['get']['parameters']).to eql(
|
|
54
|
-
[
|
|
55
|
-
{ 'in' => 'formData', 'name' => 'array_of_strings', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false, 'description' => 'array in csv collection format' }
|
|
56
|
-
]
|
|
57
|
-
)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe 'documentation for array parameters in multi collectionFormat set from documentation' do
|
|
62
|
-
subject do
|
|
63
|
-
get '/swagger_doc/array_of_strings_multi_collection_format'
|
|
64
|
-
JSON.parse(last_response.body)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
specify do
|
|
68
|
-
expect(subject['paths']['/array_of_strings_multi_collection_format']['get']['parameters']).to eql(
|
|
69
|
-
[
|
|
70
|
-
{ 'in' => 'formData', 'name' => 'array_of_strings', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false, 'collectionFormat' => 'multi', 'description' => 'array in multi collection format' }
|
|
71
|
-
]
|
|
72
|
-
)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe 'documentation for array parameters in brackets collectionFormat set from documentation' do
|
|
77
|
-
subject do
|
|
78
|
-
get '/swagger_doc/array_of_strings_brackets_collection_format'
|
|
79
|
-
JSON.parse(last_response.body)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
specify do
|
|
83
|
-
expect(subject['paths']['/array_of_strings_brackets_collection_format']['get']['parameters']).to eql(
|
|
84
|
-
[
|
|
85
|
-
{ 'in' => 'formData', 'name' => 'array_of_strings', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false, 'collectionFormat' => 'brackets', 'description' => 'array in brackets collection format' }
|
|
86
|
-
]
|
|
87
|
-
)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
describe 'documentation for array parameters with collectionFormat set to invalid option' do
|
|
92
|
-
subject do
|
|
93
|
-
get '/swagger_doc/array_of_strings_invalid_collection_format'
|
|
94
|
-
JSON.parse(last_response.body)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
specify do
|
|
98
|
-
expect(subject['paths']['/array_of_strings_invalid_collection_format']['get']['parameters']).to eql(
|
|
99
|
-
[
|
|
100
|
-
{ 'in' => 'formData', 'name' => 'array_of_strings', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false }
|
|
101
|
-
]
|
|
102
|
-
)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'Group Params as Array' do
|
|
6
|
-
include_context "#{MODEL_PARSER} swagger example"
|
|
7
|
-
|
|
8
|
-
[true, false].each do |array_use_braces|
|
|
9
|
-
context "when array_use_braces option is set to #{array_use_braces}" do
|
|
10
|
-
let(:braces) { array_use_braces ? '[]' : '' }
|
|
11
|
-
|
|
12
|
-
let(:app) do
|
|
13
|
-
Class.new(Grape::API) do
|
|
14
|
-
format :json
|
|
15
|
-
|
|
16
|
-
params do
|
|
17
|
-
requires :required_group, type: Array do
|
|
18
|
-
requires :required_param_1
|
|
19
|
-
requires :required_param_2
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
post '/groups' do
|
|
23
|
-
{ 'declared_params' => declared(params) }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
params do
|
|
27
|
-
requires :typed_group, type: Array do
|
|
28
|
-
requires :id, type: Integer, desc: 'integer given'
|
|
29
|
-
requires :name, type: String, desc: 'string given'
|
|
30
|
-
optional :email, type: String, desc: 'email given'
|
|
31
|
-
optional :others, type: Integer, values: [1, 2, 3]
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
post '/type_given' do
|
|
35
|
-
{ 'declared_params' => declared(params) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# as body parameters it would be interpreted a bit different,
|
|
39
|
-
# cause it could not be distinguished anymore, so this would be translated to one array,
|
|
40
|
-
# see also next example for the difference
|
|
41
|
-
params do
|
|
42
|
-
requires :array_of_string, type: Array[String], documentation: { param_type: 'body', desc: 'nested array of strings' }
|
|
43
|
-
requires :array_of_integer, type: Array[Integer], documentation: { param_type: 'body', desc: 'nested array of integers' }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
post '/array_of_type' do
|
|
47
|
-
{ 'declared_params' => declared(params) }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
params do
|
|
51
|
-
requires :array_of_string, type: Array[String], documentation: { param_type: 'body', desc: 'array of strings' }
|
|
52
|
-
requires :integer_value, type: Integer, documentation: { param_type: 'body', desc: 'integer value' }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
post '/object_and_array' do
|
|
56
|
-
{ 'declared_params' => declared(params) }
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
params do
|
|
60
|
-
requires :array_of_string, type: Array[String]
|
|
61
|
-
requires :array_of_integer, type: Array[Integer]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
post '/array_of_type_in_form' do
|
|
65
|
-
{ 'declared_params' => declared(params) }
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
params do
|
|
69
|
-
requires :array_of_entities, type: Array[Entities::ApiError]
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
post '/array_of_entities' do
|
|
73
|
-
{ 'declared_params' => declared(params) }
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
add_swagger_documentation array_use_braces: array_use_braces
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe 'retrieves the documentation for grouped parameters' do
|
|
81
|
-
subject do
|
|
82
|
-
get '/swagger_doc/groups'
|
|
83
|
-
JSON.parse(last_response.body)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
specify do
|
|
87
|
-
expect(subject['paths']['/groups']['post']['parameters']).to eql(
|
|
88
|
-
[
|
|
89
|
-
{ 'in' => 'formData', 'name' => "required_group#{braces}[required_param_1]", 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
|
90
|
-
{ 'in' => 'formData', 'name' => "required_group#{braces}[required_param_2]", 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } }
|
|
91
|
-
]
|
|
92
|
-
)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
describe 'retrieves the documentation for typed group parameters' do
|
|
97
|
-
subject do
|
|
98
|
-
get '/swagger_doc/type_given'
|
|
99
|
-
JSON.parse(last_response.body)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
specify do
|
|
103
|
-
expect(subject['paths']['/type_given']['post']['parameters']).to eql(
|
|
104
|
-
[
|
|
105
|
-
{ 'in' => 'formData', 'name' => "typed_group#{braces}[id]", 'description' => 'integer given', 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32' }, 'required' => true },
|
|
106
|
-
{ 'in' => 'formData', 'name' => "typed_group#{braces}[name]", 'description' => 'string given', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true },
|
|
107
|
-
{ 'in' => 'formData', 'name' => "typed_group#{braces}[email]", 'description' => 'email given', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false },
|
|
108
|
-
{ 'in' => 'formData', 'name' => "typed_group#{braces}[others]", 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32', 'enum' => [1, 2, 3] }, 'required' => false }
|
|
109
|
-
]
|
|
110
|
-
)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe 'retrieves the documentation for parameters that are arrays of primitive types' do
|
|
115
|
-
subject do
|
|
116
|
-
get '/swagger_doc/array_of_type'
|
|
117
|
-
JSON.parse(last_response.body)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
specify do
|
|
121
|
-
expect(subject['definitions']['postArrayOfType']['type']).to eql 'array'
|
|
122
|
-
expect(subject['definitions']['postArrayOfType']['items']).to eql(
|
|
123
|
-
'type' => 'object',
|
|
124
|
-
'properties' => {
|
|
125
|
-
'array_of_string' => {
|
|
126
|
-
'items' => { 'type' => 'string' }, 'type' => 'array', 'description' => 'nested array of strings'
|
|
127
|
-
},
|
|
128
|
-
'array_of_integer' => {
|
|
129
|
-
'items' => { 'type' => 'integer', 'format' => 'int32' }, 'type' => 'array', 'description' => 'nested array of integers'
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
'required' => %w[array_of_string array_of_integer]
|
|
133
|
-
)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe 'documentation for simple and array parameters' do
|
|
138
|
-
subject do
|
|
139
|
-
get '/swagger_doc/object_and_array'
|
|
140
|
-
JSON.parse(last_response.body)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
specify do
|
|
144
|
-
expect(subject['definitions']['postObjectAndArray']['type']).to eql 'object'
|
|
145
|
-
expect(subject['definitions']['postObjectAndArray']['properties']).to eql(
|
|
146
|
-
'array_of_string' => {
|
|
147
|
-
'type' => 'array',
|
|
148
|
-
'description' => 'array of strings',
|
|
149
|
-
'items' => {
|
|
150
|
-
'type' => 'string'
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
'integer_value' => {
|
|
154
|
-
'type' => 'integer', 'format' => 'int32', 'description' => 'integer value'
|
|
155
|
-
}
|
|
156
|
-
)
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
describe 'retrieves the documentation for typed group parameters' do
|
|
161
|
-
subject do
|
|
162
|
-
get '/swagger_doc/array_of_type_in_form'
|
|
163
|
-
JSON.parse(last_response.body)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
specify do
|
|
167
|
-
expect(subject['paths']['/array_of_type_in_form']['post']['parameters']).to eql(
|
|
168
|
-
[
|
|
169
|
-
{ 'in' => 'formData', 'name' => "array_of_string#{braces}", 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => true },
|
|
170
|
-
{ 'in' => 'formData', 'name' => "array_of_integer#{braces}", 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32' }, 'required' => true }
|
|
171
|
-
]
|
|
172
|
-
)
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe 'documentation for entity array parameters' do
|
|
177
|
-
let(:parameters) do
|
|
178
|
-
[
|
|
179
|
-
{
|
|
180
|
-
'in' => 'formData',
|
|
181
|
-
'name' => "array_of_entities#{braces}",
|
|
182
|
-
'type' => 'array',
|
|
183
|
-
'items' => {
|
|
184
|
-
'$ref' => '#/definitions/ApiError'
|
|
185
|
-
},
|
|
186
|
-
'required' => true
|
|
187
|
-
}
|
|
188
|
-
]
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
subject do
|
|
192
|
-
get '/swagger_doc/array_of_entities'
|
|
193
|
-
JSON.parse(last_response.body)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
specify do
|
|
197
|
-
expect(subject['definitions']['ApiError']).not_to be_blank
|
|
198
|
-
expect(subject['paths']['/array_of_entities']['post']['parameters']).to eql(parameters)
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'Param example' do
|
|
6
|
-
def app
|
|
7
|
-
Class.new(Grape::API) do
|
|
8
|
-
format :json
|
|
9
|
-
|
|
10
|
-
params do
|
|
11
|
-
requires :id, type: Integer, documentation: { example: 123 }
|
|
12
|
-
optional :name, type: String, documentation: { example: 'Person' }
|
|
13
|
-
optional :obj, type: 'Object', documentation: { example: { 'foo' => 'bar' } }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
get '/endpoint_with_examples' do
|
|
17
|
-
{ 'declared_params' => declared(params) }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
add_swagger_documentation
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe 'documentation with parameter examples' do
|
|
25
|
-
subject do
|
|
26
|
-
get '/swagger_doc/endpoint_with_examples'
|
|
27
|
-
JSON.parse(last_response.body)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
specify do
|
|
31
|
-
expect(subject['paths']['/endpoint_with_examples']['get']['parameters']).to eql(
|
|
32
|
-
[
|
|
33
|
-
{ 'in' => 'query', 'name' => 'id', 'type' => 'integer', 'example' => 123, 'format' => 'int32', 'required' => true },
|
|
34
|
-
{ 'in' => 'query', 'name' => 'name', 'type' => 'string', 'example' => 'Person', 'required' => false },
|
|
35
|
-
{ 'in' => 'query', 'name' => 'obj', 'type' => 'Object', 'example' => { 'foo' => 'bar' }, 'required' => false }
|
|
36
|
-
]
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'Group Params as Hash' do
|
|
6
|
-
def app
|
|
7
|
-
Class.new(Grape::API) do
|
|
8
|
-
format :json
|
|
9
|
-
|
|
10
|
-
params do
|
|
11
|
-
requires :required_group, type: Hash do
|
|
12
|
-
requires :required_param_1
|
|
13
|
-
requires :required_param_2
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
post '/use_groups' do
|
|
17
|
-
{ 'declared_params' => declared(params) }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
params do
|
|
21
|
-
requires :typed_group, type: Hash do
|
|
22
|
-
requires :id, type: Integer, desc: 'integer given'
|
|
23
|
-
requires :name, type: String, desc: 'string given'
|
|
24
|
-
optional :email, type: String, desc: 'email given'
|
|
25
|
-
optional :others, type: Integer, values: [1, 2, 3]
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
post '/use_given_type' do
|
|
29
|
-
{ 'declared_params' => declared(params) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
add_swagger_documentation
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe 'grouped parameters' do
|
|
37
|
-
subject do
|
|
38
|
-
get '/swagger_doc/use_groups'
|
|
39
|
-
JSON.parse(last_response.body)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
specify do
|
|
43
|
-
expect(subject['paths']['/use_groups']['post']).to include('parameters')
|
|
44
|
-
expect(subject['paths']['/use_groups']['post']['parameters']).to eql(
|
|
45
|
-
[
|
|
46
|
-
{ 'in' => 'formData', 'name' => 'required_group[required_param_1]', 'type' => 'string', 'required' => true },
|
|
47
|
-
{ 'in' => 'formData', 'name' => 'required_group[required_param_2]', 'type' => 'string', 'required' => true }
|
|
48
|
-
]
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe 'grouped parameters with given type' do
|
|
54
|
-
subject do
|
|
55
|
-
get '/swagger_doc/use_given_type'
|
|
56
|
-
JSON.parse(last_response.body)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
specify do
|
|
60
|
-
expect(subject['paths']['/use_given_type']['post']).to include('parameters')
|
|
61
|
-
expect(subject['paths']['/use_given_type']['post']['parameters']).to eql(
|
|
62
|
-
[
|
|
63
|
-
{ 'in' => 'formData', 'name' => 'typed_group[id]', 'description' => 'integer given', 'type' => 'integer', 'required' => true, 'format' => 'int32' },
|
|
64
|
-
{ 'in' => 'formData', 'name' => 'typed_group[name]', 'description' => 'string given', 'type' => 'string', 'required' => true },
|
|
65
|
-
{ 'in' => 'formData', 'name' => 'typed_group[email]', 'description' => 'email given', 'type' => 'string', 'required' => false },
|
|
66
|
-
{ 'in' => 'formData', 'name' => 'typed_group[others]', 'type' => 'integer', 'required' => false, 'format' => 'int32', 'enum' => [1, 2, 3] }
|
|
67
|
-
]
|
|
68
|
-
)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'nested group params' do
|
|
6
|
-
[true, false].each do |array_use_braces|
|
|
7
|
-
context "when array_use_braces option is set to #{array_use_braces}" do
|
|
8
|
-
let(:braces) { array_use_braces ? '[]' : '' }
|
|
9
|
-
let(:app) do
|
|
10
|
-
Class.new(Grape::API) do
|
|
11
|
-
format :json
|
|
12
|
-
|
|
13
|
-
params do
|
|
14
|
-
requires :a_array, type: Array do
|
|
15
|
-
requires :param_1, type: Integer
|
|
16
|
-
requires :b_array, type: Array do
|
|
17
|
-
requires :param_2, type: String
|
|
18
|
-
end
|
|
19
|
-
requires :c_hash, type: Hash do
|
|
20
|
-
requires :param_3, type: String
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
requires :a_array_foo, type: String
|
|
24
|
-
end
|
|
25
|
-
post '/nested_array' do
|
|
26
|
-
{ 'declared_params' => declared(params) }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
params do
|
|
30
|
-
requires :a_hash, type: Hash do
|
|
31
|
-
requires :param_1, type: Integer
|
|
32
|
-
requires :b_hash, type: Hash do
|
|
33
|
-
requires :param_2, type: String
|
|
34
|
-
end
|
|
35
|
-
requires :c_array, type: Array do
|
|
36
|
-
requires :param_3, type: String
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
requires :a_hash_foo, type: String
|
|
40
|
-
end
|
|
41
|
-
post '/nested_hash' do
|
|
42
|
-
{ 'declared_params' => declared(params) }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
add_swagger_documentation array_use_braces: array_use_braces
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe 'retrieves the documentation for nested array parameters' do
|
|
50
|
-
subject do
|
|
51
|
-
get '/swagger_doc/nested_array'
|
|
52
|
-
JSON.parse(last_response.body)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
specify do
|
|
56
|
-
expect(subject['paths']['/nested_array']['post']['parameters']).to eql(
|
|
57
|
-
[
|
|
58
|
-
{ 'in' => 'formData', 'name' => "a_array#{braces}[param_1]", 'required' => true, 'type' => 'array', 'items' => { 'type' => 'integer', 'format' => 'int32' } },
|
|
59
|
-
{ 'in' => 'formData', 'name' => "a_array#{braces}[b_array]#{braces}[param_2]", 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
|
60
|
-
{ 'in' => 'formData', 'name' => "a_array#{braces}[c_hash][param_3]", 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
|
61
|
-
{ 'in' => 'formData', 'name' => 'a_array_foo', 'required' => true, 'type' => 'string' }
|
|
62
|
-
]
|
|
63
|
-
)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe 'retrieves the documentation for nested hash parameters' do
|
|
68
|
-
subject do
|
|
69
|
-
get '/swagger_doc/nested_hash'
|
|
70
|
-
JSON.parse(last_response.body)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
specify do
|
|
74
|
-
expect(subject['paths']['/nested_hash']['post']['parameters']).to eql(
|
|
75
|
-
[
|
|
76
|
-
{ 'in' => 'formData', 'name' => 'a_hash[param_1]', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
|
|
77
|
-
{ 'in' => 'formData', 'name' => 'a_hash[b_hash][param_2]', 'required' => true, 'type' => 'string' },
|
|
78
|
-
{ 'in' => 'formData', 'name' => "a_hash[c_array]#{braces}[param_3]", 'required' => true, 'type' => 'array', 'items' => { 'type' => 'string' } },
|
|
79
|
-
{ 'in' => 'formData', 'name' => 'a_hash_foo', 'required' => true, 'type' => 'string' }
|
|
80
|
-
]
|
|
81
|
-
)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'a parent less namespace' do
|
|
6
|
-
include_context 'namespace example'
|
|
7
|
-
|
|
8
|
-
before :all do
|
|
9
|
-
class ParentLessApi < Grape::API
|
|
10
|
-
prefix :api
|
|
11
|
-
mount TheApi::ParentLessNamespaceApi
|
|
12
|
-
add_swagger_documentation version: 'v1'
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def app
|
|
17
|
-
ParentLessApi
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe 'retrieves swagger-documentation on /swagger_doc' do
|
|
21
|
-
let(:route_name) { ':animal/:breed/queues/:queue_id/reservations' }
|
|
22
|
-
subject do
|
|
23
|
-
get '/api/swagger_doc.json'
|
|
24
|
-
JSON.parse(last_response.body)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
specify do
|
|
28
|
-
expect(subject['paths']['/api/{animal}/{breed}/queues/{queue_id}/reservations']['get']['operationId'])
|
|
29
|
-
.to eql('getApiAnimalBreedQueuesQueueIdReservations')
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe 'referenceEntity' do
|
|
6
|
-
before :all do
|
|
7
|
-
module MyAPI
|
|
8
|
-
module Entities
|
|
9
|
-
class Something < Grape::Entity
|
|
10
|
-
def self.entity_name
|
|
11
|
-
'SomethingCustom'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
class Kind < Grape::Entity
|
|
18
|
-
def self.entity_name
|
|
19
|
-
'KindCustom'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
expose :title, documentation: { type: 'string', desc: 'Title of the kind.' }
|
|
23
|
-
expose :something, documentation: { type: Something, desc: 'Something interesting.' }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class Base < Grape::Entity
|
|
27
|
-
def self.entity_name
|
|
28
|
-
parts = to_s.split('::')
|
|
29
|
-
|
|
30
|
-
"MyAPI::#{parts.last}"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
expose :title, documentation: { type: 'string', desc: 'Title of the parent.' }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class Child < Base
|
|
37
|
-
expose :child, documentation: { type: 'string', desc: 'Child property.' }
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
class ResponseModelApi < Grape::API
|
|
42
|
-
format :json
|
|
43
|
-
desc 'This returns kind and something or an error',
|
|
44
|
-
params: Entities::Kind.documentation.slice(:something),
|
|
45
|
-
entity: Entities::Kind,
|
|
46
|
-
http_codes: [
|
|
47
|
-
{ code: 200, message: 'OK', model: Entities::Kind }
|
|
48
|
-
]
|
|
49
|
-
params do
|
|
50
|
-
optional :something, desc: 'something as parameter'
|
|
51
|
-
end
|
|
52
|
-
get '/kind' do
|
|
53
|
-
kind = OpenStruct.new text: 'kind'
|
|
54
|
-
present kind, with: Entities::Kind
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
desc 'This returns a child entity',
|
|
58
|
-
entity: Entities::Child,
|
|
59
|
-
http_codes: [
|
|
60
|
-
{ code: 200, message: 'OK', model: Entities::Child }
|
|
61
|
-
]
|
|
62
|
-
get '/child' do
|
|
63
|
-
child = OpenStruct.new text: 'child'
|
|
64
|
-
present child, with: Entities::Child
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
add_swagger_documentation # models: [MyAPI::Entities::Something, MyAPI::Entities::Kind]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def app
|
|
73
|
-
MyAPI::ResponseModelApi
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe 'kind' do
|
|
77
|
-
subject do
|
|
78
|
-
get '/swagger_doc/kind'
|
|
79
|
-
JSON.parse(last_response.body)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it 'should document specified models' do
|
|
83
|
-
expect(subject['paths']['/kind']['get']['parameters']).to eq [{
|
|
84
|
-
'in' => 'query',
|
|
85
|
-
'name' => 'something',
|
|
86
|
-
'description' => 'Something interesting.',
|
|
87
|
-
'type' => 'SomethingCustom',
|
|
88
|
-
'required' => false
|
|
89
|
-
}]
|
|
90
|
-
|
|
91
|
-
expect(subject['definitions'].keys).to include 'SomethingCustom'
|
|
92
|
-
expect(subject['definitions']['SomethingCustom']).to eq(
|
|
93
|
-
'type' => 'object', 'properties' => { 'text' => { 'type' => 'string', 'description' => 'Content of something.' } }
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
expect(subject['definitions'].keys).to include 'KindCustom'
|
|
97
|
-
expect(subject['definitions']['KindCustom']).to eq(
|
|
98
|
-
'type' => 'object',
|
|
99
|
-
'properties' => {
|
|
100
|
-
'title' => { 'type' => 'string', 'description' => 'Title of the kind.' },
|
|
101
|
-
'something' => {
|
|
102
|
-
'$ref' => '#/definitions/SomethingCustom',
|
|
103
|
-
'description' => 'Something interesting.'
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
'description' => 'KindCustom model'
|
|
107
|
-
)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
describe 'child' do
|
|
112
|
-
subject do
|
|
113
|
-
get '/swagger_doc/child'
|
|
114
|
-
JSON.parse(last_response.body)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it 'should document specified models' do
|
|
118
|
-
expect(subject['definitions'].keys).to include 'MyAPI::Child'
|
|
119
|
-
expect(subject['definitions']['MyAPI::Child']).to eq(
|
|
120
|
-
'type' => 'object',
|
|
121
|
-
'properties' => {
|
|
122
|
-
'title' => { 'type' => 'string', 'description' => 'Title of the parent.' },
|
|
123
|
-
'child' => { 'type' => 'string', 'description' => 'Child property.' }
|
|
124
|
-
},
|
|
125
|
-
'description' => 'MyAPI::Child model'
|
|
126
|
-
)
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
end
|