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.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/README.md +1 -0
  4. data/grape-swagger.gemspec +5 -5
  5. data/lib/grape-swagger/doc_methods/extensions.rb +2 -1
  6. data/lib/grape-swagger/doc_methods/move_params.rb +1 -0
  7. data/lib/grape-swagger/endpoint.rb +1 -1
  8. data/lib/grape-swagger/version.rb +1 -1
  9. metadata +26 -129
  10. data/.coveralls.yml +0 -1
  11. data/.github/dependabot.yml +0 -20
  12. data/.github/workflows/ci.yml +0 -120
  13. data/.gitignore +0 -45
  14. data/.rspec +0 -3
  15. data/.rubocop.yml +0 -136
  16. data/.rubocop_todo.yml +0 -45
  17. data/Dangerfile +0 -3
  18. data/Gemfile +0 -43
  19. data/Rakefile +0 -20
  20. data/example/api/endpoints.rb +0 -131
  21. data/example/api/entities.rb +0 -18
  22. data/example/config.ru +0 -42
  23. data/example/example_requests.postman_collection +0 -146
  24. data/example/splines.png +0 -0
  25. data/example/swagger-example.png +0 -0
  26. data/spec/issues/267_nested_namespaces.rb +0 -55
  27. data/spec/issues/403_versions_spec.rb +0 -124
  28. data/spec/issues/427_entity_as_string_spec.rb +0 -39
  29. data/spec/issues/430_entity_definitions_spec.rb +0 -94
  30. data/spec/issues/532_allow_custom_format_spec.rb +0 -38
  31. data/spec/issues/533_specify_status_code_spec.rb +0 -78
  32. data/spec/issues/537_enum_values_spec.rb +0 -50
  33. data/spec/issues/539_array_post_body_spec.rb +0 -65
  34. data/spec/issues/542_array_of_type_in_post_body_spec.rb +0 -46
  35. data/spec/issues/553_align_array_put_post_params_spec.rb +0 -144
  36. data/spec/issues/572_array_post_body_spec.rb +0 -51
  37. data/spec/issues/579_align_put_post_parameters_spec.rb +0 -179
  38. data/spec/issues/582_file_response_spec.rb +0 -55
  39. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +0 -26
  40. data/spec/issues/605_root_route_documentation_spec.rb +0 -23
  41. data/spec/issues/650_params_array_spec.rb +0 -59
  42. data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +0 -100
  43. data/spec/issues/680_keep_204_error_schemas_spec.rb +0 -55
  44. data/spec/issues/751_deeply_nested_objects_spec.rb +0 -190
  45. data/spec/issues/776_multiple_presents_spec.rb +0 -59
  46. data/spec/issues/784_extensions_on_params_spec.rb +0 -38
  47. data/spec/issues/809_utf8_routes_spec.rb +0 -55
  48. data/spec/issues/832_array_hash_float_decimal_spec.rb +0 -111
  49. data/spec/issues/847_route_param_options_spec.rb +0 -37
  50. data/spec/lib/data_type_spec.rb +0 -111
  51. data/spec/lib/endpoint/params_parser_spec.rb +0 -124
  52. data/spec/lib/endpoint_spec.rb +0 -153
  53. data/spec/lib/extensions_spec.rb +0 -185
  54. data/spec/lib/format_data_spec.rb +0 -115
  55. data/spec/lib/model_parsers_spec.rb +0 -104
  56. data/spec/lib/move_params_spec.rb +0 -444
  57. data/spec/lib/oapi_tasks_spec.rb +0 -163
  58. data/spec/lib/operation_id_spec.rb +0 -55
  59. data/spec/lib/optional_object_spec.rb +0 -47
  60. data/spec/lib/parse_params_spec.rb +0 -82
  61. data/spec/lib/path_string_spec.rb +0 -101
  62. data/spec/lib/produces_consumes_spec.rb +0 -116
  63. data/spec/lib/tag_name_description_spec.rb +0 -80
  64. data/spec/lib/version_spec.rb +0 -28
  65. data/spec/spec_helper.rb +0 -39
  66. data/spec/support/empty_model_parser.rb +0 -23
  67. data/spec/support/grape_version.rb +0 -13
  68. data/spec/support/mock_parser.rb +0 -23
  69. data/spec/support/model_parsers/entity_parser.rb +0 -334
  70. data/spec/support/model_parsers/mock_parser.rb +0 -346
  71. data/spec/support/model_parsers/representable_parser.rb +0 -406
  72. data/spec/support/namespace_tags.rb +0 -93
  73. data/spec/support/the_paths_definitions.rb +0 -109
  74. data/spec/swagger_v2/api_documentation_spec.rb +0 -26
  75. data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +0 -83
  76. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +0 -48
  77. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +0 -36
  78. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +0 -79
  79. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +0 -145
  80. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +0 -137
  81. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +0 -56
  82. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +0 -64
  83. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +0 -58
  84. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +0 -57
  85. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +0 -103
  86. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +0 -48
  87. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +0 -145
  88. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +0 -355
  89. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +0 -217
  90. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +0 -239
  91. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +0 -72
  92. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +0 -143
  93. data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +0 -135
  94. data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +0 -216
  95. data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +0 -55
  96. data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +0 -153
  97. data/spec/swagger_v2/api_swagger_v2_spec.rb +0 -237
  98. data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +0 -93
  99. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +0 -89
  100. data/spec/swagger_v2/boolean_params_spec.rb +0 -35
  101. data/spec/swagger_v2/default_api_spec.rb +0 -175
  102. data/spec/swagger_v2/deprecated_field_spec.rb +0 -25
  103. data/spec/swagger_v2/description_not_initialized_spec.rb +0 -39
  104. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +0 -130
  105. data/spec/swagger_v2/errors_spec.rb +0 -77
  106. data/spec/swagger_v2/float_api_spec.rb +0 -33
  107. data/spec/swagger_v2/form_params_spec.rb +0 -67
  108. data/spec/swagger_v2/grape-swagger_spec.rb +0 -17
  109. data/spec/swagger_v2/guarded_endpoint_spec.rb +0 -162
  110. data/spec/swagger_v2/hide_api_spec.rb +0 -147
  111. data/spec/swagger_v2/host_spec.rb +0 -43
  112. data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +0 -57
  113. data/spec/swagger_v2/mount_override_api_spec.rb +0 -58
  114. data/spec/swagger_v2/mounted_target_class_spec.rb +0 -76
  115. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +0 -122
  116. data/spec/swagger_v2/namespace_tags_spec.rb +0 -78
  117. data/spec/swagger_v2/namespaced_api_spec.rb +0 -121
  118. data/spec/swagger_v2/nicknamed_api_spec.rb +0 -25
  119. data/spec/swagger_v2/operation_id_api_spec.rb +0 -27
  120. data/spec/swagger_v2/param_multi_type_spec.rb +0 -77
  121. data/spec/swagger_v2/param_type_spec.rb +0 -87
  122. data/spec/swagger_v2/param_values_spec.rb +0 -162
  123. data/spec/swagger_v2/params_array_collection_format_spec.rb +0 -105
  124. data/spec/swagger_v2/params_array_spec.rb +0 -203
  125. data/spec/swagger_v2/params_example_spec.rb +0 -40
  126. data/spec/swagger_v2/params_hash_spec.rb +0 -71
  127. data/spec/swagger_v2/params_nested_spec.rb +0 -86
  128. data/spec/swagger_v2/parent_less_namespace_spec.rb +0 -32
  129. data/spec/swagger_v2/reference_entity_spec.rb +0 -129
  130. data/spec/swagger_v2/security_requirement_spec.rb +0 -46
  131. data/spec/swagger_v2/simple_mounted_api_spec.rb +0 -326
  132. data/spec/version_spec.rb +0 -10
@@ -1,216 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'response with headers' do
6
- # include_context "#{MODEL_PARSER} swagger header"
7
-
8
- before :all do
9
- module TheApi
10
- class ResponseApiHeaders < Grape::API
11
- format :json
12
-
13
- desc 'This returns headers' do
14
- success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
15
- failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
16
- end
17
- get '/response_headers' do
18
- { 'declared_params' => declared(params) }
19
- end
20
-
21
- desc 'A 204 can have headers too' do
22
- foo = { status: 204, message: 'No content', headers: { 'Location' => { description: 'Location of resource', type: 'string' } } }
23
- success foo
24
- failure [[400, 'Bad Request', Entities::ApiError, { 'application/json' => { code: 400, message: 'Bad request' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
25
- end
26
- delete '/no_content_response_headers' do
27
- { 'declared_params' => declared(params) }
28
- end
29
-
30
- desc 'A file can have headers too' do
31
- foo = { status: 200, model: 'File', headers: { 'Cache-Control': { description: 'Directive for caching', type: 'string' } } }
32
- success foo
33
- failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
34
- end
35
- get '/file_response_headers' do
36
- { 'declared_params' => declared(params) }
37
- end
38
-
39
- desc 'This syntax also returns headers' do
40
- success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
41
- failure [
42
- {
43
- code: 404,
44
- message: 'NotFound',
45
- model: Entities::ApiError,
46
- headers: { 'Date' => { description: 'Date of failure', type: 'string' } }
47
- },
48
- {
49
- code: 400,
50
- message: 'BadRequest',
51
- model: Entities::ApiError,
52
- headers: { 'Date' => { description: 'Date of failure', type: 'string' } }
53
- }
54
- ]
55
- end
56
- get '/response_failure_headers' do
57
- { 'declared_params' => declared(params) }
58
- end
59
-
60
- desc 'This does not return headers' do
61
- success model: Entities::UseResponse
62
- failure [[404, 'NotFound', Entities::ApiError]]
63
- end
64
- get '/response_no_headers' do
65
- { 'declared_params' => declared(params) }
66
- end
67
- add_swagger_documentation
68
- end
69
- end
70
- end
71
-
72
- def app
73
- TheApi::ResponseApiHeaders
74
- end
75
-
76
- describe 'response headers' do
77
- let(:header_200) do
78
- { 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
79
- end
80
- let(:header_404) do
81
- { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
82
- end
83
- let(:examples_404) do
84
- { 'application/json' => { 'code' => 404, 'message' => 'Not found' } }
85
- end
86
-
87
- subject do
88
- get '/swagger_doc/response_headers'
89
- JSON.parse(last_response.body)
90
- end
91
-
92
- specify do
93
- expect(subject['paths']['/response_headers']['get']).to eql(
94
- 'description' => 'This returns headers',
95
- 'produces' => ['application/json'],
96
- 'responses' => {
97
- '200' => { 'description' => 'This returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
98
- '404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404, 'headers' => header_404 }
99
- },
100
- 'tags' => ['response_headers'],
101
- 'operationId' => 'getResponseHeaders'
102
- )
103
- end
104
- end
105
-
106
- describe 'no content response headers' do
107
- let(:header_204) do
108
- { 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
109
- end
110
- let(:header_400) do
111
- { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
112
- end
113
- let(:examples_400) do
114
- { 'application/json' => { 'code' => 400, 'message' => 'Bad request' } }
115
- end
116
-
117
- subject do
118
- get '/swagger_doc/no_content_response_headers', {}
119
- JSON.parse(last_response.body)
120
- end
121
-
122
- specify do
123
- expect(subject['paths']['/no_content_response_headers']['delete']).to eql(
124
- 'description' => 'A 204 can have headers too',
125
- 'produces' => ['application/json'],
126
- 'responses' => {
127
- '204' => { 'description' => 'No content', 'headers' => header_204 },
128
- '400' => { 'description' => 'Bad Request', 'headers' => header_400, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_400 }
129
- },
130
- 'tags' => ['no_content_response_headers'],
131
- 'operationId' => 'deleteNoContentResponseHeaders'
132
- )
133
- end
134
- end
135
-
136
- describe 'file response headers' do
137
- let(:header_200) do
138
- { 'Cache-Control' => { 'description' => 'Directive for caching', 'type' => 'string' } }
139
- end
140
- let(:header_404) do
141
- { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
142
- end
143
- let(:examples_404) do
144
- { 'application/json' => { 'code' => 404, 'message' => 'Not found' } }
145
- end
146
-
147
- subject do
148
- get '/swagger_doc/file_response_headers'
149
- JSON.parse(last_response.body)
150
- end
151
-
152
- specify do
153
- expect(subject['paths']['/file_response_headers']['get']).to eql(
154
- 'description' => 'A file can have headers too',
155
- 'produces' => ['application/json'],
156
- 'responses' => {
157
- '200' => { 'description' => 'A file can have headers too', 'headers' => header_200, 'schema' => { 'type' => 'file' } },
158
- '404' => { 'description' => 'NotFound', 'headers' => header_404, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404 }
159
- },
160
- 'tags' => ['file_response_headers'],
161
- 'operationId' => 'getFileResponseHeaders'
162
- )
163
- end
164
- end
165
-
166
- describe 'response failure headers' do
167
- let(:header_200) do
168
- { 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
169
- end
170
- let(:header_404) do
171
- { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
172
- end
173
- let(:header_400) do
174
- { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
175
- end
176
-
177
- subject do
178
- get '/swagger_doc/response_failure_headers'
179
- JSON.parse(last_response.body)
180
- end
181
-
182
- specify do
183
- expect(subject['paths']['/response_failure_headers']['get']).to eql(
184
- 'description' => 'This syntax also returns headers',
185
- 'produces' => ['application/json'],
186
- 'responses' => {
187
- '200' => { 'description' => 'This syntax also returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
188
- '404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'headers' => header_404 },
189
- '400' => { 'description' => 'BadRequest', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'headers' => header_400 }
190
- },
191
- 'tags' => ['response_failure_headers'],
192
- 'operationId' => 'getResponseFailureHeaders'
193
- )
194
- end
195
- end
196
-
197
- describe 'response no headers' do
198
- subject do
199
- get '/swagger_doc/response_no_headers'
200
- JSON.parse(last_response.body)
201
- end
202
-
203
- specify do
204
- expect(subject['paths']['/response_no_headers']['get']).to eql(
205
- 'description' => 'This does not return headers',
206
- 'produces' => ['application/json'],
207
- 'responses' => {
208
- '200' => { 'description' => 'This does not return headers', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
209
- '404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
210
- },
211
- 'tags' => ['response_no_headers'],
212
- 'operationId' => 'getResponseNoHeaders'
213
- )
214
- end
215
- end
216
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'response' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ResponseApiModels < Grape::API
11
- format :json
12
-
13
- desc 'This returns something',
14
- success: [{ code: 200 }],
15
- failure: [
16
- { code: 400, message: 'NotFound', model: '' },
17
- { code: 404, message: 'BadRequest', model: Entities::ApiError }
18
- ],
19
- default_response: { message: 'Error', model: Entities::ApiError }
20
- get '/use-response' do
21
- { 'declared_params' => declared(params) }
22
- end
23
-
24
- add_swagger_documentation(models: [Entities::UseResponse])
25
- end
26
- end
27
- end
28
-
29
- def app
30
- TheApi::ResponseApiModels
31
- end
32
-
33
- describe 'uses entity as response object implicitly with route name' do
34
- subject do
35
- get '/swagger_doc/use-response'
36
- JSON.parse(last_response.body)
37
- end
38
-
39
- specify do
40
- expect(subject['paths']['/use-response']['get']).to eql(
41
- 'description' => 'This returns something',
42
- 'produces' => ['application/json'],
43
- 'responses' => {
44
- '200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
45
- '400' => { 'description' => 'NotFound' },
46
- '404' => { 'description' => 'BadRequest', 'schema' => { '$ref' => '#/definitions/ApiError' } },
47
- 'default' => { 'description' => 'Error', 'schema' => { '$ref' => '#/definitions/ApiError' } }
48
- },
49
- 'tags' => ['use-response'],
50
- 'operationId' => 'getUseResponse'
51
- )
52
- expect(subject['definitions']).to eql(swagger_entity_as_response_object)
53
- end
54
- end
55
- end
@@ -1,153 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'response with root' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ResponseApiWithRoot < Grape::API
11
- format :json
12
-
13
- desc 'This returns something',
14
- http_codes: [{ code: 200, model: Entities::Something }]
15
- get '/ordinary_response' do
16
- { 'declared_params' => declared(params) }
17
- end
18
-
19
- desc 'This returns something',
20
- is_array: true,
21
- http_codes: [{ code: 200, model: Entities::Something }]
22
- get '/response_with_array' do
23
- { 'declared_params' => declared(params) }
24
- end
25
-
26
- route_setting :swagger, root: true
27
- desc 'This returns something',
28
- http_codes: [{ code: 200, model: Entities::Something }]
29
- get '/response_with_root' do
30
- { 'declared_params' => declared(params) }
31
- end
32
-
33
- route_setting :swagger, root: true
34
- desc 'This returns underscored root',
35
- http_codes: [{ code: 200, model: Entities::ApiError }]
36
- get '/response_with_root_underscore' do
37
- { 'declared_params' => declared(params) }
38
- end
39
-
40
- route_setting :swagger, root: true
41
- desc 'This returns something',
42
- is_array: true,
43
- http_codes: [{ code: 200, model: Entities::Something }]
44
- get '/response_with_array_and_root' do
45
- { 'declared_params' => declared(params) }
46
- end
47
-
48
- route_setting :swagger, root: 'custom_root'
49
- desc 'This returns something',
50
- http_codes: [{ code: 200, model: Entities::Something }]
51
- get '/response_with_custom_root' do
52
- { 'declared_params' => declared(params) }
53
- end
54
-
55
- add_swagger_documentation
56
- end
57
- end
58
- end
59
-
60
- def app
61
- TheApi::ResponseApiWithRoot
62
- end
63
-
64
- describe 'GET /ordinary_response' do
65
- subject do
66
- get '/swagger_doc/ordinary_response'
67
- JSON.parse(last_response.body)
68
- end
69
-
70
- it 'does not add root or array' do
71
- schema = subject.dig('paths', '/ordinary_response', 'get', 'responses', '200', 'schema')
72
- expect(schema).to eq(
73
- '$ref' => '#/definitions/Something'
74
- )
75
- end
76
- end
77
-
78
- describe 'GET /response_with_array' do
79
- subject do
80
- get '/swagger_doc/response_with_array'
81
- JSON.parse(last_response.body)
82
- end
83
-
84
- it 'adds array to the response' do
85
- schema = subject.dig('paths', '/response_with_array', 'get', 'responses', '200', 'schema')
86
- expect(schema).to eq(
87
- 'type' => 'array', 'items' => { '$ref' => '#/definitions/Something' }
88
- )
89
- end
90
- end
91
-
92
- describe 'GET /response_with_root' do
93
- subject do
94
- get '/swagger_doc/response_with_root'
95
- JSON.parse(last_response.body)
96
- end
97
-
98
- it 'adds root to the response' do
99
- schema = subject.dig('paths', '/response_with_root', 'get', 'responses', '200', 'schema')
100
- expect(schema).to eq(
101
- 'type' => 'object',
102
- 'properties' => { 'something' => { '$ref' => '#/definitions/Something' } }
103
- )
104
- end
105
- end
106
-
107
- describe 'GET /response_with_root_underscore' do
108
- subject do
109
- get '/swagger_doc/response_with_root_underscore'
110
- JSON.parse(last_response.body)
111
- end
112
-
113
- it 'adds root to the response' do
114
- schema = subject.dig('paths', '/response_with_root_underscore', 'get', 'responses', '200', 'schema')
115
- expect(schema).to eq(
116
- 'type' => 'object',
117
- 'properties' => { 'api_error' => { '$ref' => '#/definitions/ApiError' } }
118
- )
119
- end
120
- end
121
-
122
- describe 'GET /response_with_array_and_root' do
123
- subject do
124
- get '/swagger_doc/response_with_array_and_root'
125
- JSON.parse(last_response.body)
126
- end
127
-
128
- it 'adds root and array to the response' do
129
- schema = subject.dig('paths', '/response_with_array_and_root', 'get', 'responses', '200', 'schema')
130
- expect(schema).to eq(
131
- 'type' => 'object',
132
- 'properties' => {
133
- 'somethings' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/Something' } }
134
- }
135
- )
136
- end
137
- end
138
-
139
- describe 'GET /response_with_custom_root' do
140
- subject do
141
- get '/swagger_doc/response_with_custom_root'
142
- JSON.parse(last_response.body)
143
- end
144
-
145
- it 'adds root to the response' do
146
- schema = subject.dig('paths', '/response_with_custom_root', 'get', 'responses', '200', 'schema')
147
- expect(schema).to eq(
148
- 'type' => 'object',
149
- 'properties' => { 'custom_root' => { '$ref' => '#/definitions/Something' } }
150
- )
151
- end
152
- end
153
- end
@@ -1,237 +0,0 @@
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
- # Thing stuff
13
- desc 'This gets Things.' do
14
- params Entities::Something.documentation
15
- http_codes [{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
16
- end
17
- get '/thing' do
18
- something = OpenStruct.new text: 'something'
19
- present something, with: Entities::Something
20
- end
21
-
22
- desc 'This gets Things.' do
23
- http_codes [
24
- { code: 200, message: 'get Horses', model: Entities::Something },
25
- { code: 401, message: 'HorsesOutError', model: Entities::ApiError }
26
- ]
27
- end
28
- get '/thing2' do
29
- something = OpenStruct.new text: 'something'
30
- present something, with: Entities::Something
31
- end
32
-
33
- desc 'This gets Thing.' do
34
- http_codes [{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
35
- end
36
- params do
37
- requires :id, type: Integer
38
- end
39
- get '/thing/:id' do
40
- something = OpenStruct.new text: 'something'
41
- present something, with: Entities::Something
42
- end
43
-
44
- desc 'This creates Thing.',
45
- success: Entities::Something
46
- params do
47
- requires :text, type: String, documentation: { type: 'string', desc: 'Content of something.' }
48
- requires :links, type: Array, documentation: { type: 'link', is_array: true }
49
- end
50
- post '/thing', http_codes: [{ code: 422, message: 'Unprocessible Entity' }] do
51
- something = OpenStruct.new text: 'something'
52
- present something, with: Entities::Something
53
- end
54
-
55
- desc 'This updates Thing.',
56
- success: Entities::Something
57
- params do
58
- requires :id, type: Integer
59
- optional :text, type: String, desc: 'Content of something.'
60
- optional :links, type: Array, documentation: { type: 'link', is_array: true }
61
- end
62
- put '/thing/:id' do
63
- something = OpenStruct.new text: 'something'
64
- present something, with: Entities::Something
65
- end
66
-
67
- desc 'This deletes Thing.',
68
- entity: Entities::Something
69
- params do
70
- requires :id, type: Integer
71
- end
72
- delete '/thing/:id' do
73
- something = OpenStruct.new text: 'something'
74
- present something, with: Entities::Something
75
- end
76
-
77
- desc 'dummy route.',
78
- failure: [{ code: 401, message: 'Unauthorized' }]
79
- params do
80
- requires :id, type: Integer
81
- end
82
- delete '/dummy/:id' do
83
- {}
84
- end
85
-
86
- namespace :other_thing do
87
- desc 'nested route inside namespace',
88
- entity: Entities::QueryInput,
89
- x: {
90
- 'amazon-apigateway-auth' => { type: 'none' },
91
- 'amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
92
- }
93
-
94
- params do
95
- requires :elements, documentation: {
96
- type: 'QueryInputElement',
97
- desc: 'Set of configuration',
98
- param_type: 'body',
99
- is_array: true,
100
- required: true
101
- }
102
- end
103
- get '/:elements' do
104
- present something, with: Entities::QueryInput
105
- end
106
- end
107
-
108
- version 'v3', using: :path
109
- add_swagger_documentation api_version: 'v1',
110
- base_path: '/api',
111
- info: {
112
- title: 'The API title to be displayed on the API homepage.',
113
- description: 'A description of the API.',
114
- contact_name: 'Contact name',
115
- contact_email: 'Contact@email.com',
116
- contact_url: 'Contact URL',
117
- license: 'The name of the license.',
118
- license_url: 'www.The-URL-of-the-license.org',
119
- terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com'
120
- }
121
- end
122
- end
123
-
124
- describe 'whole documentation' do
125
- subject do
126
- get '/v3/swagger_doc'
127
- JSON.parse(last_response.body)
128
- end
129
-
130
- describe 'swagger object' do
131
- describe 'required keys' do
132
- it { expect(subject.keys).to include 'swagger' }
133
- it { expect(subject['swagger']).to eql '2.0' }
134
- it { expect(subject.keys).to include 'info' }
135
- it { expect(subject['info']).to be_a Hash }
136
- it { expect(subject.keys).to include 'paths' }
137
- it { expect(subject['paths']).to be_a Hash }
138
- end
139
-
140
- describe 'info object required keys' do
141
- let(:info) { subject['info'] }
142
-
143
- it { expect(info.keys).to include 'title' }
144
- it { expect(info['title']).to be_a String }
145
- it { expect(info.keys).to include 'version' }
146
- it { expect(info['version']).to be_a String }
147
-
148
- describe 'license object' do
149
- let(:license) { subject['info']['license'] }
150
-
151
- it { expect(license.keys).to include 'name' }
152
- it { expect(license['name']).to be_a String }
153
- it { expect(license.keys).to include 'url' }
154
- it { expect(license['url']).to be_a String }
155
- end
156
-
157
- describe 'contact object' do
158
- let(:contact) { subject['info']['contact'] }
159
-
160
- it { expect(contact.keys).to include 'name' }
161
- it { expect(contact['name']).to be_a String }
162
- it { expect(contact.keys).to include 'email' }
163
- it { expect(contact['email']).to be_a String }
164
- it { expect(contact.keys).to include 'url' }
165
- it { expect(contact['url']).to be_a String }
166
- end
167
-
168
- describe 'global tags' do
169
- let(:tags) { subject['tags'] }
170
-
171
- it { expect(tags).to be_a Array }
172
- it { expect(tags).not_to be_empty }
173
- end
174
- end
175
-
176
- describe 'path object' do
177
- let(:paths) { subject['paths'] }
178
-
179
- it 'hides documentation paths per default' do
180
- expect(paths.keys).not_to include '/swagger_doc', '/swagger_doc/{name}'
181
- end
182
-
183
- specify do
184
- paths.each_pair do |path, value|
185
- expect(path).to start_with('/')
186
- expect(value).to be_a Hash
187
- expect(value).not_to be_empty
188
-
189
- value.each do |method, declaration|
190
- expect(http_verbs).to include method
191
- expect(declaration).to have_key('responses')
192
-
193
- declaration['responses'].each do |status_code, response|
194
- expect(status_code).to match(/\d{3}/)
195
- expect(response).to have_key('description')
196
- end
197
- end
198
- end
199
- end
200
- end
201
-
202
- describe 'definitions object' do
203
- let(:definitions) { subject['definitions'] }
204
-
205
- specify do
206
- definitions.each do |model, properties|
207
- expect(model).to match(/\w+/)
208
- expect(properties).to have_key('properties')
209
- end
210
- end
211
- end
212
- end
213
-
214
- describe 'swagger file' do
215
- it do
216
- expect(subject).to eql swagger_json
217
- end
218
- end
219
- end
220
-
221
- describe 'specific resource documentation' do
222
- subject do
223
- get '/v3/swagger_doc/other_thing'
224
- JSON.parse(last_response.body)
225
- end
226
-
227
- let(:tags) { subject['tags'] }
228
- specify do
229
- expect(tags).to eql [
230
- {
231
- 'name' => 'other_thing',
232
- 'description' => 'Operations about other_things'
233
- }
234
- ]
235
- end
236
- end
237
- end