apipie-rails 0.3.6 → 0.5.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +23 -7
- data/CHANGELOG.md +147 -2
- data/Gemfile +1 -0
- data/Gemfile.rails41 +2 -0
- data/Gemfile.rails42 +10 -1
- data/Gemfile.rails50 +9 -0
- data/Gemfile.rails51 +9 -0
- data/Gemfile.rails60 +14 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +570 -17
- data/apipie-rails.gemspec +3 -3
- data/app/controllers/apipie/apipies_controller.rb +48 -17
- 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/lib/apipie/apipie_module.rb +22 -4
- data/lib/apipie/application.rb +55 -28
- data/lib/apipie/configuration.rb +19 -3
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +151 -10
- 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 +13 -12
- data/lib/apipie/extractor/writer.rb +83 -55
- data/lib/apipie/extractor.rb +10 -4
- data/lib/apipie/method_description.rb +51 -4
- data/lib/apipie/param_description.rb +56 -2
- data/lib/apipie/resource_description.rb +10 -3
- 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 +3 -2
- data/lib/apipie/swagger_generator.rb +708 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +69 -8
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +7 -0
- data/lib/tasks/apipie.rake +103 -8
- data/spec/controllers/apipies_controller_spec.rb +52 -12
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/memes_controller_spec.rb +10 -0
- data/spec/controllers/users_controller_spec.rb +115 -75
- data/spec/dummy/app/controllers/application_controller.rb +5 -1
- data/spec/dummy/app/controllers/concerns/extending_concern.rb +12 -0
- data/spec/dummy/app/controllers/concerns/sample_controller.rb +5 -5
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- 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/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 +19 -11
- 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 +5 -0
- data/spec/dummy/config/environments/development.rb +3 -0
- data/spec/dummy/config/environments/production.rb +3 -0
- data/spec/dummy/config/environments/test.rb +3 -0
- data/spec/dummy/config/initializers/apipie.rb +3 -1
- data/spec/dummy/config/routes.rb +24 -1
- data/spec/lib/extractor/writer_spec.rb +32 -4
- data/spec/lib/file_handler_spec.rb +18 -0
- data/spec/lib/method_description_spec.rb +34 -0
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +139 -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 +58 -0
- data/spec/lib/validators/array_validator_spec.rb +28 -8
- data/spec/spec_helper.rb +68 -0
- metadata +75 -23
- data/Gemfile +0 -7
- data/Gemfile.rails32 +0 -6
- data/Gemfile.rails40 +0 -5
- data/lib/apipie/client/generator.rb +0 -135
data/spec/lib/validator_spec.rb
CHANGED
@@ -42,6 +42,29 @@ describe Apipie::Validator do
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
+
describe 'NumberValidator' do
|
46
|
+
it 'should expect a Numeric type' do
|
47
|
+
validator = Apipie::Validator::BaseValidator.find(params_desc, :number, nil, nil)
|
48
|
+
expect(validator.expected_type).to eq('numeric')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
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
|
62
|
+
end
|
63
|
+
|
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>.')
|
67
|
+
end
|
45
68
|
end
|
46
69
|
|
47
70
|
describe 'ArrayClassValidator' do
|
@@ -51,5 +74,40 @@ describe Apipie::Validator do
|
|
51
74
|
expect(validator.validate(1)).to be_truthy
|
52
75
|
expect(validator.validate({ 1 => 1 })).to be_falsey
|
53
76
|
end
|
77
|
+
|
78
|
+
it "should have a valid description" do
|
79
|
+
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Float, String])
|
80
|
+
expect(validator.description).to eq('Must be one of: <code>Float</code>, <code>String</code>.')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'RegexpValidator' do
|
85
|
+
it "should validate by object class" do
|
86
|
+
validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
|
87
|
+
expect(validator.validate("valid")).to be_truthy
|
88
|
+
expect(validator.validate("valid extra")).to be_truthy
|
89
|
+
expect(validator.validate("valid extra extra")).to be_truthy
|
90
|
+
expect(validator.validate("invalid")).to be_falsey
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have a valid description" do
|
94
|
+
validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
|
95
|
+
expect(validator.description).to eq('Must match regular expression <code>/^valid( extra)*$/</code>.')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'EnumValidator' do
|
100
|
+
it "should validate by object class" do
|
101
|
+
validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
|
102
|
+
expect(validator.validate("first")).to be_truthy
|
103
|
+
expect(validator.validate("second & third")).to be_truthy
|
104
|
+
expect(validator.validate(1)).to be_falsey
|
105
|
+
expect(validator.validate({ 1 => 1 })).to be_falsey
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have a valid description" do
|
109
|
+
validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
|
110
|
+
expect(validator.description).to eq('Must be one of: <code>first</code>, <code>second & third</code>.')
|
111
|
+
end
|
54
112
|
end
|
55
113
|
end
|
@@ -24,18 +24,38 @@ module Apipie::Validator
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context "with a constraint on items type" do
|
27
|
-
let(:validator) { ArrayValidator.new(param_desc, Array, :of =>
|
27
|
+
let(:validator) { ArrayValidator.new(param_desc, Array, :of => type) }
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
29
|
+
context "String" do
|
30
|
+
let(:type) { String }
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
it "accepts array of specified type" do
|
33
|
+
expect(validator.validate(['string1', 'string2'])).to eq(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "accepts empty array" do
|
37
|
+
expect(validator.validate([])).to eq(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not accepts array with other types" do
|
41
|
+
expect(validator.validate(['string1', true])).to eq(false)
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
|
-
|
38
|
-
|
45
|
+
context ":number" do
|
46
|
+
let(:type) { :decimal }
|
47
|
+
|
48
|
+
it "accepts array of specified type" do
|
49
|
+
expect(validator.validate([12, '14'])).to eq(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "accepts empty array" do
|
53
|
+
expect(validator.validate([])).to eq(true)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not accepts array with other types" do
|
57
|
+
expect(validator.validate([12, 'potato'])).to eq(false)
|
58
|
+
end
|
39
59
|
end
|
40
60
|
end
|
41
61
|
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,71 @@ require File.expand_path("../dummy/config/environment", __FILE__)
|
|
8
8
|
require 'rspec/rails'
|
9
9
|
|
10
10
|
require 'apipie-rails'
|
11
|
+
require 'test_engine'
|
12
|
+
|
13
|
+
module Rails4Compatibility
|
14
|
+
module Testing
|
15
|
+
def process(*args)
|
16
|
+
compatible_request(*args) { |*new_args| super(*new_args) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def compatible_request(method, action, hash = {})
|
20
|
+
if hash.is_a?(Hash)
|
21
|
+
if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
|
22
|
+
hash = hash.dup
|
23
|
+
hash.merge!(hash.delete(:params) || {})
|
24
|
+
elsif hash.key?(:params)
|
25
|
+
hash = { :params => hash }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if hash.empty?
|
29
|
+
yield method, action
|
30
|
+
else
|
31
|
+
yield method, action, hash
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
#
|
39
|
+
# Matcher to validate the properties (name, type and options) of a single field in the
|
40
|
+
# internal representation of a swagger schema
|
41
|
+
#
|
42
|
+
# For example, code such as:
|
43
|
+
# schema = swagger[:paths][<path>][<method>][:responses][<code>][:schema]
|
44
|
+
# expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
45
|
+
#
|
46
|
+
# will verify that the selected response schema includes a required string field called 'pet_name'
|
47
|
+
#
|
48
|
+
RSpec::Matchers.define :have_field do |name, type, opts={}|
|
49
|
+
def fail(msg)
|
50
|
+
@fail_message = msg
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
@fail_message = ""
|
55
|
+
|
56
|
+
failure_message do |actual|
|
57
|
+
@fail_message
|
58
|
+
end
|
59
|
+
|
60
|
+
match do |unresolved|
|
61
|
+
actual = resolve_refs(unresolved)
|
62
|
+
return fail("expected schema to have type 'object' (got '#{actual[:type]}')") if (actual[:type]) != 'object'
|
63
|
+
return fail("expected schema to include param named '#{name}' (got #{actual[:properties].keys})") if (prop = actual[:properties][name]).nil?
|
64
|
+
return fail("expected param '#{name}' to have type '#{type}' (got '#{prop[:type]}')") if prop[:type] != type
|
65
|
+
return fail("expected param '#{name}' to have description '#{opts[:description]}' (got '#{prop[:description]}')") if opts[:description] && prop[:description] != opts[:description]
|
66
|
+
return fail("expected param '#{name}' to have enum '#{opts[:enum]}' (got #{prop[:enum]})") if opts[:enum] && prop[:enum] != opts[:enum]
|
67
|
+
return fail("expected param '#{name}' to have items '#{opts[:items]}' (got #{prop[:items]})") if opts[:items] && prop[:items] != opts[:items]
|
68
|
+
if !opts.include?(:required) || opts[:required] == true
|
69
|
+
return fail("expected param '#{name}' to be required") unless actual[:required].include?(name)
|
70
|
+
else
|
71
|
+
return fail("expected param '#{name}' to be optional") if actual[:required].include?(name)
|
72
|
+
end
|
73
|
+
true
|
74
|
+
end
|
75
|
+
end
|
11
76
|
|
12
77
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
13
78
|
# in spec/support/ and its subdirectories.
|
@@ -41,3 +106,6 @@ RSpec.configure do |config|
|
|
41
106
|
# end
|
42
107
|
config.infer_spec_type_from_file_location!
|
43
108
|
end
|
109
|
+
|
110
|
+
require 'action_controller/test_case.rb'
|
111
|
+
ActionController::TestCase::Behavior.send(:prepend, Rails4Compatibility::Testing)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apipie-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pokorny
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,28 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 3.0.20
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: json
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
20
|
+
version: '4.1'
|
35
21
|
type: :runtime
|
36
22
|
prerelease: false
|
37
23
|
version_requirements: !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
25
|
- - ">="
|
40
26
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
27
|
+
version: '4.1'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: rspec-rails
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +123,20 @@ dependencies:
|
|
137
123
|
- - ">="
|
138
124
|
- !ruby/object:Gem::Version
|
139
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: json-schema
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '2.8'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '2.8'
|
140
140
|
description: Rails REST API documentation tool
|
141
141
|
email:
|
142
142
|
- pajkycz@gmail.com
|
@@ -151,12 +151,14 @@ files:
|
|
151
151
|
- APACHE-LICENSE-2.0
|
152
152
|
- CHANGELOG.md
|
153
153
|
- Gemfile
|
154
|
-
- Gemfile.rails32
|
155
|
-
- Gemfile.rails40
|
156
154
|
- Gemfile.rails41
|
157
155
|
- Gemfile.rails42
|
156
|
+
- Gemfile.rails50
|
157
|
+
- Gemfile.rails51
|
158
|
+
- Gemfile.rails60
|
158
159
|
- MIT-LICENSE
|
159
160
|
- NOTICE
|
161
|
+
- PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md
|
160
162
|
- README.rst
|
161
163
|
- Rakefile
|
162
164
|
- apipie-rails.gemspec
|
@@ -191,6 +193,9 @@ files:
|
|
191
193
|
- config/locales/de.yml
|
192
194
|
- config/locales/en.yml
|
193
195
|
- config/locales/es.yml
|
196
|
+
- config/locales/fr.yml
|
197
|
+
- config/locales/it.yml
|
198
|
+
- config/locales/ja.yml
|
194
199
|
- config/locales/pl.yml
|
195
200
|
- config/locales/pt-BR.yml
|
196
201
|
- config/locales/ru.yml
|
@@ -202,8 +207,8 @@ files:
|
|
202
207
|
- lib/apipie-rails.rb
|
203
208
|
- lib/apipie/apipie_module.rb
|
204
209
|
- lib/apipie/application.rb
|
205
|
-
- lib/apipie/client/generator.rb
|
206
210
|
- lib/apipie/configuration.rb
|
211
|
+
- lib/apipie/core_ext/route.rb
|
207
212
|
- lib/apipie/dsl_definition.rb
|
208
213
|
- lib/apipie/error_description.rb
|
209
214
|
- lib/apipie/errors.rb
|
@@ -218,10 +223,15 @@ files:
|
|
218
223
|
- lib/apipie/param_description.rb
|
219
224
|
- lib/apipie/railtie.rb
|
220
225
|
- lib/apipie/resource_description.rb
|
226
|
+
- lib/apipie/response_description.rb
|
227
|
+
- lib/apipie/response_description_adapter.rb
|
221
228
|
- lib/apipie/routes_formatter.rb
|
222
229
|
- lib/apipie/routing.rb
|
230
|
+
- lib/apipie/rspec/response_validation_helper.rb
|
223
231
|
- lib/apipie/see_description.rb
|
224
232
|
- lib/apipie/static_dispatcher.rb
|
233
|
+
- lib/apipie/swagger_generator.rb
|
234
|
+
- lib/apipie/tag_list_description.rb
|
225
235
|
- lib/apipie/validator.rb
|
226
236
|
- lib/apipie/version.rb
|
227
237
|
- lib/generators/apipie/install/README
|
@@ -237,6 +247,8 @@ files:
|
|
237
247
|
- spec/controllers/api/v2/nested/resources_controller_spec.rb
|
238
248
|
- spec/controllers/apipies_controller_spec.rb
|
239
249
|
- spec/controllers/concerns_controller_spec.rb
|
250
|
+
- spec/controllers/extended_controller_spec.rb
|
251
|
+
- spec/controllers/memes_controller_spec.rb
|
240
252
|
- spec/controllers/users_controller_spec.rb
|
241
253
|
- spec/dummy/Rakefile
|
242
254
|
- spec/dummy/app/controllers/api/base_controller.rb
|
@@ -247,13 +259,27 @@ files:
|
|
247
259
|
- spec/dummy/app/controllers/api/v2/nested/architectures_controller.rb
|
248
260
|
- spec/dummy/app/controllers/api/v2/nested/resources_controller.rb
|
249
261
|
- spec/dummy/app/controllers/application_controller.rb
|
262
|
+
- spec/dummy/app/controllers/concerns/extending_concern.rb
|
250
263
|
- spec/dummy/app/controllers/concerns/sample_controller.rb
|
251
264
|
- spec/dummy/app/controllers/concerns_controller.rb
|
265
|
+
- spec/dummy/app/controllers/extended_controller.rb
|
252
266
|
- spec/dummy/app/controllers/files_controller.rb
|
253
267
|
- spec/dummy/app/controllers/overridden_concerns_controller.rb
|
268
|
+
- spec/dummy/app/controllers/pets_controller.rb
|
269
|
+
- spec/dummy/app/controllers/pets_using_auto_views_controller.rb
|
270
|
+
- spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb
|
271
|
+
- spec/dummy/app/controllers/tagged_cats_controller.rb
|
272
|
+
- spec/dummy/app/controllers/tagged_dogs_controller.rb
|
254
273
|
- spec/dummy/app/controllers/twitter_example_controller.rb
|
255
274
|
- spec/dummy/app/controllers/users_controller.rb
|
256
275
|
- spec/dummy/app/views/layouts/application.html.erb
|
276
|
+
- spec/dummy/components/test_engine/Gemfile
|
277
|
+
- spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb
|
278
|
+
- spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb
|
279
|
+
- spec/dummy/components/test_engine/config/routes.rb
|
280
|
+
- spec/dummy/components/test_engine/db/.gitkeep
|
281
|
+
- spec/dummy/components/test_engine/lib/test_engine.rb
|
282
|
+
- spec/dummy/components/test_engine/test_engine.gemspec
|
257
283
|
- spec/dummy/config.ru
|
258
284
|
- spec/dummy/config/application.rb
|
259
285
|
- spec/dummy/config/boot.rb
|
@@ -283,11 +309,16 @@ files:
|
|
283
309
|
- spec/lib/extractor/extractor_spec.rb
|
284
310
|
- spec/lib/extractor/middleware_spec.rb
|
285
311
|
- spec/lib/extractor/writer_spec.rb
|
312
|
+
- spec/lib/file_handler_spec.rb
|
286
313
|
- spec/lib/method_description_spec.rb
|
287
314
|
- spec/lib/param_description_spec.rb
|
288
315
|
- spec/lib/param_group_spec.rb
|
289
316
|
- spec/lib/rake_spec.rb
|
290
317
|
- spec/lib/resource_description_spec.rb
|
318
|
+
- spec/lib/swagger/openapi_2_0_schema.json
|
319
|
+
- spec/lib/swagger/rake_swagger_spec.rb
|
320
|
+
- spec/lib/swagger/response_validation_spec.rb
|
321
|
+
- spec/lib/swagger/swagger_dsl_spec.rb
|
291
322
|
- spec/lib/validator_spec.rb
|
292
323
|
- spec/lib/validators/array_validator_spec.rb
|
293
324
|
- spec/spec_helper.rb
|
@@ -303,7 +334,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
303
334
|
requirements:
|
304
335
|
- - ">="
|
305
336
|
- !ruby/object:Gem::Version
|
306
|
-
version:
|
337
|
+
version: 2.0.0
|
307
338
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
308
339
|
requirements:
|
309
340
|
- - ">="
|
@@ -311,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
311
342
|
version: '0'
|
312
343
|
requirements: []
|
313
344
|
rubyforge_project:
|
314
|
-
rubygems_version: 2.
|
345
|
+
rubygems_version: 2.7.10
|
315
346
|
signing_key:
|
316
347
|
specification_version: 4
|
317
348
|
summary: Rails REST API documentation tool
|
@@ -321,6 +352,8 @@ test_files:
|
|
321
352
|
- spec/controllers/api/v2/nested/resources_controller_spec.rb
|
322
353
|
- spec/controllers/apipies_controller_spec.rb
|
323
354
|
- spec/controllers/concerns_controller_spec.rb
|
355
|
+
- spec/controllers/extended_controller_spec.rb
|
356
|
+
- spec/controllers/memes_controller_spec.rb
|
324
357
|
- spec/controllers/users_controller_spec.rb
|
325
358
|
- spec/dummy/Rakefile
|
326
359
|
- spec/dummy/app/controllers/api/base_controller.rb
|
@@ -331,13 +364,27 @@ test_files:
|
|
331
364
|
- spec/dummy/app/controllers/api/v2/nested/architectures_controller.rb
|
332
365
|
- spec/dummy/app/controllers/api/v2/nested/resources_controller.rb
|
333
366
|
- spec/dummy/app/controllers/application_controller.rb
|
367
|
+
- spec/dummy/app/controllers/concerns/extending_concern.rb
|
334
368
|
- spec/dummy/app/controllers/concerns/sample_controller.rb
|
335
369
|
- spec/dummy/app/controllers/concerns_controller.rb
|
370
|
+
- spec/dummy/app/controllers/extended_controller.rb
|
336
371
|
- spec/dummy/app/controllers/files_controller.rb
|
337
372
|
- spec/dummy/app/controllers/overridden_concerns_controller.rb
|
373
|
+
- spec/dummy/app/controllers/pets_controller.rb
|
374
|
+
- spec/dummy/app/controllers/pets_using_auto_views_controller.rb
|
375
|
+
- spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb
|
376
|
+
- spec/dummy/app/controllers/tagged_cats_controller.rb
|
377
|
+
- spec/dummy/app/controllers/tagged_dogs_controller.rb
|
338
378
|
- spec/dummy/app/controllers/twitter_example_controller.rb
|
339
379
|
- spec/dummy/app/controllers/users_controller.rb
|
340
380
|
- spec/dummy/app/views/layouts/application.html.erb
|
381
|
+
- spec/dummy/components/test_engine/Gemfile
|
382
|
+
- spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb
|
383
|
+
- spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb
|
384
|
+
- spec/dummy/components/test_engine/config/routes.rb
|
385
|
+
- spec/dummy/components/test_engine/db/.gitkeep
|
386
|
+
- spec/dummy/components/test_engine/lib/test_engine.rb
|
387
|
+
- spec/dummy/components/test_engine/test_engine.gemspec
|
341
388
|
- spec/dummy/config.ru
|
342
389
|
- spec/dummy/config/application.rb
|
343
390
|
- spec/dummy/config/boot.rb
|
@@ -367,11 +414,16 @@ test_files:
|
|
367
414
|
- spec/lib/extractor/extractor_spec.rb
|
368
415
|
- spec/lib/extractor/middleware_spec.rb
|
369
416
|
- spec/lib/extractor/writer_spec.rb
|
417
|
+
- spec/lib/file_handler_spec.rb
|
370
418
|
- spec/lib/method_description_spec.rb
|
371
419
|
- spec/lib/param_description_spec.rb
|
372
420
|
- spec/lib/param_group_spec.rb
|
373
421
|
- spec/lib/rake_spec.rb
|
374
422
|
- spec/lib/resource_description_spec.rb
|
423
|
+
- spec/lib/swagger/openapi_2_0_schema.json
|
424
|
+
- spec/lib/swagger/rake_swagger_spec.rb
|
425
|
+
- spec/lib/swagger/response_validation_spec.rb
|
426
|
+
- spec/lib/swagger/swagger_dsl_spec.rb
|
375
427
|
- spec/lib/validator_spec.rb
|
376
428
|
- spec/lib/validators/array_validator_spec.rb
|
377
429
|
- spec/spec_helper.rb
|
data/Gemfile
DELETED
data/Gemfile.rails32
DELETED
data/Gemfile.rails40
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
#!/bin/env ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'thor'
|
5
|
-
require 'thor/group'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'active_support/inflector'
|
8
|
-
require 'apipie/client/base'
|
9
|
-
|
10
|
-
module Apipie
|
11
|
-
module Client
|
12
|
-
|
13
|
-
class Generator < Thor::Group
|
14
|
-
include Thor::Actions
|
15
|
-
|
16
|
-
# Define arguments and options
|
17
|
-
argument :name
|
18
|
-
argument :subject
|
19
|
-
argument :suffix
|
20
|
-
argument :version
|
21
|
-
|
22
|
-
attr_reader :doc, :resource, :resource_key
|
23
|
-
|
24
|
-
def initialize(*args)
|
25
|
-
super
|
26
|
-
@doc = Apipie.to_json(version)[:docs]
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.source_root
|
30
|
-
File.expand_path("../template", __FILE__)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.destination_root(name, suffix)
|
34
|
-
File.join(FileUtils.pwd, "#{name}#{suffix}")
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.start(client_name, subject = :all, suffix = '_client', version = nil)
|
38
|
-
name = client_name.parameterize.underscore
|
39
|
-
suffix = suffix.parameterize.underscore
|
40
|
-
super([name, subject, suffix, version], :destination_root => destination_root(name, suffix))
|
41
|
-
end
|
42
|
-
|
43
|
-
def all?
|
44
|
-
subject == :all
|
45
|
-
end
|
46
|
-
|
47
|
-
def generate_cli
|
48
|
-
full_name = "#{name}#{suffix}"
|
49
|
-
template("README.tt", "README")
|
50
|
-
template("Gemfile.tt", "Gemfile")
|
51
|
-
template("Rakefile.tt", "Rakefile")
|
52
|
-
template("a_name.gemspec.tt", "#{full_name}.gemspec")
|
53
|
-
template("lib/a_name.rb.tt", "lib/#{full_name}.rb")
|
54
|
-
template("lib/a_name/version.rb.tt", "lib/#{full_name}/version.rb")
|
55
|
-
create_file "lib/#{full_name}/documentation.json", JSON.dump(Apipie.to_json)
|
56
|
-
copy_file "lib/a_name/config.yml", "lib/#{full_name}/config.yml"
|
57
|
-
if all?
|
58
|
-
template("bin/bin.rb.tt", "bin/#{full_name}")
|
59
|
-
chmod("bin/#{full_name}", 0755)
|
60
|
-
end
|
61
|
-
doc[:resources].each do |key, resource|
|
62
|
-
@resource_key, @resource = key, resource
|
63
|
-
if all?
|
64
|
-
template("lib/a_name/commands/cli.rb.tt", "lib/#{full_name}/commands/#{resource_name}.thor")
|
65
|
-
end
|
66
|
-
template("lib/a_name/resources/resource.rb.tt", "lib/#{full_name}/resources/#{resource_name}.rb")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
|
72
|
-
def camelizer(string)
|
73
|
-
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
74
|
-
string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$2.capitalize}" }
|
75
|
-
end
|
76
|
-
|
77
|
-
def class_base
|
78
|
-
@class_base ||= camelizer(name)
|
79
|
-
end
|
80
|
-
|
81
|
-
def class_suffix
|
82
|
-
@class_suffix ||= camelizer(suffix)
|
83
|
-
end
|
84
|
-
|
85
|
-
def plaintext(text)
|
86
|
-
text.gsub(/<.*?>/, '').gsub("\n", ' ').strip
|
87
|
-
end
|
88
|
-
|
89
|
-
# Resource related helper methods:
|
90
|
-
|
91
|
-
def resource_name
|
92
|
-
resource[:name].gsub(/\s/, "_").downcase.singularize
|
93
|
-
end
|
94
|
-
|
95
|
-
def api(method)
|
96
|
-
method[:apis].first
|
97
|
-
end
|
98
|
-
|
99
|
-
def params_in_path(method)
|
100
|
-
api(method)[:api_url].scan(/:([^\/]*)/).map(&:first)
|
101
|
-
end
|
102
|
-
|
103
|
-
def client_args(method)
|
104
|
-
params_in_path(method).dup
|
105
|
-
end
|
106
|
-
|
107
|
-
def substituted_url(method)
|
108
|
-
params_in_path(method).reduce(api(method)[:api_url]) { |u, p| u.sub(":#{p}", "\#{#{p}}") }
|
109
|
-
end
|
110
|
-
|
111
|
-
def transformation_hash(method)
|
112
|
-
method[:params].find_all { |p| p[:expected_type] == "hash" && !p[:params].nil? }.reduce({ }) do |h, p|
|
113
|
-
h.update(p[:name] => p[:params].map { |pp| pp[:name] })
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def validation(method)
|
118
|
-
stringify = lambda do |object|
|
119
|
-
case object
|
120
|
-
when Hash
|
121
|
-
clone = object.dup
|
122
|
-
object.keys.each { |key| clone[key.to_s] = stringify[clone.delete(key)] }
|
123
|
-
clone
|
124
|
-
when Array
|
125
|
-
object.map { |value| stringify[value] }
|
126
|
-
else
|
127
|
-
object
|
128
|
-
end
|
129
|
-
end
|
130
|
-
Apipie::Client::Base.construct_validation_hash(stringify[method])
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|