apipie-rails 0.5.19 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +31 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +128 -0
- data/.rubocop_todo.yml +2056 -0
- data/.vscode/settings.json +3 -0
- data/CHANGELOG.md +161 -0
- data/Gemfile +20 -0
- data/README.rst +117 -23
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +18 -9
- data/app/controllers/apipie/apipies_controller.rb +14 -29
- data/app/helpers/apipie_helper.rb +1 -1
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
- data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
- data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
- data/app/views/apipie/apipies/_params.html.erb +7 -1
- data/config/locales/en.yml +8 -0
- data/config/locales/ko.yml +31 -0
- data/gemfiles/Gemfile.tools +9 -0
- data/lib/apipie/apipie_module.rb +7 -7
- data/lib/apipie/application.rb +132 -97
- data/lib/apipie/configuration.rb +43 -33
- data/lib/apipie/dsl_definition.rb +44 -33
- data/lib/apipie/error_description.rb +3 -3
- data/lib/apipie/errors.rb +17 -17
- data/lib/apipie/extractor/collector.rb +5 -6
- data/lib/apipie/extractor/recorder.rb +35 -8
- data/lib/apipie/extractor/writer.rb +15 -15
- data/lib/apipie/extractor.rb +6 -9
- data/lib/apipie/generator/config.rb +12 -0
- data/lib/apipie/generator/generator.rb +2 -0
- data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
- data/lib/apipie/generator/swagger/config.rb +80 -0
- data/lib/apipie/generator/swagger/context.rb +38 -0
- data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
- data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
- data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
- data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
- data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
- data/lib/apipie/generator/swagger/method_description.rb +2 -0
- data/lib/apipie/generator/swagger/operation_id.rb +51 -0
- data/lib/apipie/generator/swagger/param_description/builder.rb +114 -0
- data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
- data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
- data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
- data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
- data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
- data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
- data/lib/apipie/generator/swagger/param_description/type.rb +128 -0
- data/lib/apipie/generator/swagger/param_description.rb +18 -0
- data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
- data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
- data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
- data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
- data/lib/apipie/generator/swagger/schema.rb +63 -0
- data/lib/apipie/generator/swagger/swagger.rb +2 -0
- data/lib/apipie/generator/swagger/type.rb +16 -0
- data/lib/apipie/generator/swagger/type_extractor.rb +51 -0
- data/lib/apipie/generator/swagger/warning.rb +74 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
- data/lib/apipie/helpers.rb +3 -3
- data/lib/apipie/markup.rb +9 -8
- data/lib/apipie/method_description/api.rb +12 -0
- data/lib/apipie/method_description/apis_service.rb +82 -0
- data/lib/apipie/method_description.rb +12 -56
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +57 -24
- data/lib/apipie/resource_description.rb +42 -14
- data/lib/apipie/response_description.rb +3 -3
- data/lib/apipie/response_description_adapter.rb +12 -10
- data/lib/apipie/routing.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +3 -3
- data/lib/apipie/static_dispatcher.rb +10 -2
- data/lib/apipie/swagger_generator.rb +28 -691
- data/lib/apipie/validator.rb +41 -11
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +36 -5
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +37 -32
- data/rel-eng/gem_release.ipynb +41 -9
- data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
- data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
- data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
- data/spec/controllers/users_controller_spec.rb +47 -6
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
- data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
- data/spec/dummy/app/controllers/pets_controller.rb +5 -5
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
- data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
- data/spec/dummy/app/controllers/users_controller.rb +17 -5
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
- data/spec/dummy/config/application.rb +2 -5
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +0 -3
- data/spec/dummy/config/environments/production.rb +0 -3
- data/spec/dummy/config/environments/test.rb +0 -5
- data/spec/dummy/config/initializers/apipie.rb +2 -2
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
- data/spec/lib/apipie/application_spec.rb +62 -0
- data/spec/lib/apipie/configuration_spec.rb +38 -0
- data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
- data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
- data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
- data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
- data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
- data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
- data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
- data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -0
- data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
- data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
- data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
- data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +183 -0
- data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
- data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
- data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
- data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
- data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
- data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
- data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/apipie/method_description_spec.rb +133 -0
- data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
- data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
- data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
- data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
- data/spec/lib/apipie/resource_description_spec.rb +91 -0
- data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
- data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
- data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
- data/spec/lib/rake_spec.rb +3 -5
- data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
- data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
- data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
- data/spec/lib/validators/array_validator_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -32
- data/spec/support/custom_bool_validator.rb +17 -0
- data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
- metadata +173 -125
- data/.travis.yml +0 -41
- data/Gemfile +0 -1
- data/Gemfile.rails41 +0 -7
- data/Gemfile.rails42 +0 -14
- data/Gemfile.rails50 +0 -9
- data/Gemfile.rails51 +0 -9
- data/Gemfile.rails60 +0 -10
- data/Gemfile.rails61 +0 -10
- data/spec/lib/application_spec.rb +0 -49
- data/spec/lib/method_description_spec.rb +0 -98
- data/spec/lib/resource_description_spec.rb +0 -48
- /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
@@ -113,6 +113,216 @@ describe Apipie::ParamDescription do
|
|
113
113
|
|
114
114
|
end
|
115
115
|
|
116
|
+
describe 'validate' do
|
117
|
+
subject { param_description.validate(validation_value) }
|
118
|
+
|
119
|
+
let(:allow_blank) { nil }
|
120
|
+
|
121
|
+
let(:param_description) do
|
122
|
+
Apipie::ParamDescription.new(
|
123
|
+
method_desc,
|
124
|
+
:param,
|
125
|
+
validation_type,
|
126
|
+
allow_blank: allow_blank
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when allow_blank is ignored, as it was before 0.7.0' do
|
131
|
+
before { Apipie.configuration.ignore_allow_blank_false = true }
|
132
|
+
after { Apipie.configuration.ignore_allow_blank_false = false }
|
133
|
+
|
134
|
+
context 'when validation type is :boolean' do
|
135
|
+
let(:validation_type) { :boolean }
|
136
|
+
|
137
|
+
context 'when validation value is false' do
|
138
|
+
let(:validation_value) { false }
|
139
|
+
|
140
|
+
it 'should not raise an error' do
|
141
|
+
expect { subject }.not_to raise_error
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when validation value is an empty string' do
|
146
|
+
let(:validation_value) { '' }
|
147
|
+
|
148
|
+
it 'should raise an error' do
|
149
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when validation type is a boolean array' do
|
155
|
+
let(:validation_type) { [true, false] }
|
156
|
+
|
157
|
+
context 'when validation value is false' do
|
158
|
+
let(:validation_value) { false }
|
159
|
+
|
160
|
+
it 'should not raise an error' do
|
161
|
+
expect { subject }.not_to raise_error
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when validation value is true' do
|
166
|
+
let(:validation_value) { true }
|
167
|
+
|
168
|
+
it 'should not raise an error' do
|
169
|
+
expect { subject }.not_to raise_error
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'when validation value is an empty string' do
|
174
|
+
let(:validation_value) { '' }
|
175
|
+
|
176
|
+
it 'should raise an error' do
|
177
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when validation type is String' do
|
183
|
+
let(:validation_type) { String }
|
184
|
+
|
185
|
+
context 'when validation value is empty string' do
|
186
|
+
let(:validation_value) { '' }
|
187
|
+
|
188
|
+
it 'should not raise an error' do
|
189
|
+
expect { subject }.not_to raise_error
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when allow_blank is specified as true' do
|
193
|
+
let(:allow_blank) { true }
|
194
|
+
|
195
|
+
it 'should not raise an error' do
|
196
|
+
expect { subject }.not_to raise_error
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when the validation type is :boolean' do
|
204
|
+
let(:validation_type) { :boolean }
|
205
|
+
|
206
|
+
context 'when validation value' do
|
207
|
+
let(:validation_value) { false }
|
208
|
+
|
209
|
+
it 'should not raise an error' do
|
210
|
+
expect { subject }.not_to raise_error
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when allow_blank is false' do
|
214
|
+
let(:allow_blank) { false }
|
215
|
+
|
216
|
+
it 'should not raise an error' do
|
217
|
+
expect { subject }.not_to raise_error
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'when allow_blank is true' do
|
222
|
+
let(:allow_blank) { true }
|
223
|
+
|
224
|
+
it 'should not raise an error' do
|
225
|
+
expect { subject }.not_to raise_error
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when validation value is empty string' do
|
231
|
+
let(:validation_value) { '' }
|
232
|
+
|
233
|
+
it 'should raise an error' do
|
234
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'when validation type is a boolean array' do
|
240
|
+
let(:validation_type) { [true, false] }
|
241
|
+
|
242
|
+
context 'when validation value is false' do
|
243
|
+
let(:validation_value) { false }
|
244
|
+
|
245
|
+
it 'should not raise an error' do
|
246
|
+
expect { subject }.not_to raise_error
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'when validation value is true' do
|
251
|
+
let(:validation_value) { true }
|
252
|
+
|
253
|
+
it 'should not raise an error' do
|
254
|
+
expect { subject }.not_to raise_error
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'when validation value is an empty string' do
|
259
|
+
let(:validation_value) { '' }
|
260
|
+
|
261
|
+
it 'should raise an error' do
|
262
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'when the validation type is a custom one' do
|
268
|
+
let(:validation_type) { :custom_bool }
|
269
|
+
|
270
|
+
context 'when ignore_allow_blank? returning true' do
|
271
|
+
before do
|
272
|
+
allow(CustomBoolValidator).to receive(:ignore_allow_blank?).and_return(true)
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when a blank but valid value is passed' do
|
276
|
+
let(:validation_value) { false }
|
277
|
+
|
278
|
+
it 'should not raise an error' do
|
279
|
+
expect { subject }.not_to raise_error
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'when allow_blank is false' do
|
283
|
+
let(:allow_blank) { false }
|
284
|
+
|
285
|
+
it 'should not raise an error' do
|
286
|
+
expect { subject }.not_to raise_error
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context 'when a blank but invalid value is passed' do
|
292
|
+
let(:validation_value) { '' }
|
293
|
+
|
294
|
+
it 'should raise an error' do
|
295
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'when validation type is String' do
|
302
|
+
let(:validation_type) { String }
|
303
|
+
|
304
|
+
context 'when a blank but invalid value is passed' do
|
305
|
+
let(:validation_value) { '' }
|
306
|
+
|
307
|
+
it 'should raise an error' do
|
308
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context 'when allow_blank is specified as true' do
|
313
|
+
let(:allow_blank) { true }
|
314
|
+
|
315
|
+
context 'when and empty string is given' do
|
316
|
+
let(:validation_value) { '' }
|
317
|
+
|
318
|
+
it 'should not raise an error' do
|
319
|
+
expect { subject }.not_to raise_error
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
116
326
|
describe "concern substitution" do
|
117
327
|
|
118
328
|
let(:concern_dsl_data) { dsl_data.merge(:from_concern => true) }
|
@@ -151,7 +361,6 @@ describe Apipie::ParamDescription do
|
|
151
361
|
end
|
152
362
|
end
|
153
363
|
|
154
|
-
|
155
364
|
describe "required_by_default config option" do
|
156
365
|
context "parameters required by default" do
|
157
366
|
|
@@ -281,14 +490,13 @@ describe Apipie::ParamDescription do
|
|
281
490
|
end
|
282
491
|
end
|
283
492
|
|
284
|
-
|
285
493
|
describe 'sub params' do
|
286
494
|
|
287
495
|
context 'with HashValidator' do
|
288
496
|
|
289
497
|
subject do
|
290
498
|
Apipie::ParamDescription.new(method_desc, :param, Hash) do
|
291
|
-
param :answer,
|
499
|
+
param :answer, Integer
|
292
500
|
end
|
293
501
|
end
|
294
502
|
|
@@ -306,7 +514,7 @@ describe Apipie::ParamDescription do
|
|
306
514
|
|
307
515
|
subject do
|
308
516
|
Apipie::ParamDescription.new(method_desc, :param, Array) do
|
309
|
-
param :answer,
|
517
|
+
param :answer, Integer
|
310
518
|
end
|
311
519
|
end
|
312
520
|
|
@@ -336,10 +544,128 @@ describe Apipie::ParamDescription do
|
|
336
544
|
|
337
545
|
describe "Array with classes" do
|
338
546
|
it "should be valid for objects included in class array" do
|
339
|
-
param = Apipie::ParamDescription.new(method_desc, :param, [
|
547
|
+
param = Apipie::ParamDescription.new(method_desc, :param, [Integer, String])
|
340
548
|
expect { param.validate("1") }.not_to raise_error
|
341
|
-
expect { param.validate(
|
549
|
+
expect { param.validate(Integer) }.to raise_error(Apipie::ParamInvalid)
|
342
550
|
end
|
343
551
|
end
|
344
552
|
|
553
|
+
describe '#deprecated?' do
|
554
|
+
subject do
|
555
|
+
Apipie::ParamDescription.new(method_desc, :param, Integer, options)
|
556
|
+
end
|
557
|
+
|
558
|
+
let(:options) { {} }
|
559
|
+
|
560
|
+
it { is_expected.not_to be_deprecated }
|
561
|
+
|
562
|
+
context 'when deprecated option is passed' do
|
563
|
+
context 'and is true' do
|
564
|
+
let(:options) { { deprecated: true } }
|
565
|
+
|
566
|
+
it { is_expected.to be_deprecated }
|
567
|
+
end
|
568
|
+
|
569
|
+
context 'and is false' do
|
570
|
+
let(:options) { { deprecated: false } }
|
571
|
+
|
572
|
+
it { is_expected.not_to be_deprecated }
|
573
|
+
end
|
574
|
+
|
575
|
+
context 'and is a string' do
|
576
|
+
let(:options) { { deprecated: 'Some description' } }
|
577
|
+
|
578
|
+
it { is_expected.to be_deprecated }
|
579
|
+
end
|
580
|
+
|
581
|
+
context 'and deprecation options are given' do
|
582
|
+
let(:options) do
|
583
|
+
{ deprecated: { in: '2.3', info: 'Something', sunset: '3.0' } }
|
584
|
+
end
|
585
|
+
|
586
|
+
it { is_expected.to be_deprecated }
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
describe '#deprecation' do
|
592
|
+
subject { param_description.deprecation }
|
593
|
+
|
594
|
+
let(:options) { {} }
|
595
|
+
|
596
|
+
let(:param_description) do
|
597
|
+
Apipie::ParamDescription.new(method_desc, :param, Integer, options)
|
598
|
+
end
|
599
|
+
|
600
|
+
it { is_expected.to be_blank }
|
601
|
+
|
602
|
+
context 'when deprecated option is passed' do
|
603
|
+
context 'and is true' do
|
604
|
+
let(:options) { { deprecated: true } }
|
605
|
+
|
606
|
+
it { is_expected.to be_blank }
|
607
|
+
end
|
608
|
+
|
609
|
+
context 'and is false' do
|
610
|
+
let(:options) { { deprecated: false } }
|
611
|
+
|
612
|
+
it { is_expected.to be_blank }
|
613
|
+
end
|
614
|
+
|
615
|
+
context 'and is a string' do
|
616
|
+
let(:options) { { deprecated: 'Some description' } }
|
617
|
+
|
618
|
+
it { is_expected.to be_an_instance_of(Apipie::ParamDescription::Deprecation) }
|
619
|
+
end
|
620
|
+
|
621
|
+
context 'and deprecation options are given' do
|
622
|
+
let(:options) do
|
623
|
+
{ deprecated: { in: '2.3', info: 'Something', sunset: '3.0' } }
|
624
|
+
end
|
625
|
+
|
626
|
+
it { is_expected.to be_an_instance_of(Apipie::ParamDescription::Deprecation) }
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
describe '#required' do
|
632
|
+
subject { param_description.required }
|
633
|
+
|
634
|
+
let(:param_description) do
|
635
|
+
Apipie::ParamDescription.new(method_desc, :param, validator, options)
|
636
|
+
end
|
637
|
+
|
638
|
+
context 'when is passed in options' do
|
639
|
+
let(:validator) { String }
|
640
|
+
|
641
|
+
context 'when is false' do
|
642
|
+
let(:options) { { required: false } }
|
643
|
+
|
644
|
+
it { is_expected.to eq(false) }
|
645
|
+
end
|
646
|
+
|
647
|
+
context 'when is true' do
|
648
|
+
let(:options) { { required: true } }
|
649
|
+
|
650
|
+
it { is_expected.to eq(true) }
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
654
|
+
context 'when validator options are passed' do
|
655
|
+
let(:options) { { only_in: :response } }
|
656
|
+
let(:validator) { { array_of: String, required: required } }
|
657
|
+
|
658
|
+
context 'when required is false' do
|
659
|
+
let(:required) { false }
|
660
|
+
|
661
|
+
it { is_expected.to eq(false) }
|
662
|
+
end
|
663
|
+
|
664
|
+
context 'when required is true' do
|
665
|
+
let(:required) { true }
|
666
|
+
|
667
|
+
it { is_expected.to eq(true) }
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
345
671
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "param groups" do
|
4
|
+
before { Apipie.reload_documentation }
|
4
5
|
|
5
6
|
it "lets reuse the params description in more actions" do
|
6
7
|
user_create_desc = Apipie["users#create"].params[:user]
|
@@ -43,17 +44,17 @@ describe "param groups" do
|
|
43
44
|
end
|
44
45
|
|
45
46
|
it "should replace parameter name in a group when it comes from concern" do
|
46
|
-
expect(Apipie["overridden_concern_resources#update"].params.
|
47
|
+
expect(Apipie["overridden_concern_resources#update"].params.key?(:user)).to eq(true)
|
47
48
|
end
|
48
49
|
|
49
50
|
it "shouldn't replace parameter name in a group redefined in the controller" do
|
50
|
-
expect(Apipie["overridden_concern_resources#create"].params.
|
51
|
-
expect(Apipie["overridden_concern_resources#create"].params.
|
51
|
+
expect(Apipie["overridden_concern_resources#create"].params.key?(:concern)).to eq(true)
|
52
|
+
expect(Apipie["overridden_concern_resources#create"].params.key?(:user)).to eq(false)
|
52
53
|
end
|
53
54
|
|
54
55
|
it "shouldn't replace name of a parameter defined in the controller" do
|
55
|
-
expect(Apipie["overridden_concern_resources#custom"].params.
|
56
|
-
expect(Apipie["overridden_concern_resources#custom"].params.
|
56
|
+
expect(Apipie["overridden_concern_resources#custom"].params.key?(:concern)).to eq(true)
|
57
|
+
expect(Apipie["overridden_concern_resources#custom"].params.key?(:user)).to eq(false)
|
57
58
|
end
|
58
59
|
|
59
60
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::ResourceDescription do
|
4
|
+
let(:resource_description) do
|
5
|
+
Apipie::ResourceDescription.new(controller, id, dsl_data)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:controller) { ApplicationController }
|
9
|
+
let(:id) { 'dummy' }
|
10
|
+
let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
|
11
|
+
|
12
|
+
describe '#_methods' do
|
13
|
+
subject(:methods) { resource_description._methods }
|
14
|
+
|
15
|
+
context 'when has method descriptions' do
|
16
|
+
before do
|
17
|
+
resource_description.add_method_description(
|
18
|
+
Apipie::MethodDescription.new(:a, resource_description, dsl_data)
|
19
|
+
)
|
20
|
+
resource_description.add_method_description(
|
21
|
+
Apipie::MethodDescription.new(:b, resource_description, dsl_data)
|
22
|
+
)
|
23
|
+
resource_description.add_method_description(
|
24
|
+
Apipie::MethodDescription.new(:c, resource_description, dsl_data)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should be ordered' do
|
29
|
+
expect(methods.keys).to eq([:a, :b, :c])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#to_json' do
|
35
|
+
let(:json_data) { resource_description.to_json }
|
36
|
+
|
37
|
+
describe 'metadata' do
|
38
|
+
subject { json_data[:metadata] }
|
39
|
+
|
40
|
+
it { is_expected.to be_nil }
|
41
|
+
|
42
|
+
context 'when meta data are provided' do
|
43
|
+
let(:meta) { { length: 32, weight: '830g' } }
|
44
|
+
let(:dsl_data) { super().update({ meta: meta }) }
|
45
|
+
|
46
|
+
it { is_expected.to eq(meta) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'methods' do
|
51
|
+
subject(:methods_as_json) { json_data[:methods] }
|
52
|
+
|
53
|
+
context 'when has method descriptions' do
|
54
|
+
before do
|
55
|
+
resource_description.add_method_description(
|
56
|
+
Apipie::MethodDescription.new(:a, resource_description, dsl_data)
|
57
|
+
)
|
58
|
+
resource_description.add_method_description(
|
59
|
+
Apipie::MethodDescription.new(:b, resource_description, dsl_data)
|
60
|
+
)
|
61
|
+
resource_description.add_method_description(
|
62
|
+
Apipie::MethodDescription.new(:c, resource_description, dsl_data)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should be ordered' do
|
67
|
+
expect(methods_as_json.map { |h| h[:name] }).to eq(%w[a b c])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'name' do
|
74
|
+
subject { resource_description.name }
|
75
|
+
|
76
|
+
it { is_expected.to eq('Dummy') }
|
77
|
+
|
78
|
+
context 'when given id contains dashes' do
|
79
|
+
let(:id) { 'some-nested-resource' }
|
80
|
+
|
81
|
+
it { is_expected.to eq('Some::Nested::Resource') }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when resource_name is given' do
|
85
|
+
let(:resource_name) { 'Some-Resource' }
|
86
|
+
let(:dsl_data) { super().merge!(resource_name: 'Some-Resource') }
|
87
|
+
|
88
|
+
it { is_expected.to eq(resource_name) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::ResponseDoesNotMatchSwaggerSchema do
|
4
|
+
let(:error) do
|
5
|
+
described_class.new(
|
6
|
+
controller_name,
|
7
|
+
method_name,
|
8
|
+
response_code,
|
9
|
+
error_messages,
|
10
|
+
schema,
|
11
|
+
returned_object
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:controller_name) { 'UserController' }
|
16
|
+
let(:method_name) { 'index' }
|
17
|
+
let(:response_code) { 200 }
|
18
|
+
let(:error_messages) { [] }
|
19
|
+
let(:schema) { {} }
|
20
|
+
let(:returned_object) { {} }
|
21
|
+
|
22
|
+
describe '#to_s' do
|
23
|
+
subject { error.to_s }
|
24
|
+
|
25
|
+
let(:error_message) do
|
26
|
+
<<~HEREDOC.chomp
|
27
|
+
Response does not match swagger schema (#{controller_name}##{method_name} #{response_code}): #{error_messages}
|
28
|
+
Schema: #{JSON(schema)}
|
29
|
+
Returned object: #{returned_object}
|
30
|
+
HEREDOC
|
31
|
+
end
|
32
|
+
|
33
|
+
it { is_expected.to eq(error_message) }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dummy/app/controllers/pets_using_self_describing_classes_controller'
|
3
|
+
|
4
|
+
describe Apipie::SwaggerGenerator do
|
5
|
+
describe '.json_schema_for_method_response' do
|
6
|
+
subject { json_schema_for_method_response }
|
7
|
+
|
8
|
+
let(:response_description_dsl) do
|
9
|
+
proc do
|
10
|
+
property :a_number, Integer, example: 1
|
11
|
+
property :an_optional_number, Integer, required: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:response_description_options) do
|
16
|
+
[{}, PetsController, response_description_dsl, nil]
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:dsl_data) do
|
20
|
+
ActionController::Base
|
21
|
+
.send(:_apipie_dsl_data_init)
|
22
|
+
.merge(
|
23
|
+
{
|
24
|
+
returns: [[200, response_description_options]],
|
25
|
+
api_args: [
|
26
|
+
['get', '/path', 'Some api description', { deprecated: true }]
|
27
|
+
]
|
28
|
+
}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:method_description) do
|
33
|
+
Apipie::MethodDescription.new(
|
34
|
+
:show,
|
35
|
+
Apipie::ResourceDescription.new(UsersController, 'users'),
|
36
|
+
dsl_data
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:json_schema_for_method_response) do
|
41
|
+
described_class.json_schema_for_method_response(
|
42
|
+
method_description,
|
43
|
+
return_code,
|
44
|
+
false
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when there is no return code for responses' do
|
49
|
+
let(:return_code) { 3000 }
|
50
|
+
|
51
|
+
it { is_expected.to be_nil }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when return code exists' do
|
55
|
+
let(:return_code) { 200 }
|
56
|
+
|
57
|
+
describe 'properties' do
|
58
|
+
subject(:properties) { json_schema_for_method_response[:properties] }
|
59
|
+
|
60
|
+
it 'returns correct properties' do
|
61
|
+
expect(properties).to eq(
|
62
|
+
{
|
63
|
+
a_number: {
|
64
|
+
type: 'number', required: true, example: 1
|
65
|
+
},
|
66
|
+
an_optional_number: {
|
67
|
+
type: 'number'
|
68
|
+
}
|
69
|
+
}
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.json_schema_for_self_describing_class' do
|
77
|
+
subject(:schema) do
|
78
|
+
described_class.json_schema_for_self_describing_class(
|
79
|
+
self_describing_class,
|
80
|
+
allow_null
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:self_describing_class) { PetWithMeasurements }
|
85
|
+
let(:allow_null) { false }
|
86
|
+
|
87
|
+
before { Apipie.configuration.generator.swagger.responses_use_refs = false }
|
88
|
+
|
89
|
+
it 'returns the self describing class schema' do
|
90
|
+
expect(schema.keys).to include(:type, :properties, :required)
|
91
|
+
expect(schema[:properties].keys).to include(:pet_name, :animal_type, :pet_measurements)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -51,25 +51,61 @@ describe Apipie::Validator do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
describe 'BooleanValidator' do
|
54
|
-
|
55
|
-
|
56
|
-
expect(validator.validate("1")).to be_truthy
|
57
|
-
expect(validator.validate(1)).to be_truthy
|
58
|
-
expect(validator.validate(true)).to be_truthy
|
59
|
-
expect(validator.validate(0)).to be_truthy
|
60
|
-
expect(validator.validate(false)).to be_truthy
|
61
|
-
expect(validator.validate({ 1 => 1 })).to be_falsey
|
54
|
+
let(:validator) do
|
55
|
+
Apipie::Validator::BooleanValidator
|
62
56
|
end
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
58
|
+
let(:validator_instance) { validator.new(params_desc) }
|
59
|
+
|
60
|
+
describe '.build' do
|
61
|
+
subject { validator.build(params_desc, argument, nil, nil) }
|
62
|
+
|
63
|
+
context 'when argument is [true, false]' do
|
64
|
+
let(:argument) { [true, false] }
|
65
|
+
|
66
|
+
it { is_expected.to be_an_instance_of(Apipie::Validator::BooleanValidator) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when argument is :bool' do
|
70
|
+
let(:argument) { :bool }
|
71
|
+
|
72
|
+
it { is_expected.to be_an_instance_of(Apipie::Validator::BooleanValidator) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when argument :boolean' do
|
76
|
+
let(:argument) { :boolean }
|
77
|
+
|
78
|
+
it { is_expected.to be_an_instance_of(Apipie::Validator::BooleanValidator) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when argument :booooooooolean' do
|
82
|
+
let(:argument) { :booooooooolean }
|
83
|
+
|
84
|
+
it { is_expected.to be_nil }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#validate' do
|
89
|
+
it "should validate by object class" do
|
90
|
+
expect(validator_instance.validate("1")).to be_truthy
|
91
|
+
expect(validator_instance.validate(1)).to be_truthy
|
92
|
+
expect(validator_instance.validate(true)).to be_truthy
|
93
|
+
expect(validator_instance.validate(0)).to be_truthy
|
94
|
+
expect(validator_instance.validate(false)).to be_truthy
|
95
|
+
expect(validator_instance.validate({ 1 => 1 })).to be_falsey
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#description' do
|
100
|
+
subject { validator_instance.description }
|
101
|
+
|
102
|
+
it { is_expected.to eq('Must be one of: <code>true</code>, <code>false</code>, <code>1</code>, <code>0</code>.') }
|
67
103
|
end
|
68
104
|
end
|
69
105
|
|
70
106
|
describe 'ArrayClassValidator' do
|
71
107
|
it "should validate by object class" do
|
72
|
-
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [
|
108
|
+
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Integer, String])
|
73
109
|
expect(validator.validate("1")).to be_truthy
|
74
110
|
expect(validator.validate(1)).to be_truthy
|
75
111
|
expect(validator.validate({ 1 => 1 })).to be_falsey
|