gitlab-grape-swagger 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.github/dependabot.yml +20 -0
  4. data/.github/workflows/ci.yml +45 -0
  5. data/.gitignore +44 -0
  6. data/.gitlab-ci.yml +19 -0
  7. data/.rspec +3 -0
  8. data/.rubocop.yml +136 -0
  9. data/.rubocop_todo.yml +60 -0
  10. data/.ruby-gemset +1 -0
  11. data/CHANGELOG.md +671 -0
  12. data/CONTRIBUTING.md +126 -0
  13. data/Dangerfile +3 -0
  14. data/Gemfile +45 -0
  15. data/Gemfile.lock +249 -0
  16. data/LICENSE.txt +20 -0
  17. data/README.md +1772 -0
  18. data/RELEASING.md +82 -0
  19. data/Rakefile +20 -0
  20. data/UPGRADING.md +201 -0
  21. data/example/api/endpoints.rb +131 -0
  22. data/example/api/entities.rb +18 -0
  23. data/example/config.ru +42 -0
  24. data/example/example_requests.postman_collection +146 -0
  25. data/example/splines.png +0 -0
  26. data/example/swagger-example.png +0 -0
  27. data/grape-swagger.gemspec +23 -0
  28. data/lib/grape-swagger/doc_methods/build_model_definition.rb +68 -0
  29. data/lib/grape-swagger/doc_methods/data_type.rb +110 -0
  30. data/lib/grape-swagger/doc_methods/extensions.rb +101 -0
  31. data/lib/grape-swagger/doc_methods/file_params.rb +17 -0
  32. data/lib/grape-swagger/doc_methods/format_data.rb +53 -0
  33. data/lib/grape-swagger/doc_methods/headers.rb +20 -0
  34. data/lib/grape-swagger/doc_methods/move_params.rb +209 -0
  35. data/lib/grape-swagger/doc_methods/operation_id.rb +32 -0
  36. data/lib/grape-swagger/doc_methods/optional_object.rb +30 -0
  37. data/lib/grape-swagger/doc_methods/parse_params.rb +190 -0
  38. data/lib/grape-swagger/doc_methods/path_string.rb +52 -0
  39. data/lib/grape-swagger/doc_methods/produces_consumes.rb +15 -0
  40. data/lib/grape-swagger/doc_methods/status_codes.rb +21 -0
  41. data/lib/grape-swagger/doc_methods/tag_name_description.rb +34 -0
  42. data/lib/grape-swagger/doc_methods/version.rb +20 -0
  43. data/lib/grape-swagger/doc_methods.rb +142 -0
  44. data/lib/grape-swagger/endpoint/params_parser.rb +76 -0
  45. data/lib/grape-swagger/endpoint.rb +476 -0
  46. data/lib/grape-swagger/errors.rb +17 -0
  47. data/lib/grape-swagger/instance.rb +7 -0
  48. data/lib/grape-swagger/model_parsers.rb +42 -0
  49. data/lib/grape-swagger/rake/oapi_tasks.rb +135 -0
  50. data/lib/grape-swagger/version.rb +5 -0
  51. data/lib/grape-swagger.rb +174 -0
  52. data/spec/issues/267_nested_namespaces.rb +55 -0
  53. data/spec/issues/403_versions_spec.rb +124 -0
  54. data/spec/issues/427_entity_as_string_spec.rb +39 -0
  55. data/spec/issues/430_entity_definitions_spec.rb +94 -0
  56. data/spec/issues/532_allow_custom_format_spec.rb +42 -0
  57. data/spec/issues/533_specify_status_code_spec.rb +78 -0
  58. data/spec/issues/537_enum_values_spec.rb +50 -0
  59. data/spec/issues/539_array_post_body_spec.rb +65 -0
  60. data/spec/issues/542_array_of_type_in_post_body_spec.rb +46 -0
  61. data/spec/issues/553_align_array_put_post_params_spec.rb +152 -0
  62. data/spec/issues/572_array_post_body_spec.rb +51 -0
  63. data/spec/issues/579_align_put_post_parameters_spec.rb +185 -0
  64. data/spec/issues/582_file_response_spec.rb +55 -0
  65. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
  66. data/spec/issues/605_root_route_documentation_spec.rb +23 -0
  67. data/spec/issues/650_params_array_spec.rb +65 -0
  68. data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +100 -0
  69. data/spec/issues/680_keep_204_error_schemas_spec.rb +55 -0
  70. data/spec/issues/721_set_default_parameter_location_based_on_consumes_spec.rb +62 -0
  71. data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
  72. data/spec/issues/776_multiple_presents_spec.rb +59 -0
  73. data/spec/issues/784_extensions_on_params_spec.rb +42 -0
  74. data/spec/issues/809_utf8_routes_spec.rb +55 -0
  75. data/spec/issues/832_array_hash_float_decimal_spec.rb +114 -0
  76. data/spec/issues/847_route_param_options_spec.rb +37 -0
  77. data/spec/issues/873_wildcard_segments_path_parameters_spec.rb +28 -0
  78. data/spec/issues/878_optional_path_segments_spec.rb +29 -0
  79. data/spec/issues/881_handle_file_params_spec.rb +38 -0
  80. data/spec/issues/883_query_array_parameter_spec.rb +46 -0
  81. data/spec/issues/884_dont_document_non_schema_examples_spec.rb +49 -0
  82. data/spec/issues/887_prevent_duplicate_operation_ids_spec.rb +35 -0
  83. data/spec/lib/data_type_spec.rb +111 -0
  84. data/spec/lib/endpoint/params_parser_spec.rb +124 -0
  85. data/spec/lib/endpoint_spec.rb +153 -0
  86. data/spec/lib/extensions_spec.rb +185 -0
  87. data/spec/lib/format_data_spec.rb +115 -0
  88. data/spec/lib/model_parsers_spec.rb +104 -0
  89. data/spec/lib/move_params_spec.rb +444 -0
  90. data/spec/lib/oapi_tasks_spec.rb +163 -0
  91. data/spec/lib/operation_id_spec.rb +55 -0
  92. data/spec/lib/optional_object_spec.rb +47 -0
  93. data/spec/lib/parse_params_spec.rb +68 -0
  94. data/spec/lib/path_string_spec.rb +101 -0
  95. data/spec/lib/produces_consumes_spec.rb +116 -0
  96. data/spec/lib/tag_name_description_spec.rb +80 -0
  97. data/spec/lib/version_spec.rb +28 -0
  98. data/spec/spec_helper.rb +39 -0
  99. data/spec/support/empty_model_parser.rb +23 -0
  100. data/spec/support/grape_version.rb +13 -0
  101. data/spec/support/mock_parser.rb +23 -0
  102. data/spec/support/model_parsers/entity_parser.rb +334 -0
  103. data/spec/support/model_parsers/mock_parser.rb +346 -0
  104. data/spec/support/model_parsers/representable_parser.rb +406 -0
  105. data/spec/support/namespace_tags.rb +93 -0
  106. data/spec/support/the_paths_definitions.rb +109 -0
  107. data/spec/swagger_v2/api_documentation_spec.rb +42 -0
  108. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
  109. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +48 -0
  110. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +36 -0
  111. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +79 -0
  112. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +145 -0
  113. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +137 -0
  114. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +56 -0
  115. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +64 -0
  116. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +58 -0
  117. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +57 -0
  118. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +109 -0
  119. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +48 -0
  120. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +153 -0
  121. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +355 -0
  122. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +217 -0
  123. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +247 -0
  124. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +80 -0
  125. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +147 -0
  126. data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +135 -0
  127. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +216 -0
  128. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +53 -0
  129. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
  130. data/spec/swagger_v2/api_swagger_v2_spec.rb +245 -0
  131. data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +93 -0
  132. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +90 -0
  133. data/spec/swagger_v2/boolean_params_spec.rb +38 -0
  134. data/spec/swagger_v2/default_api_spec.rb +175 -0
  135. data/spec/swagger_v2/deprecated_field_spec.rb +25 -0
  136. data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
  137. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +130 -0
  138. data/spec/swagger_v2/errors_spec.rb +77 -0
  139. data/spec/swagger_v2/float_api_spec.rb +36 -0
  140. data/spec/swagger_v2/form_params_spec.rb +76 -0
  141. data/spec/swagger_v2/grape-swagger_spec.rb +17 -0
  142. data/spec/swagger_v2/guarded_endpoint_spec.rb +162 -0
  143. data/spec/swagger_v2/hide_api_spec.rb +147 -0
  144. data/spec/swagger_v2/host_spec.rb +43 -0
  145. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +57 -0
  146. data/spec/swagger_v2/mount_override_api_spec.rb +58 -0
  147. data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
  148. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +122 -0
  149. data/spec/swagger_v2/namespace_tags_spec.rb +78 -0
  150. data/spec/swagger_v2/namespaced_api_spec.rb +121 -0
  151. data/spec/swagger_v2/nicknamed_api_spec.rb +25 -0
  152. data/spec/swagger_v2/operation_id_api_spec.rb +27 -0
  153. data/spec/swagger_v2/param_multi_type_spec.rb +82 -0
  154. data/spec/swagger_v2/param_type_spec.rb +95 -0
  155. data/spec/swagger_v2/param_values_spec.rb +180 -0
  156. data/spec/swagger_v2/params_array_collection_format_spec.rb +105 -0
  157. data/spec/swagger_v2/params_array_spec.rb +225 -0
  158. data/spec/swagger_v2/params_example_spec.rb +38 -0
  159. data/spec/swagger_v2/params_hash_spec.rb +77 -0
  160. data/spec/swagger_v2/params_nested_spec.rb +92 -0
  161. data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
  162. data/spec/swagger_v2/reference_entity_spec.rb +129 -0
  163. data/spec/swagger_v2/security_requirement_spec.rb +46 -0
  164. data/spec/swagger_v2/simple_mounted_api_spec.rb +332 -0
  165. data/spec/version_spec.rb +10 -0
  166. metadata +225 -0
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'headers' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ before :all do
9
+ module TheApi
10
+ class HeadersApi < Grape::API
11
+ format :json
12
+
13
+ desc 'This returns something',
14
+ failure: [{ code: 400, model: Entities::ApiError }],
15
+ headers: {
16
+ 'X-Rate-Limit-Limit' => {
17
+ 'description' => 'The number of allowed requests in the current period',
18
+ 'type' => 'integer'
19
+ }
20
+ },
21
+
22
+ entity: Entities::UseResponse
23
+ params do
24
+ optional :param_x, type: String, desc: 'This is a parameter', documentation: { param_type: 'query' }
25
+ end
26
+ get '/use_headers' do
27
+ { 'declared_params' => declared(params) }
28
+ end
29
+
30
+ add_swagger_documentation
31
+ end
32
+ end
33
+ end
34
+
35
+ def app
36
+ TheApi::HeadersApi
37
+ end
38
+
39
+ subject do
40
+ get '/swagger_doc'
41
+ JSON.parse(last_response.body)
42
+ end
43
+
44
+ specify do
45
+ parameters = subject['paths']['/use_headers']['get']['parameters']
46
+ expect(parameters).to include(
47
+ 'in' => 'header',
48
+ 'name' => 'X-Rate-Limit-Limit',
49
+ 'description' => 'The number of allowed requests in the current period',
50
+ 'type' => 'integer',
51
+ 'format' => 'int32',
52
+ 'required' => false
53
+ )
54
+ expect(parameters.size).to eq(2)
55
+ expect(parameters.first['in']).to eq('header')
56
+ expect(parameters.last['in']).to eq('query')
57
+ end
58
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'hide documentation path' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ before :all do
9
+ module TheApi
10
+ class HideDocumentationApi < Grape::API
11
+ format :json
12
+
13
+ desc 'This returns something',
14
+ params: Entities::UseResponse.documentation,
15
+ failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
16
+ params do
17
+ requires :foo, type: Integer
18
+ end
19
+ get '/params_response' do
20
+ { 'declared_params' => declared(params) }
21
+ end
22
+
23
+ desc 'This returns something',
24
+ entity: Entities::UseResponse,
25
+ failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
26
+ get '/entity_response' do
27
+ { 'declared_params' => declared(params) }
28
+ end
29
+
30
+ desc 'This returns something',
31
+ failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
32
+ get '/present_response' do
33
+ foo = OpenStruct.new id: 1, name: 'bar'
34
+ something = OpenStruct.new description: 'something', item: foo
35
+ present :somethings, something, with: Entities::UseResponse
36
+ end
37
+
38
+ add_swagger_documentation hide_documentation_path: false
39
+ end
40
+ end
41
+ end
42
+
43
+ def app
44
+ TheApi::HideDocumentationApi
45
+ end
46
+
47
+ describe 'shows documentation paths' do
48
+ subject do
49
+ get '/swagger_doc'
50
+ JSON.parse(last_response.body)
51
+ end
52
+
53
+ specify do
54
+ expect(subject['paths'].keys).to include '/swagger_doc', '/swagger_doc/{name}'
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'hidden flag enables a single endpoint parameter to be excluded from the documentation' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+ before :all do
8
+ module TheApi
9
+ class HideParamsApi < Grape::API
10
+ helpers do
11
+ def resource_owner
12
+ '123'
13
+ end
14
+ end
15
+
16
+ namespace :flat_params_endpoint do
17
+ desc 'This is a endpoint with a flat parameter hierarchy' do
18
+ consumes ['application/x-www-form-urlencoded']
19
+ end
20
+ params do
21
+ requires :name, type: String, documentation: { desc: 'name' }
22
+ optional :favourite_color, type: String, documentation: { desc: 'I should not be anywhere', hidden: true }
23
+ optional :proc_param, type: String, documentation: { desc: 'I should not be anywhere', hidden: proc { true } }
24
+ optional :proc_with_token, type: String, documentation: { desc: 'I may be somewhere', hidden: proc { false } }
25
+ end
26
+
27
+ post do
28
+ { 'declared_params' => declared(params) }
29
+ end
30
+ end
31
+
32
+ namespace :nested_params_endpoint do
33
+ desc 'This is a endpoint with a nested parameter hierarchy' do
34
+ consumes ['application/x-www-form-urlencoded']
35
+ end
36
+ params do
37
+ optional :name, type: String, documentation: { desc: 'name' }
38
+ optional :hidden_attribute, type: Hash do
39
+ optional :favourite_color, type: String, documentation: { desc: 'I should not be anywhere', hidden: true }
40
+ end
41
+
42
+ optional :attributes, type: Hash do
43
+ optional :attribute_1, type: String, documentation: { desc: 'Attribute one' }
44
+ optional :hidden_attribute, type: String, documentation: { desc: 'I should not be anywhere', hidden: true }
45
+ end
46
+ end
47
+
48
+ post do
49
+ { 'declared_params' => declared(params) }
50
+ end
51
+ end
52
+
53
+ namespace :required_param_endpoint do
54
+ desc 'This endpoint has hidden defined for a required parameter' do
55
+ consumes ['application/x-www-form-urlencoded']
56
+ end
57
+ params do
58
+ requires :name, type: String, documentation: { desc: 'name', hidden: true }
59
+ end
60
+
61
+ post do
62
+ { 'declared_params' => declared(params) }
63
+ end
64
+ end
65
+
66
+ add_swagger_documentation token_owner: 'resource_owner'
67
+ end
68
+ end
69
+ end
70
+
71
+ let(:app) { TheApi::HideParamsApi }
72
+
73
+ describe 'simple flat parameter hierarchy' do
74
+ subject do
75
+ get '/swagger_doc/flat_params_endpoint'
76
+ JSON.parse(last_response.body)
77
+ end
78
+
79
+ it 'ignores parameters that are explicitly hidden' do
80
+ expect(subject['paths']['/flat_params_endpoint']['post']['parameters'].map { |p| p['name'] }).not_to include('favourite_color', 'proc_param')
81
+ end
82
+
83
+ it 'allows procs to consult the token_owner' do
84
+ expect(subject['paths']['/flat_params_endpoint']['post']['parameters'].map { |p| p['name'] }).to include('proc_with_token')
85
+ end
86
+ end
87
+
88
+ describe 'nested parameter hierarchy' do
89
+ subject do
90
+ get '/swagger_doc/nested_params_endpoint'
91
+ JSON.parse(last_response.body)
92
+ end
93
+
94
+ specify do
95
+ expect(subject['paths']['/nested_params_endpoint']['post']['parameters'].map { |p| p['name'] }).not_to include(/hidden_attribute/)
96
+ end
97
+ end
98
+
99
+ describe 'hidden defined for required parameter' do
100
+ subject do
101
+ get '/swagger_doc/required_param_endpoint'
102
+ JSON.parse(last_response.body)
103
+ end
104
+
105
+ specify do
106
+ expect(subject['paths']['/required_param_endpoint']['post']['parameters'].map { |p| p['name'] }).to include('name')
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'swagger spec v2.0' do
6
+ include_context "#{MODEL_PARSER} swagger example"
7
+
8
+ def app
9
+ Class.new(Grape::API) do
10
+ format :json
11
+
12
+ desc 'This creates Thing after a delay',
13
+ success: { code: 202, message: 'OK', model: Entities::Something }
14
+ params do
15
+ requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' }
16
+ requires :links, type: Array, documentation: { type: 'link', is_array: true }
17
+ end
18
+ post '/delay_thing' do
19
+ status 202
20
+ end
21
+
22
+ version 'v3', using: :path
23
+ add_swagger_documentation api_version: 'v1',
24
+ base_path: '/api',
25
+ info: {
26
+ title: 'The API title to be displayed on the API homepage.',
27
+ description: 'A description of the API.',
28
+ contact_name: 'Contact name',
29
+ contact_email: 'Contact@email.com',
30
+ contact_url: 'Contact URL',
31
+ license: 'The name of the license.',
32
+ license_url: 'www.The-URL-of-the-license.org',
33
+ terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com'
34
+ }
35
+ end
36
+ end
37
+
38
+ before do
39
+ get '/v3/swagger_doc'
40
+ end
41
+
42
+ let(:json) { JSON.parse(last_response.body) }
43
+
44
+ it 'only returns one response if ignore_defaults is specified' do
45
+ expect(json['paths']['/delay_thing']['post']['responses']).to eq('202' => { 'description' => 'OK', 'schema' => { '$ref' => '#/definitions/Something' } })
46
+ expect(json['paths']['/delay_thing']['post']['responses'].keys).not_to include '201'
47
+ end
48
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'swagger spec v2.0' do
6
+ describe 'mounted APIs' do
7
+ include_context "#{MODEL_PARSER} swagger example"
8
+
9
+ def app
10
+ Class.new(Grape::API) do
11
+ format :json
12
+
13
+ # Thing stuff
14
+ desc 'This gets Things.' do
15
+ consumes ['application/x-www-form-urlencoded']
16
+ params Entities::Something.documentation
17
+ http_codes [{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
18
+ end
19
+ get '/thing' do
20
+ something = OpenStruct.new text: 'something'
21
+ present something, with: Entities::Something
22
+ end
23
+
24
+ desc 'This gets Things.' do
25
+ consumes ['application/x-www-form-urlencoded']
26
+ http_codes [
27
+ { code: 200, message: 'get Horses', model: Entities::Something },
28
+ { code: 401, message: 'HorsesOutError', model: Entities::ApiError }
29
+ ]
30
+ end
31
+ get '/thing2' do
32
+ something = OpenStruct.new text: 'something'
33
+ present something, with: Entities::Something
34
+ end
35
+
36
+ desc 'This gets Thing.' do
37
+ consumes ['application/x-www-form-urlencoded']
38
+ http_codes [{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
39
+ end
40
+ params do
41
+ requires :id, type: Integer
42
+ end
43
+ get '/thing/:id' do
44
+ something = OpenStruct.new text: 'something'
45
+ present something, with: Entities::Something
46
+ end
47
+
48
+ desc 'This creates Thing.',
49
+ consumes: ['application/x-www-form-urlencoded'],
50
+ success: Entities::Something
51
+ params do
52
+ requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' }
53
+ requires :links, type: Array, documentation: { type: 'link', is_array: true }
54
+ end
55
+ post '/thing', http_codes: [{ code: 422, message: 'Unprocessible Entity' }] do
56
+ something = OpenStruct.new text: 'something'
57
+ present something, with: Entities::Something
58
+ end
59
+
60
+ desc 'This updates Thing.',
61
+ consumes: ['application/x-www-form-urlencoded'],
62
+ success: Entities::Something
63
+ params do
64
+ requires :id, type: Integer
65
+ optional :text, type: String, desc: 'Content of something.'
66
+ optional :links, type: Array, documentation: { type: 'link', is_array: true }
67
+ end
68
+ put '/thing/:id' do
69
+ something = OpenStruct.new text: 'something'
70
+ present something, with: Entities::Something
71
+ end
72
+
73
+ desc 'This deletes Thing.',
74
+ consumes: ['application/x-www-form-urlencoded'],
75
+ entity: Entities::Something
76
+ params do
77
+ requires :id, type: Integer
78
+ end
79
+ delete '/thing/:id' do
80
+ something = OpenStruct.new text: 'something'
81
+ present something, with: Entities::Something
82
+ end
83
+
84
+ desc 'dummy route.',
85
+ consumes: ['application/x-www-form-urlencoded'],
86
+ failure: [{ code: 401, message: 'Unauthorized' }]
87
+ params do
88
+ requires :id, type: Integer
89
+ end
90
+ delete '/dummy/:id' do
91
+ {}
92
+ end
93
+
94
+ namespace :other_thing do
95
+ desc 'nested route inside namespace',
96
+ consumes: ['application/x-www-form-urlencoded'],
97
+ entity: Entities::QueryInput,
98
+ x: {
99
+ 'amazon-apigateway-auth' => { type: 'none' },
100
+ 'amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
101
+ }
102
+
103
+ params do
104
+ requires :elements, documentation: {
105
+ type: 'QueryInputElement',
106
+ desc: 'Set of configuration',
107
+ param_type: 'body',
108
+ is_array: true,
109
+ required: true
110
+ }
111
+ end
112
+ get '/:elements' do
113
+ present something, with: Entities::QueryInput
114
+ end
115
+ end
116
+
117
+ version 'v3', using: :path
118
+ add_swagger_documentation base_path: '/api',
119
+ info: {
120
+ title: 'The API title to be displayed on the API homepage.',
121
+ description: 'A description of the API.',
122
+ contact_name: 'Contact name',
123
+ contact_email: 'Contact@email.com',
124
+ contact_url: 'Contact URL',
125
+ license: 'The name of the license.',
126
+ license_url: 'www.The-URL-of-the-license.org',
127
+ terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com'
128
+ }
129
+ end
130
+ end
131
+
132
+ mounted_paths.each do |expected_path|
133
+ describe "documents only #{expected_path} paths" do
134
+ let(:mount_path) { "/v3/swagger_doc#{expected_path}" }
135
+ subject do
136
+ get mount_path
137
+ JSON.parse(last_response.body)['paths']
138
+ end
139
+
140
+ specify do
141
+ unexpected_paths = mounted_paths - [expected_path]
142
+ subject.each_key do |path|
143
+ unexpected_paths.each do |unexpected_path|
144
+ expect(path).not_to start_with unexpected_path
145
+ end
146
+ expect(path).to start_with(expected_path).or include(expected_path)
147
+ expect(subject[path]).to eql swagger_json['paths'][path]
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end