gitlab-grape-swagger 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.github/dependabot.yml +20 -0
- data/.github/workflows/ci.yml +45 -0
- data/.gitignore +44 -0
- data/.gitlab-ci.yml +19 -0
- data/.rspec +3 -0
- data/.rubocop.yml +136 -0
- data/.rubocop_todo.yml +60 -0
- data/.ruby-gemset +1 -0
- data/CHANGELOG.md +671 -0
- data/CONTRIBUTING.md +126 -0
- data/Dangerfile +3 -0
- data/Gemfile +45 -0
- data/Gemfile.lock +249 -0
- data/LICENSE.txt +20 -0
- data/README.md +1772 -0
- data/RELEASING.md +82 -0
- data/Rakefile +20 -0
- data/UPGRADING.md +201 -0
- data/example/api/endpoints.rb +131 -0
- data/example/api/entities.rb +18 -0
- data/example/config.ru +42 -0
- data/example/example_requests.postman_collection +146 -0
- data/example/splines.png +0 -0
- data/example/swagger-example.png +0 -0
- data/grape-swagger.gemspec +23 -0
- data/lib/grape-swagger/doc_methods/build_model_definition.rb +68 -0
- data/lib/grape-swagger/doc_methods/data_type.rb +110 -0
- data/lib/grape-swagger/doc_methods/extensions.rb +101 -0
- data/lib/grape-swagger/doc_methods/file_params.rb +17 -0
- data/lib/grape-swagger/doc_methods/format_data.rb +53 -0
- data/lib/grape-swagger/doc_methods/headers.rb +20 -0
- data/lib/grape-swagger/doc_methods/move_params.rb +209 -0
- data/lib/grape-swagger/doc_methods/operation_id.rb +32 -0
- data/lib/grape-swagger/doc_methods/optional_object.rb +30 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +190 -0
- data/lib/grape-swagger/doc_methods/path_string.rb +52 -0
- data/lib/grape-swagger/doc_methods/produces_consumes.rb +15 -0
- data/lib/grape-swagger/doc_methods/status_codes.rb +21 -0
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +34 -0
- data/lib/grape-swagger/doc_methods/version.rb +20 -0
- data/lib/grape-swagger/doc_methods.rb +142 -0
- data/lib/grape-swagger/endpoint/params_parser.rb +76 -0
- data/lib/grape-swagger/endpoint.rb +476 -0
- data/lib/grape-swagger/errors.rb +17 -0
- data/lib/grape-swagger/instance.rb +7 -0
- data/lib/grape-swagger/model_parsers.rb +42 -0
- data/lib/grape-swagger/rake/oapi_tasks.rb +135 -0
- data/lib/grape-swagger/version.rb +5 -0
- data/lib/grape-swagger.rb +174 -0
- data/spec/issues/267_nested_namespaces.rb +55 -0
- data/spec/issues/403_versions_spec.rb +124 -0
- data/spec/issues/427_entity_as_string_spec.rb +39 -0
- data/spec/issues/430_entity_definitions_spec.rb +94 -0
- data/spec/issues/532_allow_custom_format_spec.rb +42 -0
- data/spec/issues/533_specify_status_code_spec.rb +78 -0
- data/spec/issues/537_enum_values_spec.rb +50 -0
- data/spec/issues/539_array_post_body_spec.rb +65 -0
- data/spec/issues/542_array_of_type_in_post_body_spec.rb +46 -0
- data/spec/issues/553_align_array_put_post_params_spec.rb +152 -0
- data/spec/issues/572_array_post_body_spec.rb +51 -0
- data/spec/issues/579_align_put_post_parameters_spec.rb +185 -0
- data/spec/issues/582_file_response_spec.rb +55 -0
- data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
- data/spec/issues/605_root_route_documentation_spec.rb +23 -0
- data/spec/issues/650_params_array_spec.rb +65 -0
- data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +100 -0
- data/spec/issues/680_keep_204_error_schemas_spec.rb +55 -0
- data/spec/issues/721_set_default_parameter_location_based_on_consumes_spec.rb +62 -0
- data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
- data/spec/issues/776_multiple_presents_spec.rb +59 -0
- data/spec/issues/784_extensions_on_params_spec.rb +42 -0
- data/spec/issues/809_utf8_routes_spec.rb +55 -0
- data/spec/issues/832_array_hash_float_decimal_spec.rb +114 -0
- data/spec/issues/847_route_param_options_spec.rb +37 -0
- data/spec/issues/873_wildcard_segments_path_parameters_spec.rb +28 -0
- data/spec/issues/878_optional_path_segments_spec.rb +29 -0
- data/spec/issues/881_handle_file_params_spec.rb +38 -0
- data/spec/issues/883_query_array_parameter_spec.rb +46 -0
- data/spec/issues/884_dont_document_non_schema_examples_spec.rb +49 -0
- data/spec/issues/887_prevent_duplicate_operation_ids_spec.rb +35 -0
- data/spec/lib/data_type_spec.rb +111 -0
- data/spec/lib/endpoint/params_parser_spec.rb +124 -0
- data/spec/lib/endpoint_spec.rb +153 -0
- data/spec/lib/extensions_spec.rb +185 -0
- data/spec/lib/format_data_spec.rb +115 -0
- data/spec/lib/model_parsers_spec.rb +104 -0
- data/spec/lib/move_params_spec.rb +444 -0
- data/spec/lib/oapi_tasks_spec.rb +163 -0
- data/spec/lib/operation_id_spec.rb +55 -0
- data/spec/lib/optional_object_spec.rb +47 -0
- data/spec/lib/parse_params_spec.rb +68 -0
- data/spec/lib/path_string_spec.rb +101 -0
- data/spec/lib/produces_consumes_spec.rb +116 -0
- data/spec/lib/tag_name_description_spec.rb +80 -0
- data/spec/lib/version_spec.rb +28 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/empty_model_parser.rb +23 -0
- data/spec/support/grape_version.rb +13 -0
- data/spec/support/mock_parser.rb +23 -0
- data/spec/support/model_parsers/entity_parser.rb +334 -0
- data/spec/support/model_parsers/mock_parser.rb +346 -0
- data/spec/support/model_parsers/representable_parser.rb +406 -0
- data/spec/support/namespace_tags.rb +93 -0
- data/spec/support/the_paths_definitions.rb +109 -0
- data/spec/swagger_v2/api_documentation_spec.rb +42 -0
- data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
- data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +48 -0
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +36 -0
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +79 -0
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +145 -0
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +137 -0
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +56 -0
- data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +64 -0
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +58 -0
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +57 -0
- data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +109 -0
- data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +48 -0
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +153 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +355 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +217 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +247 -0
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +80 -0
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +147 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +135 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +216 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +53 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
- data/spec/swagger_v2/api_swagger_v2_spec.rb +245 -0
- data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +93 -0
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +90 -0
- data/spec/swagger_v2/boolean_params_spec.rb +38 -0
- data/spec/swagger_v2/default_api_spec.rb +175 -0
- data/spec/swagger_v2/deprecated_field_spec.rb +25 -0
- data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
- data/spec/swagger_v2/endpoint_versioned_path_spec.rb +130 -0
- data/spec/swagger_v2/errors_spec.rb +77 -0
- data/spec/swagger_v2/float_api_spec.rb +36 -0
- data/spec/swagger_v2/form_params_spec.rb +76 -0
- data/spec/swagger_v2/grape-swagger_spec.rb +17 -0
- data/spec/swagger_v2/guarded_endpoint_spec.rb +162 -0
- data/spec/swagger_v2/hide_api_spec.rb +147 -0
- data/spec/swagger_v2/host_spec.rb +43 -0
- data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +57 -0
- data/spec/swagger_v2/mount_override_api_spec.rb +58 -0
- data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +122 -0
- data/spec/swagger_v2/namespace_tags_spec.rb +78 -0
- data/spec/swagger_v2/namespaced_api_spec.rb +121 -0
- data/spec/swagger_v2/nicknamed_api_spec.rb +25 -0
- data/spec/swagger_v2/operation_id_api_spec.rb +27 -0
- data/spec/swagger_v2/param_multi_type_spec.rb +82 -0
- data/spec/swagger_v2/param_type_spec.rb +95 -0
- data/spec/swagger_v2/param_values_spec.rb +180 -0
- data/spec/swagger_v2/params_array_collection_format_spec.rb +105 -0
- data/spec/swagger_v2/params_array_spec.rb +225 -0
- data/spec/swagger_v2/params_example_spec.rb +38 -0
- data/spec/swagger_v2/params_hash_spec.rb +77 -0
- data/spec/swagger_v2/params_nested_spec.rb +92 -0
- data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
- data/spec/swagger_v2/reference_entity_spec.rb +129 -0
- data/spec/swagger_v2/security_requirement_spec.rb +46 -0
- data/spec/swagger_v2/simple_mounted_api_spec.rb +332 -0
- data/spec/version_spec.rb +10 -0
- metadata +225 -0
@@ -0,0 +1,122 @@
|
|
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
|
@@ -0,0 +1,78 @@
|
|
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
|
@@ -0,0 +1,121 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,82 @@
|
|
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
|
+
desc 'action' do
|
11
|
+
consumes ['application/x-www-form-urlencoded']
|
12
|
+
end
|
13
|
+
params do
|
14
|
+
if Grape::VERSION < '0.14'
|
15
|
+
requires :input, type: [String, Integer]
|
16
|
+
else
|
17
|
+
requires :input, types: [String, Integer]
|
18
|
+
end
|
19
|
+
requires :another_input, type: [String, Integer]
|
20
|
+
end
|
21
|
+
post :action do
|
22
|
+
{ message: 'hi' }
|
23
|
+
end
|
24
|
+
|
25
|
+
add_swagger_documentation
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
subject do
|
30
|
+
get '/swagger_doc/action'
|
31
|
+
expect(last_response.status).to eq 200
|
32
|
+
body = JSON.parse last_response.body
|
33
|
+
body['paths']['/action']['post']['parameters']
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'reads param type correctly' do
|
37
|
+
expect(subject).to eq [
|
38
|
+
{
|
39
|
+
'in' => 'formData',
|
40
|
+
'name' => 'input',
|
41
|
+
'type' => 'string',
|
42
|
+
'required' => true
|
43
|
+
},
|
44
|
+
{
|
45
|
+
'in' => 'formData',
|
46
|
+
'name' => 'another_input',
|
47
|
+
'type' => 'string',
|
48
|
+
'required' => true
|
49
|
+
}
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'header params' do
|
54
|
+
def app
|
55
|
+
Class.new(Grape::API) do
|
56
|
+
format :json
|
57
|
+
|
58
|
+
desc 'Some API',
|
59
|
+
consumes: ['application/x-www-form-urlencoded'],
|
60
|
+
headers: { 'My-Header' => { required: true, description: 'Set this!' } }
|
61
|
+
params do
|
62
|
+
if Grape::VERSION < '0.14'
|
63
|
+
requires :input, type: [String, Integer]
|
64
|
+
else
|
65
|
+
requires :input, types: [String, Integer]
|
66
|
+
end
|
67
|
+
requires :another_input, type: [String, Integer]
|
68
|
+
end
|
69
|
+
post :action do
|
70
|
+
{ message: 'hi' }
|
71
|
+
end
|
72
|
+
|
73
|
+
add_swagger_documentation
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has consistent types' do
|
78
|
+
types = subject.map { |param| param['type'] }
|
79
|
+
expect(types).to eq(%w[string string string])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,95 @@
|
|
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
|
+
desc 'action' do
|
11
|
+
consumes ['application/x-www-form-urlencoded']
|
12
|
+
end
|
13
|
+
params do
|
14
|
+
requires :input, type: String
|
15
|
+
end
|
16
|
+
post :action do
|
17
|
+
{ message: 'hi' }
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'action_with_doc' do
|
21
|
+
consumes ['application/x-www-form-urlencoded']
|
22
|
+
end
|
23
|
+
params do
|
24
|
+
requires :input, type: String, default: '14', documentation: { type: 'email', default: '42' }
|
25
|
+
end
|
26
|
+
post :action_with_doc do
|
27
|
+
{ message: 'hi' }
|
28
|
+
end
|
29
|
+
|
30
|
+
add_swagger_documentation
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'with no documentation hash' do
|
34
|
+
subject do
|
35
|
+
get '/swagger_doc/action'
|
36
|
+
expect(last_response.status).to eq 200
|
37
|
+
body = JSON.parse last_response.body
|
38
|
+
body['paths']['/action']['post']['parameters']
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'reads param type correctly' do
|
42
|
+
expect(subject).to eq [{
|
43
|
+
'in' => 'formData',
|
44
|
+
'name' => 'input',
|
45
|
+
'type' => 'string',
|
46
|
+
'required' => true
|
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',
|
56
|
+
consumes: ['application/x-www-form-urlencoded'],
|
57
|
+
headers: { 'My-Header' => { required: true, description: 'Set this!' } }
|
58
|
+
params do
|
59
|
+
requires :input, type: String
|
60
|
+
end
|
61
|
+
post :action do
|
62
|
+
{ message: 'hi' }
|
63
|
+
end
|
64
|
+
|
65
|
+
add_swagger_documentation
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'has consistent types' do
|
70
|
+
types = subject.map { |param| param['type'] }
|
71
|
+
expect(types).to eq(%w[string string])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with documentation hash' do
|
77
|
+
subject do
|
78
|
+
get '/swagger_doc/action_with_doc'
|
79
|
+
expect(last_response.status).to eq 200
|
80
|
+
body = JSON.parse last_response.body
|
81
|
+
body['paths']['/action_with_doc']['post']['parameters']
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'reads param type correctly' do
|
85
|
+
expect(subject).to eq [{
|
86
|
+
'in' => 'formData',
|
87
|
+
'name' => 'input',
|
88
|
+
'type' => 'string',
|
89
|
+
'format' => 'email',
|
90
|
+
'default' => '42',
|
91
|
+
'required' => true
|
92
|
+
}]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|