grape-swagger 1.6.1 → 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 +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,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'namespace tags check while using prefix and version' do
|
6
|
-
include_context 'namespace example'
|
7
|
-
|
8
|
-
before :all do
|
9
|
-
module TheApi
|
10
|
-
class NamespaceApi < Grape::API
|
11
|
-
version %i[v1 v2]
|
12
|
-
end
|
13
|
-
|
14
|
-
class CascadingVersionApi < Grape::API
|
15
|
-
version :v2
|
16
|
-
|
17
|
-
namespace :hudson do
|
18
|
-
desc 'Document root'
|
19
|
-
get '/' do
|
20
|
-
{ message: 'hi' }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
namespace :colorado do
|
25
|
-
desc 'This gets something.',
|
26
|
-
notes: '_test_'
|
27
|
-
|
28
|
-
get '/simple' do
|
29
|
-
{ bla: 'something' }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class NestedPrefixApi < Grape::API
|
35
|
-
version :v1
|
36
|
-
prefix 'nested_prefix/api'
|
37
|
-
|
38
|
-
namespace :deep_namespace do
|
39
|
-
desc 'This gets something within a deeply nested resource'
|
40
|
-
get '/deep' do
|
41
|
-
{ bla: 'something' }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class TagApi < Grape::API
|
48
|
-
prefix :api
|
49
|
-
mount TheApi::CascadingVersionApi
|
50
|
-
mount TheApi::NamespaceApi
|
51
|
-
mount TheApi::NestedPrefixApi
|
52
|
-
add_swagger_documentation
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def app
|
57
|
-
TagApi
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'retrieves swagger-documentation on /swagger_doc' do
|
61
|
-
subject do
|
62
|
-
get '/api/swagger_doc.json'
|
63
|
-
JSON.parse(last_response.body)
|
64
|
-
end
|
65
|
-
|
66
|
-
specify do
|
67
|
-
expect(subject['tags']).to eql(
|
68
|
-
[
|
69
|
-
{ 'name' => 'hudson', 'description' => 'Operations about hudsons' },
|
70
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
|
71
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' },
|
72
|
-
{ 'name' => 'niles', 'description' => 'Operations about niles' },
|
73
|
-
{ 'name' => 'deep_namespace', 'description' => 'Operations about deep_namespaces' }
|
74
|
-
]
|
75
|
-
)
|
76
|
-
|
77
|
-
expect(subject['paths']['/api/v1/hudson']['get']['tags']).to eql(['hudson'])
|
78
|
-
expect(subject['paths']['/api/v1/colorado/simple']['get']['tags']).to eql(['colorado'])
|
79
|
-
expect(subject['paths']['/api/v1/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
80
|
-
expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
81
|
-
expect(subject['paths']['/api/v1/niles/items']['post']['tags']).to eql(['niles'])
|
82
|
-
expect(subject['paths']['/api/v1/niles/custom']['get']['tags']).to eql(['niles'])
|
83
|
-
expect(subject['paths']['/api/v2/hudson']['get']['tags']).to eql(['hudson'])
|
84
|
-
expect(subject['paths']['/api/v2/colorado/simple']['get']['tags']).to eql(['colorado'])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe 'retrieves the documentation for mounted-api' do
|
89
|
-
subject do
|
90
|
-
get '/api/swagger_doc/colorado.json'
|
91
|
-
JSON.parse(last_response.body)
|
92
|
-
end
|
93
|
-
|
94
|
-
specify do
|
95
|
-
expect(subject['tags']).to eql(
|
96
|
-
[
|
97
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' }
|
98
|
-
]
|
99
|
-
)
|
100
|
-
|
101
|
-
expect(subject['paths']['/api/v1/colorado/simple']['get']['tags']).to eql(['colorado'])
|
102
|
-
expect(subject['paths']['/api/v1/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
103
|
-
end
|
104
|
-
|
105
|
-
describe 'includes headers' do
|
106
|
-
subject do
|
107
|
-
get '/api/swagger_doc/thames.json'
|
108
|
-
JSON.parse(last_response.body)
|
109
|
-
end
|
110
|
-
|
111
|
-
specify do
|
112
|
-
expect(subject['tags']).to eql(
|
113
|
-
[
|
114
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' }
|
115
|
-
]
|
116
|
-
)
|
117
|
-
|
118
|
-
expect(subject['paths']['/api/v1/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'namespace tags check' do
|
6
|
-
include_context 'namespace example'
|
7
|
-
|
8
|
-
before :all do
|
9
|
-
class TestApi < Grape::API
|
10
|
-
mount TheApi::NamespaceApi
|
11
|
-
add_swagger_documentation
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def app
|
16
|
-
TestApi
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'retrieves swagger-documentation on /swagger_doc' do
|
20
|
-
subject do
|
21
|
-
get '/swagger_doc.json'
|
22
|
-
JSON.parse(last_response.body)
|
23
|
-
end
|
24
|
-
|
25
|
-
specify do
|
26
|
-
expect(subject['tags']).to eql(
|
27
|
-
[
|
28
|
-
{ 'name' => 'hudson', 'description' => 'Operations about hudsons' },
|
29
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
|
30
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' },
|
31
|
-
{ 'name' => 'niles', 'description' => 'Operations about niles' }
|
32
|
-
]
|
33
|
-
)
|
34
|
-
|
35
|
-
expect(subject['paths']['/hudson']['get']['tags']).to eql(['hudson'])
|
36
|
-
expect(subject['paths']['/colorado/simple']['get']['tags']).to eql(['colorado'])
|
37
|
-
expect(subject['paths']['/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
38
|
-
expect(subject['paths']['/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
39
|
-
expect(subject['paths']['/niles/items']['post']['tags']).to eql(['niles'])
|
40
|
-
expect(subject['paths']['/niles/custom']['get']['tags']).to eql(['niles'])
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'retrieves the documentation for mounted-api' do
|
45
|
-
subject do
|
46
|
-
get '/swagger_doc/colorado.json'
|
47
|
-
JSON.parse(last_response.body)
|
48
|
-
end
|
49
|
-
|
50
|
-
specify do
|
51
|
-
expect(subject['tags']).to eql(
|
52
|
-
[
|
53
|
-
{ 'name' => 'colorado', 'description' => 'Operations about colorados' }
|
54
|
-
]
|
55
|
-
)
|
56
|
-
|
57
|
-
expect(subject['paths']['/colorado/simple']['get']['tags']).to eql(['colorado'])
|
58
|
-
expect(subject['paths']['/colorado/simple-test']['get']['tags']).to eql(['colorado'])
|
59
|
-
end
|
60
|
-
|
61
|
-
describe 'includes headers' do
|
62
|
-
subject do
|
63
|
-
get '/swagger_doc/thames.json'
|
64
|
-
JSON.parse(last_response.body)
|
65
|
-
end
|
66
|
-
|
67
|
-
specify do
|
68
|
-
expect(subject['tags']).to eql(
|
69
|
-
[
|
70
|
-
{ 'name' => 'thames', 'description' => 'Operations about thames' }
|
71
|
-
]
|
72
|
-
)
|
73
|
-
|
74
|
-
expect(subject['paths']['/thames/simple_with_headers']['get']['tags']).to eql(['thames'])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'namespace' do
|
6
|
-
context 'at root level' do
|
7
|
-
def app
|
8
|
-
Class.new(Grape::API) do
|
9
|
-
namespace :aspace do
|
10
|
-
get '/', desc: 'Description for aspace'
|
11
|
-
end
|
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']['/aspace']['get']
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'shows the namespace summary in the json spec' do
|
22
|
-
expect(subject['summary']).to eql('Description for aspace')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with camel case namespace' do
|
27
|
-
def app
|
28
|
-
Class.new(Grape::API) do
|
29
|
-
namespace :camelCases do
|
30
|
-
get '/', desc: 'Look! An endpoint.'
|
31
|
-
end
|
32
|
-
add_swagger_documentation format: :json
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
subject do
|
37
|
-
get '/swagger_doc'
|
38
|
-
JSON.parse(last_response.body)['paths']['/camelCases']['get']
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'shows the namespace summary in the json spec' do
|
42
|
-
expect(subject['summary']).to eql('Look! An endpoint.')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'mounted' do
|
47
|
-
def app
|
48
|
-
namespaced_api = Class.new(Grape::API) do
|
49
|
-
namespace :bspace do
|
50
|
-
get '/', desc: 'Description for aspace'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
Class.new(Grape::API) do
|
55
|
-
mount namespaced_api
|
56
|
-
add_swagger_documentation format: :json
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
subject do
|
61
|
-
get '/swagger_doc'
|
62
|
-
JSON.parse(last_response.body)['paths']['/bspace']['get']
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'shows the namespace summary in the json spec' do
|
66
|
-
expect(subject['summary']).to eql('Description for aspace')
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'mounted under a route' do
|
71
|
-
def app
|
72
|
-
namespaced_api = Class.new(Grape::API) do
|
73
|
-
namespace :bspace do
|
74
|
-
get '/', desc: 'Description for aspace'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
Class.new(Grape::API) do
|
79
|
-
mount namespaced_api => '/mounted'
|
80
|
-
add_swagger_documentation format: :json
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
subject do
|
85
|
-
get '/swagger_doc'
|
86
|
-
JSON.parse(last_response.body)['paths']['/mounted/bspace']['get']
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'shows the namespace summary in the json spec' do
|
90
|
-
expect(subject['summary']).to eql('Description for aspace')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'arbitrary mounting' do
|
95
|
-
def app
|
96
|
-
inner_namespaced_api = Class.new(Grape::API) do
|
97
|
-
namespace :bspace do
|
98
|
-
get '/', desc: 'Description for aspace'
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
outer_namespaced_api = Class.new(Grape::API) do
|
103
|
-
mount inner_namespaced_api => '/mounted'
|
104
|
-
end
|
105
|
-
|
106
|
-
Class.new(Grape::API) do
|
107
|
-
mount outer_namespaced_api => '/'
|
108
|
-
add_swagger_documentation format: :json
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
subject do
|
113
|
-
get '/swagger_doc'
|
114
|
-
JSON.parse(last_response.body)['paths']['/mounted/bspace']['get']
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'shows the namespace summary in the json spec' do
|
118
|
-
expect(subject['summary']).to eql('Description for aspace')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'a nicknamed mounted api' do
|
6
|
-
def app
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
desc 'Show this endpoint', nickname: 'simple'
|
9
|
-
get '/simple' do
|
10
|
-
{ foo: 'bar' }
|
11
|
-
end
|
12
|
-
|
13
|
-
add_swagger_documentation format: :json
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
subject do
|
18
|
-
get '/swagger_doc.json'
|
19
|
-
JSON.parse(last_response.body)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'uses the nickname as the operationId' do
|
23
|
-
expect(subject['paths']['/simple']['get']['operationId']).to eql('simple')
|
24
|
-
end
|
25
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'an operation id api' do
|
6
|
-
def app
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
version '0.1'
|
9
|
-
|
10
|
-
desc 'Show this endpoint'
|
11
|
-
get '/simple_opp' do
|
12
|
-
{ foo: 'bar' }
|
13
|
-
end
|
14
|
-
|
15
|
-
add_swagger_documentation format: :json
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
subject do
|
20
|
-
get '/0.1/swagger_doc.json'
|
21
|
-
JSON.parse(last_response.body)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'uses build name as operationId' do
|
25
|
-
expect(subject['paths']['/0.1/simple_opp']['get']['operationId']).to eql('get01SimpleOpp')
|
26
|
-
end
|
27
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Params Multi Types' do
|
6
|
-
def app
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
format :json
|
9
|
-
|
10
|
-
params do
|
11
|
-
if Grape::VERSION < '0.14'
|
12
|
-
requires :input, type: [String, Integer]
|
13
|
-
else
|
14
|
-
requires :input, types: [String, Integer]
|
15
|
-
end
|
16
|
-
requires :another_input, type: [String, Integer]
|
17
|
-
end
|
18
|
-
post :action do
|
19
|
-
{ message: 'hi' }
|
20
|
-
end
|
21
|
-
|
22
|
-
add_swagger_documentation
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
subject do
|
27
|
-
get '/swagger_doc/action'
|
28
|
-
expect(last_response.status).to eq 200
|
29
|
-
body = JSON.parse last_response.body
|
30
|
-
body['paths']['/action']['post']['parameters']
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'reads param type correctly' do
|
34
|
-
expect(subject).to eq [
|
35
|
-
{
|
36
|
-
'in' => 'formData',
|
37
|
-
'name' => 'input',
|
38
|
-
'type' => 'string',
|
39
|
-
'required' => true
|
40
|
-
},
|
41
|
-
{
|
42
|
-
'in' => 'formData',
|
43
|
-
'name' => 'another_input',
|
44
|
-
'type' => 'string',
|
45
|
-
'required' => true
|
46
|
-
}
|
47
|
-
]
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'header params' do
|
51
|
-
def app
|
52
|
-
Class.new(Grape::API) do
|
53
|
-
format :json
|
54
|
-
|
55
|
-
desc 'Some API', headers: { 'My-Header' => { required: true, description: 'Set this!' } }
|
56
|
-
params do
|
57
|
-
if Grape::VERSION < '0.14'
|
58
|
-
requires :input, type: [String, Integer]
|
59
|
-
else
|
60
|
-
requires :input, types: [String, Integer]
|
61
|
-
end
|
62
|
-
requires :another_input, type: [String, Integer]
|
63
|
-
end
|
64
|
-
post :action do
|
65
|
-
{ message: 'hi' }
|
66
|
-
end
|
67
|
-
|
68
|
-
add_swagger_documentation
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'has consistent types' do
|
73
|
-
types = subject.map { |param| param['type'] }
|
74
|
-
expect(types).to eq(%w[string string string])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe 'Params Types' do
|
6
|
-
def app
|
7
|
-
Class.new(Grape::API) do
|
8
|
-
format :json
|
9
|
-
|
10
|
-
params do
|
11
|
-
requires :input, type: String
|
12
|
-
end
|
13
|
-
post :action do
|
14
|
-
{ message: 'hi' }
|
15
|
-
end
|
16
|
-
|
17
|
-
params do
|
18
|
-
requires :input, type: String, default: '14', documentation: { type: 'email', default: '42' }
|
19
|
-
end
|
20
|
-
post :action_with_doc do
|
21
|
-
{ message: 'hi' }
|
22
|
-
end
|
23
|
-
|
24
|
-
add_swagger_documentation
|
25
|
-
end
|
26
|
-
end
|
27
|
-
context 'with no documentation hash' do
|
28
|
-
subject do
|
29
|
-
get '/swagger_doc/action'
|
30
|
-
expect(last_response.status).to eq 200
|
31
|
-
body = JSON.parse last_response.body
|
32
|
-
body['paths']['/action']['post']['parameters']
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'reads param type correctly' do
|
36
|
-
expect(subject).to eq [{
|
37
|
-
'in' => 'formData',
|
38
|
-
'name' => 'input',
|
39
|
-
'type' => 'string',
|
40
|
-
'required' => true
|
41
|
-
}]
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'header params' do
|
45
|
-
def app
|
46
|
-
Class.new(Grape::API) do
|
47
|
-
format :json
|
48
|
-
|
49
|
-
desc 'Some API', headers: { 'My-Header' => { required: true, description: 'Set this!' } }
|
50
|
-
params do
|
51
|
-
requires :input, type: String
|
52
|
-
end
|
53
|
-
post :action do
|
54
|
-
{ message: 'hi' }
|
55
|
-
end
|
56
|
-
|
57
|
-
add_swagger_documentation
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'has consistent types' do
|
62
|
-
types = subject.map { |param| param['type'] }
|
63
|
-
expect(types).to eq(%w[string string])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'with documentation hash' do
|
69
|
-
subject do
|
70
|
-
get '/swagger_doc/action_with_doc'
|
71
|
-
expect(last_response.status).to eq 200
|
72
|
-
body = JSON.parse last_response.body
|
73
|
-
body['paths']['/action_with_doc']['post']['parameters']
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'reads param type correctly' do
|
77
|
-
expect(subject).to eq [{
|
78
|
-
'in' => 'formData',
|
79
|
-
'name' => 'input',
|
80
|
-
'type' => 'string',
|
81
|
-
'format' => 'email',
|
82
|
-
'default' => '42',
|
83
|
-
'required' => true
|
84
|
-
}]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
# require 'grape_version'
|
5
|
-
|
6
|
-
describe 'Convert values to enum or Range' do
|
7
|
-
def app
|
8
|
-
Class.new(Grape::API) do
|
9
|
-
format :json
|
10
|
-
|
11
|
-
params do
|
12
|
-
requires :letter, type: String, values: %w[a b c]
|
13
|
-
end
|
14
|
-
post :plain_array do
|
15
|
-
{ message: 'hi' }
|
16
|
-
end
|
17
|
-
|
18
|
-
params do
|
19
|
-
requires :letter, type: String, values: proc { %w[d e f] }
|
20
|
-
end
|
21
|
-
post :array_in_proc do
|
22
|
-
{ message: 'hi' }
|
23
|
-
end
|
24
|
-
|
25
|
-
params do
|
26
|
-
requires :letter, type: String, values: 'a'..'z'
|
27
|
-
end
|
28
|
-
post :range_letter do
|
29
|
-
{ message: 'hi' }
|
30
|
-
end
|
31
|
-
|
32
|
-
params do
|
33
|
-
requires :integer, type: Integer, values: -5..5
|
34
|
-
end
|
35
|
-
post :range_integer do
|
36
|
-
{ message: 'hi' }
|
37
|
-
end
|
38
|
-
|
39
|
-
add_swagger_documentation
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def first_parameter_info(request)
|
44
|
-
get "/swagger_doc/#{request}"
|
45
|
-
expect(last_response.status).to eq 200
|
46
|
-
body = JSON.parse last_response.body
|
47
|
-
body['paths']["/#{request}"]['post']['parameters']
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'Plain array values' do
|
51
|
-
subject(:plain_array) { first_parameter_info('plain_array') }
|
52
|
-
it 'has values as array in enum' do
|
53
|
-
expect(plain_array).to eq [{
|
54
|
-
'in' => 'formData',
|
55
|
-
'name' => 'letter',
|
56
|
-
'type' => 'string',
|
57
|
-
'required' => true,
|
58
|
-
'enum' => %w[a b c]
|
59
|
-
}]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'Array in proc values' do
|
64
|
-
subject(:array_in_proc) { first_parameter_info('array_in_proc') }
|
65
|
-
|
66
|
-
it 'has proc returned values as array in enum' do
|
67
|
-
expect(array_in_proc).to eq [{
|
68
|
-
'in' => 'formData',
|
69
|
-
'name' => 'letter',
|
70
|
-
'type' => 'string',
|
71
|
-
'required' => true,
|
72
|
-
'enum' => %w[d e f]
|
73
|
-
}]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'Range values' do
|
78
|
-
subject(:range_letter) { first_parameter_info('range_letter') }
|
79
|
-
|
80
|
-
it 'has letter range values' do
|
81
|
-
expect(range_letter).to eq [{
|
82
|
-
'in' => 'formData',
|
83
|
-
'name' => 'letter',
|
84
|
-
'type' => 'string',
|
85
|
-
'required' => true
|
86
|
-
}]
|
87
|
-
end
|
88
|
-
|
89
|
-
subject(:range_integer) { first_parameter_info('range_integer') }
|
90
|
-
|
91
|
-
it 'has integer range values' do
|
92
|
-
expect(range_integer).to eq [{
|
93
|
-
'in' => 'formData',
|
94
|
-
'name' => 'integer',
|
95
|
-
'type' => 'integer',
|
96
|
-
'required' => true,
|
97
|
-
'format' => 'int32',
|
98
|
-
'minimum' => -5,
|
99
|
-
'maximum' => 5
|
100
|
-
}]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe 'Convert values to enum for float range and not arrays inside a proc', if: GrapeVersion.satisfy?('>= 0.11.0') do
|
106
|
-
def app
|
107
|
-
Class.new(Grape::API) do
|
108
|
-
format :json
|
109
|
-
|
110
|
-
params do
|
111
|
-
requires :letter, type: String, values: proc { 'string' }
|
112
|
-
end
|
113
|
-
post :non_array_in_proc do
|
114
|
-
{ message: 'hi' }
|
115
|
-
end
|
116
|
-
|
117
|
-
params do
|
118
|
-
requires :float, type: Float, values: -5.0..5.0
|
119
|
-
end
|
120
|
-
post :range_float do
|
121
|
-
{ message: 'hi' }
|
122
|
-
end
|
123
|
-
|
124
|
-
add_swagger_documentation
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def first_parameter_info(request)
|
129
|
-
get "/swagger_doc/#{request}"
|
130
|
-
expect(last_response.status).to eq 200
|
131
|
-
body = JSON.parse last_response.body
|
132
|
-
body['paths']["/#{request}"]['post']['parameters']
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'Non array in proc values' do
|
136
|
-
subject(:non_array_in_proc) { first_parameter_info('non_array_in_proc') }
|
137
|
-
|
138
|
-
it 'has proc returned value as string in enum' do
|
139
|
-
expect(non_array_in_proc).to eq [{
|
140
|
-
'in' => 'formData',
|
141
|
-
'name' => 'letter',
|
142
|
-
'type' => 'string',
|
143
|
-
'required' => true,
|
144
|
-
'enum' => %w[string]
|
145
|
-
}]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'Range values' do
|
150
|
-
subject(:range_float) { first_parameter_info('range_float') }
|
151
|
-
|
152
|
-
it 'has float range values as string' do
|
153
|
-
expect(range_float).to eq [{
|
154
|
-
'in' => 'formData',
|
155
|
-
'name' => 'float',
|
156
|
-
'type' => 'number',
|
157
|
-
'required' => true,
|
158
|
-
'format' => 'float'
|
159
|
-
}]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|