apipie-rails 0.9.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -14
  3. data/.rubocop_todo.yml +102 -213
  4. data/CHANGELOG.md +17 -6
  5. data/README.rst +12 -12
  6. data/app/controllers/apipie/apipies_controller.rb +4 -4
  7. data/lib/apipie/apipie_module.rb +4 -4
  8. data/lib/apipie/application.rb +70 -54
  9. data/lib/apipie/configuration.rb +19 -26
  10. data/lib/apipie/dsl_definition.rb +4 -5
  11. data/lib/apipie/extractor/collector.rb +2 -2
  12. data/lib/apipie/extractor.rb +1 -1
  13. data/lib/apipie/generator/config.rb +12 -0
  14. data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
  15. data/lib/apipie/generator/swagger/config.rb +78 -0
  16. data/lib/apipie/generator/swagger/context.rb +12 -1
  17. data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
  18. data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +86 -0
  19. data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
  20. data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
  21. data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
  22. data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
  23. data/lib/apipie/generator/swagger/method_description.rb +2 -0
  24. data/lib/apipie/generator/swagger/operation_id.rb +1 -1
  25. data/lib/apipie/generator/swagger/param_description/builder.rb +4 -4
  26. data/lib/apipie/generator/swagger/param_description/composite.rb +9 -1
  27. data/lib/apipie/generator/swagger/param_description/in.rb +1 -1
  28. data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
  29. data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
  30. data/lib/apipie/generator/swagger/param_description/type.rb +9 -2
  31. data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
  32. data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
  33. data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
  34. data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
  35. data/lib/apipie/generator/swagger/schema.rb +63 -0
  36. data/lib/apipie/generator/swagger/type_extractor.rb +0 -19
  37. data/lib/apipie/generator/swagger/warning.rb +3 -6
  38. data/lib/apipie/generator/swagger/warning_writer.rb +7 -1
  39. data/lib/apipie/method_description.rb +4 -2
  40. data/lib/apipie/param_description.rb +4 -2
  41. data/lib/apipie/resource_description.rb +1 -1
  42. data/lib/apipie/swagger_generator.rb +27 -551
  43. data/lib/apipie/validator.rb +7 -3
  44. data/lib/apipie/version.rb +1 -1
  45. data/lib/apipie-rails.rb +17 -0
  46. data/lib/tasks/apipie.rake +15 -10
  47. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +2 -2
  48. data/spec/controllers/pets_controller_spec.rb +10 -16
  49. data/spec/controllers/users_controller_spec.rb +2 -2
  50. data/spec/dummy/app/controllers/pets_controller.rb +4 -4
  51. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  52. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  53. data/spec/dummy/app/controllers/users_controller.rb +5 -5
  54. data/spec/lib/apipie/application_spec.rb +16 -7
  55. data/spec/lib/apipie/configuration_spec.rb +15 -0
  56. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  57. data/spec/lib/apipie/generator/swagger/context_spec.rb +22 -2
  58. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +106 -0
  59. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  60. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +1 -1
  61. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +2 -2
  62. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +7 -7
  63. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  64. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  65. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  66. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  67. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  68. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +0 -43
  69. data/spec/lib/apipie/generator/swagger/warning_spec.rb +1 -1
  70. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +19 -7
  71. data/spec/lib/apipie/method_description_spec.rb +101 -66
  72. data/spec/lib/apipie/param_description_spec.rb +209 -49
  73. data/spec/lib/apipie/param_group_spec.rb +1 -0
  74. data/spec/lib/apipie/resource_description_spec.rb +1 -1
  75. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  76. data/spec/lib/apipie/validator_spec.rb +47 -11
  77. data/spec/lib/swagger/rake_swagger_spec.rb +4 -4
  78. data/spec/lib/swagger/swagger_dsl_spec.rb +7 -7
  79. data/spec/lib/validators/array_validator_spec.rb +1 -1
  80. metadata +28 -2
@@ -114,88 +114,210 @@ describe Apipie::ParamDescription do
114
114
  end
115
115
 
116
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
+
117
130
  context 'when allow_blank is ignored, as it was before 0.7.0' do
118
- before do
119
- Apipie.configuration.ignore_allow_blank_false = true
120
- end
131
+ before { Apipie.configuration.ignore_allow_blank_false = true }
132
+ after { Apipie.configuration.ignore_allow_blank_false = false }
121
133
 
122
- context 'when the parameter is a boolean' do
123
- it "should not throw an exception when passed false" do
124
- expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate(false) }.to_not raise_error
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
125
143
  end
126
144
 
127
- it "should throw an exception when passed an empty value" do
128
- expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate('') }.to raise_error(Apipie::ParamInvalid)
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
129
151
  end
130
152
  end
131
153
 
132
- context 'when the parameter is a string' do
133
- context 'when allow_blank is specified as true' do
134
- it "should throw an exception when passed an empty value" do
135
- expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: true).validate('') }.to_not raise_error
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
136
162
  end
137
163
  end
138
- context 'when allow_blank is specified as false' do
139
- it "should throw an exception when passed an empty value" do
140
- expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: false).validate('') }.to_not raise_error
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
141
170
  end
142
171
  end
143
- context 'when allow_blank is not specified' do
144
- it "should throw an exception when passed an empty value" do
145
- expect { Apipie::ParamDescription.new(method_desc, :param, String).validate('') }.to_not raise_error
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)
146
178
  end
147
179
  end
148
180
  end
149
181
 
150
- after do
151
- Apipie.configuration.ignore_allow_blank_false = false
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
152
200
  end
153
201
  end
154
202
 
155
- context 'when the parameter is a boolean' do
156
- it "should not throw an exception when passed false" do
157
- expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate(false) }.to_not raise_error
158
- end
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 }
159
223
 
160
- it "should still not throw an exception when passed false with explicit allow_blank: false" do
161
- expect { Apipie::ParamDescription.new(method_desc, :param, :boolean, allow_blank: false).validate(false) }.to_not raise_error
224
+ it 'should not raise an error' do
225
+ expect { subject }.not_to raise_error
226
+ end
227
+ end
162
228
  end
163
229
 
164
- it "should throw an exception when passed an empty value" do
165
- expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate('') }.to raise_error(Apipie::ParamInvalid)
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
166
236
  end
167
237
  end
168
238
 
169
- context "when the parameter is a custom type with ignore_allow_blank? returning true" do
170
- it "should not throw an exception when passed a blank but valid value" do
171
- expect { Apipie::ParamDescription.new(method_desc, :param, :custom_bool).validate(false) }.to_not raise_error
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
172
248
  end
173
249
 
174
- it "should still not throw an exception when passed false with explicit allow_blank: false" do
175
- expect { Apipie::ParamDescription.new(method_desc, :param, :custom_bool, allow_blank: false).validate(false) }.to_not raise_error
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
176
256
  end
177
257
 
178
- it "should throw an exception when passed an invalid but blank value" do
179
- expect { Apipie::ParamDescription.new(method_desc, :param, :custom_bool).validate("") }.to raise_error(Apipie::ParamInvalid)
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
180
264
  end
181
265
  end
182
266
 
183
- context 'when the parameter is a string' do
184
- context 'when allow_blank is specified as true' do
185
- it "should throw an exception when passed an empty value" do
186
- expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: true).validate('') }.to_not raise_error
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
187
297
  end
188
298
  end
189
- context 'when allow_blank is specified as false' do
190
- it "should throw an exception when passed an empty value" do
191
- expect do
192
- Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: false).validate('')
193
- end.to raise_error(Apipie::ParamInvalid)
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)
194
309
  end
195
310
  end
196
- context 'when allow_blank is not specified' do
197
- it "should throw an exception when passed an empty value" do
198
- expect { Apipie::ParamDescription.new(method_desc, :param, String).validate('') }.to raise_error(Apipie::ParamInvalid)
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
199
321
  end
200
322
  end
201
323
  end
@@ -239,7 +361,6 @@ describe Apipie::ParamDescription do
239
361
  end
240
362
  end
241
363
 
242
-
243
364
  describe "required_by_default config option" do
244
365
  context "parameters required by default" do
245
366
 
@@ -369,7 +490,6 @@ describe Apipie::ParamDescription do
369
490
  end
370
491
  end
371
492
 
372
-
373
493
  describe 'sub params' do
374
494
 
375
495
  context 'with HashValidator' do
@@ -508,4 +628,44 @@ describe Apipie::ParamDescription do
508
628
  end
509
629
  end
510
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
511
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]
@@ -64,7 +64,7 @@ describe Apipie::ResourceDescription do
64
64
  end
65
65
 
66
66
  it 'should be ordered' do
67
- expect(methods_as_json.map { |h| h[:name] }).to eq(['a', 'b', 'c'])
67
+ expect(methods_as_json.map { |h| h[:name] }).to eq(%w[a b c])
68
68
  end
69
69
  end
70
70
  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
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'
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,19 +51,55 @@ describe Apipie::Validator do
51
51
  end
52
52
 
53
53
  describe 'BooleanValidator' do
54
- it "should validate by object class" do
55
- validator = Apipie::Validator::BooleanValidator.new(params_desc)
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
- it "should have a valid description" do
65
- validator = Apipie::Validator::BooleanValidator.new(params_desc)
66
- expect(validator.description).to eq('Must be one of: <code>true</code>, <code>false</code>, <code>1</code>, <code>0</code>.')
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
 
@@ -12,7 +12,7 @@ describe 'rake tasks' do
12
12
 
13
13
  before do
14
14
  Apipie.configuration.doc_path = doc_path
15
- Apipie.configuration.swagger_suppress_warnings = true
15
+ Apipie.configuration.generator.swagger.suppress_warnings = true
16
16
  allow(Apipie).to receive(:reload_documentation)
17
17
  subject.invoke(*task_args)
18
18
  end
@@ -102,7 +102,7 @@ describe 'rake tasks' do
102
102
 
103
103
  expect_param_def("get", "/users/by_department", "department", "in", "query")
104
104
  expect_param_def("get", "/users/by_department", "department", "enum",
105
- ["finance", "operations", "sales", "marketing", "HR"])
105
+ %w[finance operations sales marketing HR])
106
106
 
107
107
  expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
108
108
  end
@@ -128,11 +128,11 @@ describe 'rake tasks' do
128
128
  expect_param_def("put", "/users/{id}", "oauth", "in", "formData")
129
129
  expect_param_def("get", "/users/by_department", "department", "in", "query")
130
130
  expect_param_def("get", "/users/by_department", "department", "enum",
131
- ["finance", "operations", "sales", "marketing", "HR"])
131
+ %w[finance operations sales marketing HR])
132
132
 
133
133
  expect_param_def("get", "/users/in_departments", "departments", "in", "query")
134
134
  expect_array_param_def("get", "/users/in_departments", "departments",
135
- ["finance", "operations", "sales", "marketing", "HR"])
135
+ %w[finance operations sales marketing HR])
136
136
 
137
137
  expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
138
138
 
@@ -6,7 +6,7 @@ describe "Swagger Responses" do
6
6
  let(:desc) { Apipie.get_resource_description(controller_class, Apipie.configuration.default_version) }
7
7
 
8
8
  let(:swagger) {
9
- Apipie.configuration.swagger_suppress_warnings = true
9
+ Apipie.configuration.generator.swagger.suppress_warnings = true
10
10
  Apipie.to_swagger_json(Apipie.configuration.default_version, controller_class.to_s.underscore.sub("_controller", ""))
11
11
  }
12
12
 
@@ -141,7 +141,7 @@ describe "Swagger Responses" do
141
141
 
142
142
  a_schema = resolve_refs(schema[:items])
143
143
  expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
144
- expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
144
+ expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
145
145
  end
146
146
 
147
147
 
@@ -210,7 +210,7 @@ describe "Swagger Responses" do
210
210
 
211
211
  schema = response[:schema]
212
212
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
213
- expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
213
+ expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
214
214
  end
215
215
 
216
216
  it 'should have the 404 response description overridden' do
@@ -247,7 +247,7 @@ describe "Swagger Responses" do
247
247
 
248
248
  schema = response[:schema]
249
249
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
250
- expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
250
+ expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
251
251
  end
252
252
  end
253
253
 
@@ -282,7 +282,7 @@ describe "Swagger Responses" do
282
282
  schema = response[:schema]
283
283
  expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'})
284
284
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
285
- expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
285
+ expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
286
286
  expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false})
287
287
  end
288
288
 
@@ -433,7 +433,7 @@ describe "Swagger Responses" do
433
433
 
434
434
  schema = response[:schema]
435
435
  expect(schema).to have_field(:int_array, 'array', {items: {type: 'number'}})
436
- expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: ['v1','v2','v3']}})
436
+ expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: %w[v1 v2 v3]}})
437
437
  end
438
438
 
439
439
 
@@ -551,7 +551,7 @@ describe "Swagger Responses" do
551
551
 
552
552
  a_schema = schema[:items]
553
553
  expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
554
- expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
554
+ expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
555
555
  end
556
556
  end
557
557
 
@@ -30,7 +30,7 @@ module Apipie::Validator
30
30
  let(:type) { String }
31
31
 
32
32
  it "accepts array of specified type" do
33
- expect(validator.validate(['string1', 'string2'])).to eq(true)
33
+ expect(validator.validate(%w[string1 string2])).to eq(true)
34
34
  end
35
35
 
36
36
  it "accepts empty array" do