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/lib/apipie/validator.rb
CHANGED
@@ -13,6 +13,16 @@ module Apipie
|
|
13
13
|
@param_description = param_description
|
14
14
|
end
|
15
15
|
|
16
|
+
def inspected_fields
|
17
|
+
[:param_description]
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
string = "#<#{self.class.name}:#{self.object_id} "
|
22
|
+
fields = inspected_fields.map {|field| "#{field}: #{self.send(field)}"}
|
23
|
+
string << fields.join(", ") << ">"
|
24
|
+
end
|
25
|
+
|
16
26
|
def self.inherited(subclass)
|
17
27
|
@validators ||= []
|
18
28
|
@validators.insert 0, subclass
|
@@ -47,6 +57,10 @@ module Apipie
|
|
47
57
|
"TODO: validator description"
|
48
58
|
end
|
49
59
|
|
60
|
+
def format_description_value(value)
|
61
|
+
"<code>#{CGI::escapeHTML(value.to_s)}</code>"
|
62
|
+
end
|
63
|
+
|
50
64
|
def error
|
51
65
|
ParamInvalid.new(param_name, @error_value, description)
|
52
66
|
end
|
@@ -67,13 +81,22 @@ module Apipie
|
|
67
81
|
end
|
68
82
|
|
69
83
|
def merge_with(other_validator)
|
70
|
-
|
84
|
+
return self if self == other_validator
|
85
|
+
raise NotImplementedError, "Don't know how to merge #{self.inspect} with #{other_validator.inspect}"
|
71
86
|
end
|
72
87
|
|
73
88
|
def params_ordered
|
74
89
|
nil
|
75
90
|
end
|
76
91
|
|
92
|
+
def ==(other)
|
93
|
+
return false unless self.class == other.class
|
94
|
+
if param_description == other.param_description
|
95
|
+
true
|
96
|
+
else
|
97
|
+
false
|
98
|
+
end
|
99
|
+
end
|
77
100
|
end
|
78
101
|
|
79
102
|
# validate arguments type
|
@@ -96,7 +119,7 @@ module Apipie
|
|
96
119
|
end
|
97
120
|
|
98
121
|
def description
|
99
|
-
"Must be #{@type}"
|
122
|
+
"Must be a #{@type}"
|
100
123
|
end
|
101
124
|
|
102
125
|
def expected_type
|
@@ -106,6 +129,8 @@ module Apipie
|
|
106
129
|
'array'
|
107
130
|
elsif @type.ancestors.include? Numeric
|
108
131
|
'numeric'
|
132
|
+
elsif @type.ancestors.include? File
|
133
|
+
'file'
|
109
134
|
else
|
110
135
|
'string'
|
111
136
|
end
|
@@ -129,7 +154,7 @@ module Apipie
|
|
129
154
|
end
|
130
155
|
|
131
156
|
def description
|
132
|
-
"Must match regular expression
|
157
|
+
"Must match regular expression #{format_description_value("/#{@regexp.source}/")}."
|
133
158
|
end
|
134
159
|
end
|
135
160
|
|
@@ -148,8 +173,12 @@ module Apipie
|
|
148
173
|
self.new(param_description, argument) if argument.is_a?(Array)
|
149
174
|
end
|
150
175
|
|
176
|
+
def values
|
177
|
+
@array
|
178
|
+
end
|
179
|
+
|
151
180
|
def description
|
152
|
-
string = @array.map { |value|
|
181
|
+
string = @array.map { |value| format_description_value(value) }.join(', ')
|
153
182
|
"Must be one of: #{string}."
|
154
183
|
end
|
155
184
|
end
|
@@ -202,7 +231,13 @@ module Apipie
|
|
202
231
|
|
203
232
|
def has_valid_type?(value)
|
204
233
|
if @items_type
|
205
|
-
|
234
|
+
item_validator = BaseValidator.find('', @items_type, nil, nil)
|
235
|
+
|
236
|
+
if item_validator
|
237
|
+
item_validator.valid?(value)
|
238
|
+
else
|
239
|
+
value.kind_of?(@items_type)
|
240
|
+
end
|
206
241
|
else
|
207
242
|
true
|
208
243
|
end
|
@@ -243,7 +278,8 @@ module Apipie
|
|
243
278
|
end
|
244
279
|
|
245
280
|
def description
|
246
|
-
|
281
|
+
string = @array.map { |value| format_description_value(value) }.join(', ')
|
282
|
+
"Must be one of: #{string}."
|
247
283
|
end
|
248
284
|
end
|
249
285
|
|
@@ -375,6 +411,27 @@ module Apipie
|
|
375
411
|
end
|
376
412
|
end
|
377
413
|
|
414
|
+
class DecimalValidator < BaseValidator
|
415
|
+
|
416
|
+
def validate(value)
|
417
|
+
self.class.validate(value)
|
418
|
+
end
|
419
|
+
|
420
|
+
def self.build(param_description, argument, options, block)
|
421
|
+
if argument == :decimal
|
422
|
+
self.new(param_description)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
def description
|
427
|
+
"Must be a decimal number."
|
428
|
+
end
|
429
|
+
|
430
|
+
def self.validate(value)
|
431
|
+
value.to_s =~ /\A^[-+]?[0-9]+([,.][0-9]+)?\Z$/
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
378
435
|
class NumberValidator < BaseValidator
|
379
436
|
|
380
437
|
def validate(value)
|
@@ -391,6 +448,10 @@ module Apipie
|
|
391
448
|
"Must be a number."
|
392
449
|
end
|
393
450
|
|
451
|
+
def expected_type
|
452
|
+
'numeric'
|
453
|
+
end
|
454
|
+
|
394
455
|
def self.validate(value)
|
395
456
|
value.to_s =~ /\A(0|[1-9]\d*)\Z$/
|
396
457
|
end
|
@@ -413,7 +474,8 @@ module Apipie
|
|
413
474
|
end
|
414
475
|
|
415
476
|
def description
|
416
|
-
|
477
|
+
string = %w(true false 1 0).map { |value| format_description_value(value) }.join(', ')
|
478
|
+
"Must be one of: #{string}."
|
417
479
|
end
|
418
480
|
end
|
419
481
|
|
@@ -464,4 +526,3 @@ module Apipie
|
|
464
526
|
|
465
527
|
end
|
466
528
|
end
|
467
|
-
|
data/lib/apipie/version.rb
CHANGED
data/lib/apipie-rails.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'i18n'
|
2
|
+
require 'json'
|
2
3
|
require 'active_support/hash_with_indifferent_access'
|
3
4
|
|
5
|
+
require 'apipie/core_ext/route.rb'
|
6
|
+
|
4
7
|
require "apipie/routing"
|
5
8
|
require "apipie/markup"
|
6
9
|
require "apipie/apipie_module"
|
@@ -11,11 +14,15 @@ require "apipie/resource_description"
|
|
11
14
|
require "apipie/param_description"
|
12
15
|
require "apipie/errors"
|
13
16
|
require "apipie/error_description"
|
17
|
+
require "apipie/response_description"
|
18
|
+
require "apipie/response_description_adapter"
|
14
19
|
require "apipie/see_description"
|
20
|
+
require "apipie/tag_list_description"
|
15
21
|
require "apipie/validator"
|
16
22
|
require "apipie/railtie"
|
17
23
|
require 'apipie/extractor'
|
18
24
|
require "apipie/version"
|
25
|
+
require "apipie/swagger_generator"
|
19
26
|
|
20
27
|
if Rails.version.start_with?("3.0")
|
21
28
|
warn 'Warning: apipie-rails is not going to support Rails 3.0 anymore in future versions'
|
data/lib/tasks/apipie.rake
CHANGED
@@ -51,6 +51,71 @@ namespace :apipie do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
desc "Generate static swagger json"
|
55
|
+
task :static_swagger_json, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
|
56
|
+
with_loaded_documentation do
|
57
|
+
out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
|
58
|
+
generate_swagger_using_args(args, out)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# The following task compares the currently-generated swagger output to a reference copy generated
|
63
|
+
# by the previous execution of this task.
|
64
|
+
# if a difference is detected, the current output will be stored as a reference.
|
65
|
+
# reference files have the
|
66
|
+
# if more than 3 references are detected, the older ones will be purged
|
67
|
+
desc "Did swagger output change since the last execution of this task?"
|
68
|
+
task :did_swagger_change, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
|
69
|
+
with_loaded_documentation do
|
70
|
+
out = ENV["OUT_REF"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc_ref')
|
71
|
+
paths = generate_swagger_using_args(args, out)
|
72
|
+
paths.each {|path|
|
73
|
+
existing_files_in_dir = Pathname(out).children(true)
|
74
|
+
|
75
|
+
make_reference = false
|
76
|
+
|
77
|
+
# reference filenames have the format <basename>.<counter>.swagger_ref
|
78
|
+
reference_files = existing_files_in_dir.select{|f|
|
79
|
+
f.extname == '.swagger_ref' &&
|
80
|
+
f.basename.sub_ext("").extname.delete('.').to_i > 0 &&
|
81
|
+
f.basename.sub_ext("").sub_ext("") == path.basename.sub_ext("")
|
82
|
+
}
|
83
|
+
if reference_files.empty?
|
84
|
+
print "Reference file does not exist for [#{path}]\n"
|
85
|
+
counter = 1
|
86
|
+
make_reference = true
|
87
|
+
else
|
88
|
+
reference_files.sort_by! {|f| f.ctime }
|
89
|
+
last_ref = reference_files[-1]
|
90
|
+
print "Comparing [#{path}] to reference file: [#{last_ref.basename}]: "
|
91
|
+
if !FileUtils.compare_file(path, last_ref)
|
92
|
+
print("\n ---> Differences detected\n")
|
93
|
+
counter = last_ref.sub_ext("").extname.delete('.').to_i + 1
|
94
|
+
make_reference = true
|
95
|
+
else
|
96
|
+
print("identical\n")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if make_reference
|
101
|
+
new_path = path.sub_ext(".#{counter}.swagger_ref")
|
102
|
+
print " ---> Keeping current output as [#{new_path}]\n"
|
103
|
+
path.rename(new_path)
|
104
|
+
reference_files << new_path
|
105
|
+
else
|
106
|
+
path.delete
|
107
|
+
end
|
108
|
+
|
109
|
+
num_refs_to_keep = 3
|
110
|
+
if reference_files.length > num_refs_to_keep
|
111
|
+
(reference_files - reference_files[-num_refs_to_keep..-1]).each{|f| f.delete}
|
112
|
+
end
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
54
119
|
# By default the full cache is built.
|
55
120
|
# It is possible to generate index resp. resources only with
|
56
121
|
# rake apipie:cache cache_part=index (resources resp.)
|
@@ -100,13 +165,14 @@ namespace :apipie do
|
|
100
165
|
# Attempt to use the Rails application views, otherwise default to built in views
|
101
166
|
def renderer
|
102
167
|
return @apipie_renderer if @apipie_renderer
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
168
|
+
|
169
|
+
base_paths = [File.expand_path("../../../app/views/apipie/apipies", __FILE__)]
|
170
|
+
base_paths.unshift("#{Rails.root}/app/views/apipie/apipies") if File.directory?("#{Rails.root}/app/views/apipie/apipies")
|
171
|
+
|
172
|
+
layouts_paths = [File.expand_path("../../../app/views/layouts", __FILE__)]
|
173
|
+
layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie")
|
174
|
+
|
175
|
+
@apipie_renderer = ActionView::Base.new(base_paths + layouts_paths)
|
110
176
|
@apipie_renderer.singleton_class.send(:include, ApipieHelper)
|
111
177
|
return @apipie_renderer
|
112
178
|
end
|
@@ -123,6 +189,26 @@ namespace :apipie do
|
|
123
189
|
end
|
124
190
|
end
|
125
191
|
|
192
|
+
def generate_swagger_using_args(args, out)
|
193
|
+
args.with_defaults(:version => Apipie.configuration.default_version,
|
194
|
+
:swagger_content_type_input => Apipie.configuration.swagger_content_type_input || :form_data,
|
195
|
+
:filename_suffix => nil)
|
196
|
+
Apipie.configuration.swagger_content_type_input = args[:swagger_content_type_input].to_sym
|
197
|
+
count = 0
|
198
|
+
|
199
|
+
sfx = args[:filename_suffix] || "_#{args[:swagger_content_type_input]}"
|
200
|
+
|
201
|
+
paths = []
|
202
|
+
|
203
|
+
([nil] + Apipie.configuration.languages).each do |lang|
|
204
|
+
doc = Apipie.to_swagger_json(args[:version], nil, nil, lang, count==0)
|
205
|
+
paths << generate_swagger_json_page(out, doc, sfx, lang)
|
206
|
+
count+=1
|
207
|
+
end
|
208
|
+
|
209
|
+
paths
|
210
|
+
end
|
211
|
+
|
126
212
|
def generate_json_page(file_base, doc, lang = nil)
|
127
213
|
FileUtils.mkdir_p(file_base) unless File.exists?(file_base)
|
128
214
|
|
@@ -130,6 +216,15 @@ namespace :apipie do
|
|
130
216
|
File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
|
131
217
|
end
|
132
218
|
|
219
|
+
def generate_swagger_json_page(file_base, doc, sfx="", lang = nil)
|
220
|
+
FileUtils.mkdir_p(file_base) unless File.exists?(file_base)
|
221
|
+
|
222
|
+
path = Pathname.new("#{file_base}/schema_swagger#{sfx}#{lang_ext(lang)}.json")
|
223
|
+
File.open(path, 'w') { |file| file.write(JSON.pretty_generate(doc)) }
|
224
|
+
|
225
|
+
path
|
226
|
+
end
|
227
|
+
|
133
228
|
def generate_one_page(file_base, doc, lang = nil)
|
134
229
|
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
|
135
230
|
|
@@ -224,7 +319,7 @@ MESSAGE
|
|
224
319
|
apis_from_routes.each do |(controller, action), apis|
|
225
320
|
next if ignored.include?(controller)
|
226
321
|
next if ignored.include?("#{controller}##{action}")
|
227
|
-
Apipie::Extractor::Writer.update_action_description(controller.
|
322
|
+
Apipie::Extractor::Writer.update_action_description((controller.safe_constantize || next), action) do |u|
|
228
323
|
u.update_apis(apis)
|
229
324
|
end
|
230
325
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'fileutils'
|
3
|
+
require "json-schema"
|
3
4
|
|
4
5
|
describe Apipie::ApipiesController do
|
5
6
|
|
@@ -12,37 +13,37 @@ describe Apipie::ApipiesController do
|
|
12
13
|
end
|
13
14
|
|
14
15
|
it "succeeds on version details" do
|
15
|
-
get :index, :version => "2.0"
|
16
|
+
get :index, :params => { :version => "2.0" }
|
16
17
|
|
17
18
|
assert_response :success
|
18
19
|
end
|
19
20
|
|
20
21
|
it "returns not_found on wrong version" do
|
21
|
-
get :index, :version => "wrong_version"
|
22
|
+
get :index, :params => { :version => "wrong_version" }
|
22
23
|
|
23
24
|
assert_response :not_found
|
24
25
|
end
|
25
26
|
|
26
27
|
it "succeeds on resource details" do
|
27
|
-
get :index, :version => "2.0", :resource => "architectures"
|
28
|
+
get :index, :params => { :version => "2.0", :resource => "architectures" }
|
28
29
|
|
29
30
|
assert_response :success
|
30
31
|
end
|
31
32
|
|
32
33
|
it "returns not_found on wrong resource" do
|
33
|
-
get :index, :version => "2.0", :resource => "wrong_resource"
|
34
|
+
get :index, :params => { :version => "2.0", :resource => "wrong_resource" }
|
34
35
|
|
35
36
|
assert_response :not_found
|
36
37
|
end
|
37
38
|
|
38
39
|
it "succeeds on method details" do
|
39
|
-
get :index, :version => "2.0", :resource => "architectures", :method => "index"
|
40
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index" }
|
40
41
|
|
41
42
|
assert_response :success
|
42
43
|
end
|
43
44
|
|
44
45
|
it "returns not_found on wrong method" do
|
45
|
-
get :index, :version => "2.0", :resource => "architectures", :method => "wrong_method"
|
46
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "wrong_method" }
|
46
47
|
|
47
48
|
assert_response :not_found
|
48
49
|
end
|
@@ -130,6 +131,38 @@ describe Apipie::ApipiesController do
|
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
134
|
+
describe "GET index as swagger" do
|
135
|
+
|
136
|
+
let(:swagger_schema) do
|
137
|
+
File.read(File.join(File.dirname(__FILE__),"../lib/swagger/openapi_2_0_schema.json"))
|
138
|
+
end
|
139
|
+
|
140
|
+
it "outputs swagger when format is json and type is swagger" do
|
141
|
+
get :index, :params => { :format => "json", :type => "swagger"}
|
142
|
+
|
143
|
+
assert_response :success
|
144
|
+
expect(response.body).to match(/"swagger":"2.0"/)
|
145
|
+
# puts response.body
|
146
|
+
|
147
|
+
expect(JSON::Validator.validate(swagger_schema, response.body)).to be_truthy
|
148
|
+
end
|
149
|
+
|
150
|
+
it "does not output swagger when format is not json even if type is swagger" do
|
151
|
+
get :index, :params => { :type => "swagger"}
|
152
|
+
|
153
|
+
assert_response :success
|
154
|
+
expect(response.body).not_to match(/"swagger":"2.0"/)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "does not output swagger when format is json even but type is not swagger" do
|
158
|
+
get :index, :params => { :format => "json"}
|
159
|
+
|
160
|
+
assert_response :success
|
161
|
+
expect(response.body).not_to match(/"swagger":"2.0"/)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
133
166
|
describe "authenticate user" do
|
134
167
|
it "authenticate user if an authentication method is setted" do
|
135
168
|
test = false
|
@@ -183,6 +216,11 @@ describe Apipie::ApipiesController do
|
|
183
216
|
expect(assigns(:doc)[:resources]["users"][:methods].size).to eq(users_methods - 1)
|
184
217
|
expect(assigns(:doc)[:resources]["twitter_example"][:methods].size).to eq(twitter_example_methods)
|
185
218
|
end
|
219
|
+
it "does not allow access to swagger when authorization is set" do
|
220
|
+
get :index, :params => { :format => "json", :type => "swagger"}
|
221
|
+
|
222
|
+
assert_response :forbidden
|
223
|
+
end
|
186
224
|
end
|
187
225
|
|
188
226
|
describe "documentation cache" do
|
@@ -215,19 +253,21 @@ describe Apipie::ApipiesController do
|
|
215
253
|
it "uses the file in cache dir instead of generating the content on runtime" do
|
216
254
|
get :index
|
217
255
|
expect(response.body).to eq("apidoc.html cache v1")
|
218
|
-
get :index, :version => 'v1'
|
256
|
+
get :index, :params => { :version => 'v1' }
|
219
257
|
expect(response.body).to eq("apidoc.html cache v1")
|
220
|
-
get :index, :version => 'v2'
|
258
|
+
get :index, :params => { :version => 'v2' }
|
221
259
|
expect(response.body).to eq("apidoc.html cache v2")
|
222
|
-
get :index, :version => 'v1', :format => "html"
|
260
|
+
get :index, :params => { :version => 'v1', :format => "html" }
|
223
261
|
expect(response.body).to eq("apidoc.html cache v1")
|
224
|
-
get :index, :version => 'v1', :format => "json"
|
262
|
+
get :index, :params => { :version => 'v1', :format => "json" }
|
225
263
|
expect(response.body).to eq("apidoc.json cache")
|
226
|
-
get :index, :version => 'v1', :format => "html", :resource => "resource"
|
264
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource" }
|
227
265
|
expect(response.body).to eq("resource.html cache")
|
228
|
-
get :index, :version => 'v1', :format => "html", :resource => "resource", :method => "method"
|
266
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource", :method => "method" }
|
229
267
|
expect(response.body).to eq("method.html cache")
|
230
268
|
end
|
231
269
|
|
232
270
|
end
|
271
|
+
|
272
|
+
|
233
273
|
end
|
@@ -8,12 +8,12 @@ describe ConcernsController do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should reply to valid request" do
|
11
|
-
get :show, :id => '5', :session => "secret_hash"
|
11
|
+
get :show, :params => { :id => '5' }, :session => { :user_id => "secret_hash" }
|
12
12
|
assert_response :success
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should pass if required parameter is missing" do
|
16
|
-
expect { get :show, :id => '5' }.not_to raise_error
|
16
|
+
expect { get :show, :params => { :id => '5' } }.not_to raise_error
|
17
17
|
end
|
18
18
|
|
19
19
|
it "peserved the order of methods being defined in file" do
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ExtendedController do
|
4
|
+
|
5
|
+
it 'should include params from both original controller and extending concern' do
|
6
|
+
expect(Apipie["extended#create"].params.keys).to eq [:oauth, :user, :admin]
|
7
|
+
user_param = Apipie["extended#create"].params[:user]
|
8
|
+
expect(user_param.validator.params_ordered.map(&:name)).to eq [:name, :password, :from_concern]
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should include updated metadata' do
|
12
|
+
expect(Apipie['extended#create'].metadata).to eq metadata: 'data'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TestEngine::MemesController do
|
4
|
+
|
5
|
+
describe "#index" do
|
6
|
+
it "should have the full mounted path of engine" do
|
7
|
+
Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path].should eq("/test/memes")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|