apipie-rails 0.3.6 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +67 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +1991 -0
- data/CHANGELOG.md +246 -2
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +646 -25
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +14 -9
- data/app/controllers/apipie/apipies_controller.rb +51 -20
- 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/_method_detail.erb +21 -0
- data/app/views/apipie/apipies/_params.html.erb +4 -2
- data/app/views/apipie/apipies/index.html.erb +5 -1
- data/app/views/apipie/apipies/resource.html.erb +3 -0
- data/app/views/layouts/apipie/apipie.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/config/locales/fr.yml +31 -0
- data/config/locales/it.yml +31 -0
- data/config/locales/ja.yml +31 -0
- data/config/locales/ko.yml +31 -0
- data/config/locales/pt-BR.yml +1 -1
- data/gemfiles/Gemfile.rails50 +10 -0
- data/gemfiles/Gemfile.rails51 +10 -0
- data/gemfiles/Gemfile.rails52 +10 -0
- data/gemfiles/Gemfile.rails60 +17 -0
- data/gemfiles/Gemfile.rails61 +17 -0
- data/gemfiles/Gemfile.rails70 +17 -0
- data/lib/apipie/apipie_module.rb +22 -4
- data/lib/apipie/application.rb +54 -25
- data/lib/apipie/configuration.rb +26 -4
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +168 -16
- data/lib/apipie/error_description.rb +9 -2
- data/lib/apipie/errors.rb +34 -0
- data/lib/apipie/extractor/collector.rb +4 -0
- data/lib/apipie/extractor/recorder.rb +14 -12
- data/lib/apipie/extractor/writer.rb +86 -58
- data/lib/apipie/extractor.rb +5 -5
- data/lib/apipie/generator/generator.rb +2 -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 +70 -0
- data/lib/apipie/generator/swagger/warning.rb +77 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
- data/lib/apipie/markup.rb +14 -11
- 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 +51 -49
- data/lib/apipie/param_description.rb +63 -5
- data/lib/apipie/resource_description.rb +11 -4
- data/lib/apipie/response_description.rb +131 -0
- data/lib/apipie/response_description_adapter.rb +200 -0
- data/lib/apipie/routes_formatter.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +194 -0
- data/lib/apipie/static_dispatcher.rb +5 -2
- data/lib/apipie/swagger_generator.rb +717 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +83 -9
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +15 -4
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +115 -15
- data/rel-eng/gem_release.ipynb +398 -0
- data/spec/controllers/apipies_controller_spec.rb +79 -14
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/controllers/memes_controller_spec.rb +10 -0
- data/spec/controllers/users_controller_spec.rb +139 -76
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/application_controller.rb +5 -1
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- data/spec/dummy/app/controllers/extending_concern.rb +10 -0
- 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 +408 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +5 -7
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +26 -12
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/Gemfile +6 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
- data/spec/dummy/components/test_engine/config/routes.rb +3 -0
- data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
- data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
- data/spec/dummy/config/application.rb +6 -4
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/environments/production.rb +3 -3
- data/spec/dummy/config/environments/test.rb +3 -5
- data/spec/dummy/config/initializers/apipie.rb +5 -3
- data/spec/dummy/config/routes.rb +25 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/lib/application_spec.rb +1 -1
- data/spec/lib/extractor/writer_spec.rb +37 -7
- data/spec/lib/file_handler_spec.rb +25 -0
- data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
- data/spec/lib/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
- data/spec/lib/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/method_description_spec.rb +34 -0
- data/spec/lib/param_description_spec.rb +90 -4
- data/spec/lib/rake_spec.rb +2 -4
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +154 -0
- data/spec/lib/swagger/response_validation_spec.rb +104 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
- data/spec/lib/validator_spec.rb +59 -1
- data/spec/lib/validators/array_validator_spec.rb +28 -8
- data/spec/spec_helper.rb +49 -3
- data/spec/support/custom_bool_validator.rb +17 -0
- metadata +104 -99
- data/.travis.yml +0 -12
- data/Gemfile +0 -7
- data/Gemfile.rails32 +0 -6
- data/Gemfile.rails40 +0 -5
- data/Gemfile.rails41 +0 -5
- data/Gemfile.rails42 +0 -5
- data/lib/apipie/client/generator.rb +0 -135
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::Generator::Swagger::WarningWriter do
|
4
|
+
let(:writer) { described_class.clone.instance }
|
5
|
+
|
6
|
+
let(:warning) do
|
7
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
8
|
+
Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
|
9
|
+
'SampleController#action',
|
10
|
+
{ parameter: 'some-param' }
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
Apipie.configuration.swagger_suppress_warnings = false
|
16
|
+
Singleton.__init__(described_class)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#warn' do
|
20
|
+
subject { writer.warn(warning) }
|
21
|
+
|
22
|
+
it 'outputs the warning' do
|
23
|
+
expect { subject }.to output(warning.warning_message).to_stderr
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when Apipie.configuration.swagger_suppress_warnings is true' do
|
27
|
+
before { Apipie.configuration.swagger_suppress_warnings = true }
|
28
|
+
|
29
|
+
it { is_expected.to be_falsey }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when Apipie.configuration.swagger_suppress_warnings includes warning code' do
|
33
|
+
before do
|
34
|
+
Apipie.configuration.swagger_suppress_warnings =
|
35
|
+
Array(Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE)
|
36
|
+
end
|
37
|
+
|
38
|
+
it { is_expected.to be_falsey }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when a warning already been logged' do
|
42
|
+
before { writer.warn(warning) }
|
43
|
+
|
44
|
+
it { is_expected.to be_falsey }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#issued_warnings?' do
|
49
|
+
subject { writer.issued_warnings? }
|
50
|
+
|
51
|
+
it { is_expected.to be_falsey }
|
52
|
+
|
53
|
+
context 'when a warning already been logged' do
|
54
|
+
before { writer.warn(warning) }
|
55
|
+
|
56
|
+
it { is_expected.to be_truthy }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::MethodDescription::ApisService do
|
4
|
+
let(:resource) {}
|
5
|
+
let(:controller_action) {}
|
6
|
+
let(:api_args) { [] }
|
7
|
+
let(:dsl) { { api_args: api_args } }
|
8
|
+
let(:service) { described_class.new(resource, controller_action, dsl) }
|
9
|
+
|
10
|
+
describe '#call' do
|
11
|
+
subject { service.call }
|
12
|
+
|
13
|
+
it { is_expected.to eq(api_args) }
|
14
|
+
|
15
|
+
context 'when api_from_routes is given' do
|
16
|
+
let(:controller) { UsersController }
|
17
|
+
let(:controller_action) { :show }
|
18
|
+
let(:resource) { Apipie::ResourceDescription.new(controller, 'dummy') }
|
19
|
+
let(:short_description) { 'Short description' }
|
20
|
+
|
21
|
+
let(:dsl) do
|
22
|
+
super().merge({
|
23
|
+
api_from_routes: {
|
24
|
+
desc: short_description,
|
25
|
+
options: {}
|
26
|
+
}
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns an array of Apipie::MethodDescription::Api' do
|
31
|
+
expect(subject).to all(be_an_instance_of(Apipie::MethodDescription::Api))
|
32
|
+
expect(subject.count).to eq(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Apipie::MethodDescription::Api' do
|
36
|
+
subject { service.call.first }
|
37
|
+
|
38
|
+
it 'has the correct values' do
|
39
|
+
expect(subject.short_description).to eq(short_description)
|
40
|
+
expect(subject.path).to eq('/api/users/:id')
|
41
|
+
expect(subject.from_routes).to eq(true)
|
42
|
+
expect(subject.options).to eq({ from_routes: true })
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when it's from concern" do
|
46
|
+
let(:controller) { ConcernsController }
|
47
|
+
let(:controller_action) { :custom }
|
48
|
+
let(:dsl) { super().merge(from_concern: true ) }
|
49
|
+
|
50
|
+
it 'has the correct values' do
|
51
|
+
expect(subject.short_description).to eq(short_description)
|
52
|
+
expect(subject.path).to eq('/api/concern_resources/custom')
|
53
|
+
expect(subject.from_routes).to eq(true)
|
54
|
+
expect(subject.options).to eq({ from_routes: true })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -36,6 +36,13 @@ describe Apipie::MethodDescription do
|
|
36
36
|
method = Apipie::MethodDescription.new(:a, @resource, dsl_data)
|
37
37
|
expect(method.method_apis_to_json.first[:deprecated]).to eq(true)
|
38
38
|
end
|
39
|
+
|
40
|
+
it "should return the deprecated flag if resource is deprecated" do
|
41
|
+
@resource.instance_variable_set("@_deprecated", true)
|
42
|
+
dsl_data[:api_args] = [[:GET, "/foo/bar", "description", {}]]
|
43
|
+
method = Apipie::MethodDescription.new(:a, @resource, dsl_data)
|
44
|
+
expect(method.method_apis_to_json.first[:deprecated]).to eq(true)
|
45
|
+
end
|
39
46
|
end
|
40
47
|
|
41
48
|
describe "params descriptions" do
|
@@ -61,4 +68,31 @@ describe Apipie::MethodDescription do
|
|
61
68
|
|
62
69
|
end
|
63
70
|
|
71
|
+
describe "response-only properties" do
|
72
|
+
before(:each) do
|
73
|
+
@resource = Apipie::ResourceDescription.new(ApplicationController, "dummy")
|
74
|
+
dsl_data[:params] = [[:a, String, nil, {:only_in => :request}, nil],
|
75
|
+
[:b, String, nil, {:only_in => :response}, nil],
|
76
|
+
[:c, String, nil, {}, nil]]
|
77
|
+
@method = Apipie::MethodDescription.new(:a, @resource, dsl_data)
|
78
|
+
@resource.add_method_description @method
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should ignore response-only parameters" do
|
82
|
+
expect(@method.params.keys).to eq([:a, :c])
|
83
|
+
expect(@method.to_json[:params].map{|h| h[:name]}).to eq(['a', 'c'])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
describe "'returns' properties" do
|
89
|
+
it "should raise an error if both :param_group and :array_of are specified in 'returns'" do
|
90
|
+
@resource = Apipie::ResourceDescription.new(ApplicationController, "dummy")
|
91
|
+
dsl_data[:returns] = { 200 => [{:param_group => 'pet', :array_of => 'pet'}, nil, nil] }
|
92
|
+
|
93
|
+
expect {Apipie::MethodDescription.new(:a, @resource, dsl_data)}.to raise_error(Apipie::ReturnsMultipleDefinitionError)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
64
98
|
end
|
@@ -113,6 +113,92 @@ describe Apipie::ParamDescription do
|
|
113
113
|
|
114
114
|
end
|
115
115
|
|
116
|
+
describe 'validate' do
|
117
|
+
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
|
121
|
+
|
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
|
125
|
+
end
|
126
|
+
|
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)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
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
|
136
|
+
end
|
137
|
+
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
|
141
|
+
end
|
142
|
+
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
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
after do
|
151
|
+
Apipie.configuration.ignore_allow_blank_false = false
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
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
|
159
|
+
|
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
|
162
|
+
end
|
163
|
+
|
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)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
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
|
172
|
+
end
|
173
|
+
|
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
|
176
|
+
end
|
177
|
+
|
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)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
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
|
187
|
+
end
|
188
|
+
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 { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: false).validate('') }.to raise_error(Apipie::ParamInvalid)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
context 'when allow_blank is not specified' do
|
195
|
+
it "should throw an exception when passed an empty value" do
|
196
|
+
expect { Apipie::ParamDescription.new(method_desc, :param, String).validate('') }.to raise_error(Apipie::ParamInvalid)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
116
202
|
describe "concern substitution" do
|
117
203
|
|
118
204
|
let(:concern_dsl_data) { dsl_data.merge(:from_concern => true) }
|
@@ -288,7 +374,7 @@ describe Apipie::ParamDescription do
|
|
288
374
|
|
289
375
|
subject do
|
290
376
|
Apipie::ParamDescription.new(method_desc, :param, Hash) do
|
291
|
-
param :answer,
|
377
|
+
param :answer, Integer
|
292
378
|
end
|
293
379
|
end
|
294
380
|
|
@@ -306,7 +392,7 @@ describe Apipie::ParamDescription do
|
|
306
392
|
|
307
393
|
subject do
|
308
394
|
Apipie::ParamDescription.new(method_desc, :param, Array) do
|
309
|
-
param :answer,
|
395
|
+
param :answer, Integer
|
310
396
|
end
|
311
397
|
end
|
312
398
|
|
@@ -336,9 +422,9 @@ describe Apipie::ParamDescription do
|
|
336
422
|
|
337
423
|
describe "Array with classes" do
|
338
424
|
it "should be valid for objects included in class array" do
|
339
|
-
param = Apipie::ParamDescription.new(method_desc, :param, [
|
425
|
+
param = Apipie::ParamDescription.new(method_desc, :param, [Integer, String])
|
340
426
|
expect { param.validate("1") }.not_to raise_error
|
341
|
-
expect { param.validate(
|
427
|
+
expect { param.validate(Integer) }.to raise_error(Apipie::ParamInvalid)
|
342
428
|
end
|
343
429
|
end
|
344
430
|
|
data/spec/lib/rake_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'rake tasks' do
|
4
4
|
include_context "rake"
|
5
5
|
|
6
|
-
let(:doc_path) {
|
6
|
+
let(:doc_path) { 'tmp/user_specified_doc_path' }
|
7
7
|
|
8
8
|
before do
|
9
9
|
Apipie.configuration.doc_path = doc_path
|
@@ -49,9 +49,7 @@ describe 'rake tasks' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe 'apipie:cache' do
|
52
|
-
let(:cache_output)
|
53
|
-
File.join(::Rails.root, 'public', 'apipie-cache')
|
54
|
-
end
|
52
|
+
let(:cache_output) { Apipie.configuration.cache_dir }
|
55
53
|
|
56
54
|
let(:apidoc_html) do
|
57
55
|
File.read("#{cache_output}.html")
|