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.
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,239 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'setting of param type, such as `query`, `path`, `formData`, `body`, `header`' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ParamTypeApi < Grape::API
11
- # using `:param_type`
12
- desc 'full set of request param types',
13
- success: Entities::UseResponse
14
- params do
15
- optional :in_query, type: String, documentation: { param_type: 'query' }
16
- optional :in_header, type: String, documentation: { param_type: 'header' }
17
- end
18
-
19
- get '/defined_param_type' do
20
- { 'declared_params' => declared(params) }
21
- end
22
-
23
- desc 'full set of request param types',
24
- success: Entities::UseResponse
25
- params do
26
- requires :in_path, type: Integer
27
- optional :in_query, type: String, documentation: { param_type: 'query' }
28
- optional :in_header, type: String, documentation: { param_type: 'header' }
29
- end
30
-
31
- get '/defined_param_type/:in_path' do
32
- { 'declared_params' => declared(params) }
33
- end
34
-
35
- desc 'full set of request param types',
36
- success: Entities::UseResponse
37
- params do
38
- optional :in_path, type: Integer
39
- optional :in_query, type: String, documentation: { param_type: 'query' }
40
- optional :in_header, type: String, documentation: { param_type: 'header' }
41
- end
42
-
43
- delete '/defined_param_type/:in_path' do
44
- { 'declared_params' => declared(params) }
45
- end
46
-
47
- # using `:in`
48
- desc 'full set of request param types using `:in`',
49
- success: Entities::UseResponse
50
- params do
51
- optional :in_query, type: String, documentation: { in: 'query' }
52
- optional :in_header, type: String, documentation: { in: 'header' }
53
- end
54
-
55
- get '/defined_in' do
56
- { 'declared_params' => declared(params) }
57
- end
58
-
59
- desc 'full set of request param types using `:in`',
60
- success: Entities::UseResponse
61
- params do
62
- requires :in_path, type: Integer
63
- optional :in_query, type: String, documentation: { in: 'query' }
64
- optional :in_header, type: String, documentation: { in: 'header' }
65
- end
66
-
67
- get '/defined_in/:in_path' do
68
- { 'declared_params' => declared(params) }
69
- end
70
-
71
- desc 'full set of request param types using `:in`'
72
- params do
73
- optional :in_path, type: Integer
74
- optional :in_query, type: String, documentation: { in: 'query' }
75
- optional :in_header, type: String, documentation: { in: 'header' }
76
- end
77
-
78
- delete '/defined_in/:in_path' do
79
- { 'declared_params' => declared(params) }
80
- end
81
-
82
- # file
83
- desc 'file download',
84
- success: Entities::UseResponse
85
- params do
86
- requires :name, type: String
87
- end
88
-
89
- get '/download' do
90
- { 'declared_params' => declared(params) }
91
- end
92
-
93
- desc 'file upload',
94
- success: Entities::UseResponse
95
- params do
96
- requires :name, type: File
97
- end
98
-
99
- post '/upload' do
100
- { 'declared_params' => declared(params) }
101
- end
102
-
103
- add_swagger_documentation
104
- end
105
- end
106
- end
107
-
108
- def app
109
- TheApi::ParamTypeApi
110
- end
111
-
112
- describe 'foo' do
113
- subject do
114
- get '/swagger_doc'
115
- JSON.parse(last_response.body)
116
- end
117
-
118
- specify do
119
- expect(subject['paths']['/defined_param_type/{in_path}']['delete']['responses']).to eql(
120
- '200' => {
121
- 'description' => 'full set of request param types',
122
- 'schema' => { '$ref' => '#/definitions/UseResponse' }
123
- }
124
- )
125
- end
126
-
127
- specify do
128
- expect(subject['paths']['/defined_in/{in_path}']['delete']['responses']).to eql(
129
- '204' => {
130
- 'description' => 'full set of request param types using `:in`'
131
- }
132
- )
133
- end
134
- end
135
-
136
- describe 'defined param types' do
137
- subject do
138
- get '/swagger_doc/defined_param_type'
139
- JSON.parse(last_response.body)
140
- end
141
-
142
- specify do
143
- expect(subject['paths']['/defined_param_type']['get']['parameters']).to eql(
144
- [
145
- { 'in' => 'query', 'name' => 'in_query', 'required' => false, 'type' => 'string' },
146
- { 'in' => 'header', 'name' => 'in_header', 'required' => false, 'type' => 'string' }
147
- ]
148
- )
149
- end
150
-
151
- specify do
152
- expect(subject['paths']['/defined_param_type/{in_path}']['get']['parameters']).to eql(
153
- [
154
- { 'in' => 'path', 'name' => 'in_path', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
155
- { 'in' => 'query', 'name' => 'in_query', 'required' => false, 'type' => 'string' },
156
- { 'in' => 'header', 'name' => 'in_header', 'required' => false, 'type' => 'string' }
157
- ]
158
- )
159
- end
160
-
161
- specify do
162
- expect(subject['paths']['/defined_param_type/{in_path}']['delete']['parameters']).to eql(
163
- [
164
- { 'in' => 'path', 'name' => 'in_path', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
165
- { 'in' => 'query', 'name' => 'in_query', 'required' => false, 'type' => 'string' },
166
- { 'in' => 'header', 'name' => 'in_header', 'required' => false, 'type' => 'string' }
167
- ]
168
- )
169
- end
170
- end
171
-
172
- describe 'defined param types with `:in`' do
173
- subject do
174
- get '/swagger_doc/defined_in'
175
- JSON.parse(last_response.body)
176
- end
177
-
178
- specify do
179
- expect(subject['paths']['/defined_in']['get']['parameters']).to eql(
180
- [
181
- { 'in' => 'query', 'name' => 'in_query', 'required' => false, 'type' => 'string' },
182
- { 'in' => 'header', 'name' => 'in_header', 'required' => false, 'type' => 'string' }
183
- ]
184
- )
185
- end
186
-
187
- specify do
188
- expect(subject['paths']['/defined_in/{in_path}']['get']['parameters']).to eql(
189
- [
190
- { 'in' => 'path', 'name' => 'in_path', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
191
- { 'in' => 'query', 'name' => 'in_query', 'required' => false, 'type' => 'string' },
192
- { 'in' => 'header', 'name' => 'in_header', 'required' => false, 'type' => 'string' }
193
- ]
194
- )
195
- end
196
-
197
- specify do
198
- expect(subject['paths']['/defined_in/{in_path}']['delete']['parameters']).to eql(
199
- [
200
- { 'in' => 'path', 'name' => 'in_path', 'required' => true, 'type' => 'integer', 'format' => 'int32' },
201
- { 'in' => 'query', 'name' => 'in_query', 'required' => false, 'type' => 'string' },
202
- { 'in' => 'header', 'name' => 'in_header', 'required' => false, 'type' => 'string' }
203
- ]
204
- )
205
- end
206
- end
207
-
208
- describe 'file' do
209
- describe 'upload' do
210
- subject do
211
- get '/swagger_doc/upload'
212
- JSON.parse(last_response.body)
213
- end
214
-
215
- specify do
216
- expect(subject['paths']['/upload']['post']['parameters']).to eql(
217
- [
218
- { 'in' => 'formData', 'name' => 'name', 'required' => true, 'type' => 'file' }
219
- ]
220
- )
221
- end
222
- end
223
-
224
- describe 'download' do
225
- subject do
226
- get '/swagger_doc/download'
227
- JSON.parse(last_response.body)
228
- end
229
-
230
- specify do
231
- expect(subject['paths']['/download']['get']['parameters']).to eql(
232
- [
233
- { 'in' => 'query', 'name' => 'name', 'required' => true, 'type' => 'string' }
234
- ]
235
- )
236
- end
237
- end
238
- end
239
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'additional parameter settings' do
6
- before :all do
7
- module TheApi
8
- class RequestParamFix < Grape::API
9
- resource :bookings do
10
- desc 'Update booking'
11
- params do
12
- optional :name, type: String
13
- end
14
- put ':id' do
15
- { 'declared_params' => declared(params) }
16
- end
17
-
18
- desc 'Get booking details'
19
- get ':id' do
20
- { 'declared_params' => declared(params) }
21
- end
22
-
23
- desc 'Get booking details by access_number'
24
- get '/conf/:access_number' do
25
- { 'declared_params' => declared(params) }
26
- end
27
-
28
- desc 'Remove booking'
29
- delete ':id' do
30
- { 'declared_params' => declared(params) }
31
- end
32
- end
33
-
34
- add_swagger_documentation
35
- end
36
- end
37
- end
38
-
39
- def app
40
- TheApi::RequestParamFix
41
- end
42
-
43
- subject do
44
- get '/swagger_doc'
45
- JSON.parse(last_response.body)
46
- end
47
-
48
- specify do
49
- expect(subject['paths']['/bookings/{id}']['put']['parameters'].sort_by { |p| p['name'] }).to eql(
50
- [
51
- { 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true },
52
- { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false }
53
- ]
54
- )
55
- end
56
-
57
- specify do
58
- expect(subject['paths']['/bookings/{id}']['get']['parameters']).to eql(
59
- [
60
- { 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }
61
- ]
62
- )
63
- end
64
-
65
- specify do
66
- expect(subject['paths']['/bookings/{id}']['delete']['parameters']).to eql(
67
- [
68
- { 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }
69
- ]
70
- )
71
- end
72
- end
@@ -1,143 +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 ResponseApi < 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
- post '/params_given' do
17
- { 'declared_params' => declared(params) }
18
- end
19
-
20
- desc 'This returns something',
21
- entity: Entities::UseResponse,
22
- failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
23
- get '/entity_response' do
24
- { 'declared_params' => declared(params) }
25
- end
26
-
27
- desc 'This returns something',
28
- entity: Entities::UseItemResponseAsType,
29
- failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
30
- get '/nested_type' do
31
- { 'declared_params' => declared(params) }
32
- end
33
-
34
- desc 'This returns something',
35
- success: [
36
- { code: 200, message: 'Request has succeeded' },
37
- { code: 201, message: 'Successful Operation' },
38
- { code: 204, message: 'Request was fulfilled' }
39
- ],
40
- failure: [{ code: 400, message: 'NotFound', model: Entities::ApiError }]
41
- get '/multiple-success-responses' do
42
- { 'declared_params' => declared(params) }
43
- end
44
-
45
- add_swagger_documentation
46
- end
47
- end
48
- end
49
-
50
- def app
51
- TheApi::ResponseApi
52
- end
53
-
54
- describe 'uses nested type as response object' do
55
- subject do
56
- get '/swagger_doc/nested_type'
57
- JSON.parse(last_response.body)
58
- end
59
- specify do
60
- expect(subject['paths']['/nested_type']['get']).to eql(
61
- 'description' => 'This returns something',
62
- 'produces' => ['application/json'],
63
- 'responses' => {
64
- '200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseItemResponseAsType' } },
65
- '400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
66
- },
67
- 'tags' => ['nested_type'],
68
- 'operationId' => 'getNestedType'
69
- )
70
- expect(subject['definitions']).to eql(swagger_nested_type)
71
- end
72
- end
73
-
74
- describe 'uses entity as response object' do
75
- subject do
76
- get '/swagger_doc/entity_response'
77
- JSON.parse(last_response.body)
78
- end
79
-
80
- specify do
81
- expect(subject['paths']['/entity_response']['get']).to eql(
82
- 'description' => 'This returns something',
83
- 'produces' => ['application/json'],
84
- 'responses' => {
85
- '200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
86
- '400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
87
- },
88
- 'tags' => ['entity_response'],
89
- 'operationId' => 'getEntityResponse'
90
- )
91
- expect(subject['definitions']).to eql(swagger_entity_as_response_object)
92
- end
93
- end
94
-
95
- describe 'uses params as response object' do
96
- subject do
97
- get '/swagger_doc/params_given'
98
- JSON.parse(last_response.body)
99
- end
100
-
101
- specify do
102
- expect(subject['paths']['/params_given']['post']).to eql(
103
- 'description' => 'This returns something',
104
- 'produces' => ['application/json'],
105
- 'consumes' => ['application/json'],
106
- 'parameters' => [
107
- { 'in' => 'formData', 'name' => 'description', 'type' => 'string', 'required' => false },
108
- { 'in' => 'formData', 'name' => '$responses', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false }
109
- ],
110
- 'responses' => {
111
- '201' => { 'description' => 'This returns something' },
112
- '400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
113
- },
114
- 'tags' => ['params_given'],
115
- 'operationId' => 'postParamsGiven'
116
- )
117
- expect(subject['definitions']).to eql(swagger_params_as_response_object)
118
- end
119
- end
120
-
121
- describe 'uses params as response object when response contains multiple values for success' do
122
- subject do
123
- get '/swagger_doc/multiple-success-responses'
124
- JSON.parse(last_response.body)
125
- end
126
-
127
- specify do
128
- expect(subject['paths']['/multiple-success-responses']['get']).to eql(
129
- 'description' => 'This returns something',
130
- 'produces' => ['application/json'],
131
- 'responses' => {
132
- '200' => { 'description' => 'Request has succeeded' },
133
- '201' => { 'description' => 'Successful Operation' },
134
- '204' => { 'description' => 'Request was fulfilled' },
135
- '400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
136
- },
137
- 'tags' => ['multiple-success-responses'],
138
- 'operationId' => 'getMultipleSuccessResponses'
139
- )
140
- expect(subject['definitions']).to eql(swagger_params_as_response_object)
141
- end
142
- end
143
- end
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'response with examples' do
6
- include_context "#{MODEL_PARSER} swagger example"
7
-
8
- before :all do
9
- module TheApi
10
- class ResponseApiExamples < Grape::API
11
- format :json
12
-
13
- desc 'This returns examples' do
14
- success model: Entities::UseResponse, examples: { 'application/json' => { description: 'Names list', items: [{ id: '123', name: 'John' }] } }
15
- failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }]]
16
- end
17
- get '/response_examples' do
18
- { 'declared_params' => declared(params) }
19
- end
20
-
21
- desc 'This syntax also returns examples' do
22
- success model: Entities::UseResponse, examples: { 'application/json' => { description: 'Names list', items: [{ id: '123', name: 'John' }] } }
23
- failure [
24
- {
25
- code: 404,
26
- message: 'NotFound',
27
- model: Entities::ApiError,
28
- examples: { 'application/json' => { code: 404, message: 'Not found' } }
29
- },
30
- {
31
- code: 400,
32
- message: 'BadRequest',
33
- model: Entities::ApiError,
34
- examples: { 'application/json' => { code: 400, message: 'Bad Request' } }
35
- }
36
- ]
37
- end
38
- get '/response_failure_examples' do
39
- { 'declared_params' => declared(params) }
40
- end
41
-
42
- desc 'This does not return examples' do
43
- success model: Entities::UseResponse
44
- failure [[404, 'NotFound', Entities::ApiError]]
45
- end
46
- get '/response_no_examples' do
47
- { 'declared_params' => declared(params) }
48
- end
49
- add_swagger_documentation
50
- end
51
- end
52
- end
53
-
54
- def app
55
- TheApi::ResponseApiExamples
56
- end
57
-
58
- describe 'response examples' do
59
- let(:example_200) do
60
- { 'application/json' => { 'description' => 'Names list', 'items' => [{ 'id' => '123', 'name' => 'John' }] } }
61
- end
62
- let(:example_404) do
63
- { 'application/json' => { 'code' => 404, 'message' => 'Not found' } }
64
- end
65
-
66
- subject do
67
- get '/swagger_doc/response_examples'
68
- JSON.parse(last_response.body)
69
- end
70
-
71
- specify do
72
- expect(subject['paths']['/response_examples']['get']).to eql(
73
- 'description' => 'This returns examples',
74
- 'produces' => ['application/json'],
75
- 'responses' => {
76
- '200' => { 'description' => 'This returns examples', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'examples' => example_200 },
77
- '404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_404 }
78
- },
79
- 'tags' => ['response_examples'],
80
- 'operationId' => 'getResponseExamples'
81
- )
82
- end
83
- end
84
-
85
- describe 'response failure examples' do
86
- let(:example_200) do
87
- { 'application/json' => { 'description' => 'Names list', 'items' => [{ 'id' => '123', 'name' => 'John' }] } }
88
- end
89
- let(:example_404) do
90
- { 'application/json' => { 'code' => 404, 'message' => 'Not found' } }
91
- end
92
- let(:example_400) do
93
- { 'application/json' => { 'code' => 400, 'message' => 'Bad Request' } }
94
- end
95
-
96
- subject do
97
- get '/swagger_doc/response_failure_examples'
98
- JSON.parse(last_response.body)
99
- end
100
-
101
- specify do
102
- expect(subject['paths']['/response_failure_examples']['get']).to eql(
103
- 'description' => 'This syntax also returns examples',
104
- 'produces' => ['application/json'],
105
- 'responses' => {
106
- '200' => { 'description' => 'This syntax also returns examples', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'examples' => example_200 },
107
- '404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_404 },
108
- '400' => { 'description' => 'BadRequest', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_400 }
109
- },
110
- 'tags' => ['response_failure_examples'],
111
- 'operationId' => 'getResponseFailureExamples'
112
- )
113
- end
114
- end
115
-
116
- describe 'response no examples' do
117
- subject do
118
- get '/swagger_doc/response_no_examples'
119
- JSON.parse(last_response.body)
120
- end
121
-
122
- specify do
123
- expect(subject['paths']['/response_no_examples']['get']).to eql(
124
- 'description' => 'This does not return examples',
125
- 'produces' => ['application/json'],
126
- 'responses' => {
127
- '200' => { 'description' => 'This does not return examples', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
128
- '404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
129
- },
130
- 'tags' => ['response_no_examples'],
131
- 'operationId' => 'getResponseNoExamples'
132
- )
133
- end
134
- end
135
- end