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.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +67 -0
  3. data/.github/workflows/rubocop-challenger.yml +28 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +37 -0
  6. data/.rubocop_todo.yml +1991 -0
  7. data/CHANGELOG.md +246 -2
  8. data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
  9. data/README.rst +646 -25
  10. data/Rakefile +0 -5
  11. data/apipie-rails.gemspec +14 -9
  12. data/app/controllers/apipie/apipies_controller.rb +51 -20
  13. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
  14. data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
  15. data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
  16. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
  17. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
  18. data/app/views/apipie/apipies/_method_detail.erb +21 -0
  19. data/app/views/apipie/apipies/_params.html.erb +4 -2
  20. data/app/views/apipie/apipies/index.html.erb +5 -1
  21. data/app/views/apipie/apipies/resource.html.erb +3 -0
  22. data/app/views/layouts/apipie/apipie.html.erb +1 -1
  23. data/config/locales/en.yml +1 -0
  24. data/config/locales/fr.yml +31 -0
  25. data/config/locales/it.yml +31 -0
  26. data/config/locales/ja.yml +31 -0
  27. data/config/locales/ko.yml +31 -0
  28. data/config/locales/pt-BR.yml +1 -1
  29. data/gemfiles/Gemfile.rails50 +10 -0
  30. data/gemfiles/Gemfile.rails51 +10 -0
  31. data/gemfiles/Gemfile.rails52 +10 -0
  32. data/gemfiles/Gemfile.rails60 +17 -0
  33. data/gemfiles/Gemfile.rails61 +17 -0
  34. data/gemfiles/Gemfile.rails70 +17 -0
  35. data/lib/apipie/apipie_module.rb +22 -4
  36. data/lib/apipie/application.rb +54 -25
  37. data/lib/apipie/configuration.rb +26 -4
  38. data/lib/apipie/core_ext/route.rb +9 -0
  39. data/lib/apipie/dsl_definition.rb +168 -16
  40. data/lib/apipie/error_description.rb +9 -2
  41. data/lib/apipie/errors.rb +34 -0
  42. data/lib/apipie/extractor/collector.rb +4 -0
  43. data/lib/apipie/extractor/recorder.rb +14 -12
  44. data/lib/apipie/extractor/writer.rb +86 -58
  45. data/lib/apipie/extractor.rb +5 -5
  46. data/lib/apipie/generator/generator.rb +2 -0
  47. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  48. data/lib/apipie/generator/swagger/type.rb +16 -0
  49. data/lib/apipie/generator/swagger/type_extractor.rb +70 -0
  50. data/lib/apipie/generator/swagger/warning.rb +77 -0
  51. data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
  52. data/lib/apipie/markup.rb +14 -11
  53. data/lib/apipie/method_description/api.rb +12 -0
  54. data/lib/apipie/method_description/apis_service.rb +82 -0
  55. data/lib/apipie/method_description.rb +51 -49
  56. data/lib/apipie/param_description.rb +63 -5
  57. data/lib/apipie/resource_description.rb +11 -4
  58. data/lib/apipie/response_description.rb +131 -0
  59. data/lib/apipie/response_description_adapter.rb +200 -0
  60. data/lib/apipie/routes_formatter.rb +1 -1
  61. data/lib/apipie/rspec/response_validation_helper.rb +194 -0
  62. data/lib/apipie/static_dispatcher.rb +5 -2
  63. data/lib/apipie/swagger_generator.rb +717 -0
  64. data/lib/apipie/tag_list_description.rb +11 -0
  65. data/lib/apipie/validator.rb +83 -9
  66. data/lib/apipie/version.rb +1 -1
  67. data/lib/apipie-rails.rb +15 -4
  68. data/lib/generators/apipie/install/install_generator.rb +1 -1
  69. data/lib/generators/apipie/views_generator.rb +1 -1
  70. data/lib/tasks/apipie.rake +115 -15
  71. data/rel-eng/gem_release.ipynb +398 -0
  72. data/spec/controllers/apipies_controller_spec.rb +79 -14
  73. data/spec/controllers/concerns_controller_spec.rb +2 -2
  74. data/spec/controllers/extended_controller_spec.rb +14 -0
  75. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  76. data/spec/controllers/memes_controller_spec.rb +10 -0
  77. data/spec/controllers/users_controller_spec.rb +139 -76
  78. data/spec/dummy/Rakefile +1 -1
  79. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  80. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  81. data/spec/dummy/app/controllers/extended_controller.rb +14 -0
  82. data/spec/dummy/app/controllers/extending_concern.rb +10 -0
  83. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  84. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  85. data/spec/dummy/app/controllers/pets_controller.rb +408 -0
  86. data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
  87. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
  88. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +5 -7
  89. data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
  90. data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
  91. data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
  92. data/spec/dummy/app/controllers/users_controller.rb +26 -12
  93. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  94. data/spec/dummy/components/test_engine/Gemfile +6 -0
  95. data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
  96. data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
  97. data/spec/dummy/components/test_engine/config/routes.rb +3 -0
  98. data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
  99. data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
  100. data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
  101. data/spec/dummy/config/application.rb +6 -4
  102. data/spec/dummy/config/boot.rb +2 -2
  103. data/spec/dummy/config/environment.rb +1 -1
  104. data/spec/dummy/config/environments/development.rb +3 -3
  105. data/spec/dummy/config/environments/production.rb +3 -3
  106. data/spec/dummy/config/environments/test.rb +3 -5
  107. data/spec/dummy/config/initializers/apipie.rb +5 -3
  108. data/spec/dummy/config/routes.rb +25 -1
  109. data/spec/dummy/config.ru +1 -1
  110. data/spec/dummy/script/rails +2 -2
  111. data/spec/lib/application_spec.rb +1 -1
  112. data/spec/lib/extractor/writer_spec.rb +37 -7
  113. data/spec/lib/file_handler_spec.rb +25 -0
  114. data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
  115. data/spec/lib/generator/swagger/warning_spec.rb +51 -0
  116. data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
  117. data/spec/lib/method_description/apis_service_spec.rb +60 -0
  118. data/spec/lib/method_description_spec.rb +34 -0
  119. data/spec/lib/param_description_spec.rb +90 -4
  120. data/spec/lib/rake_spec.rb +2 -4
  121. data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
  122. data/spec/lib/swagger/rake_swagger_spec.rb +154 -0
  123. data/spec/lib/swagger/response_validation_spec.rb +104 -0
  124. data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
  125. data/spec/lib/validator_spec.rb +59 -1
  126. data/spec/lib/validators/array_validator_spec.rb +28 -8
  127. data/spec/spec_helper.rb +49 -3
  128. data/spec/support/custom_bool_validator.rb +17 -0
  129. metadata +104 -99
  130. data/.travis.yml +0 -12
  131. data/Gemfile +0 -7
  132. data/Gemfile.rails32 +0 -6
  133. data/Gemfile.rails40 +0 -5
  134. data/Gemfile.rails41 +0 -5
  135. data/Gemfile.rails42 +0 -5
  136. data/lib/apipie/client/generator.rb +0 -135
@@ -0,0 +1,11 @@
1
+ module Apipie
2
+
3
+ class TagListDescription
4
+
5
+ attr_reader :tags
6
+
7
+ def initialize(tags); @tags = tags; end
8
+
9
+ end
10
+
11
+ end
@@ -3,7 +3,7 @@ module Apipie
3
3
 
4
4
  module Validator
5
5
 
6
- # to create new validator, inherit from Apipie::Validator::Base
6
+ # to create new validator, inherit from Apipie::Validator::BaseValidator
7
7
  # and implement class method build and instance method validate
8
8
  class BaseValidator
9
9
 
@@ -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
@@ -66,14 +80,27 @@ module Apipie
66
80
  'string'
67
81
  end
68
82
 
83
+ def ignore_allow_blank?
84
+ false
85
+ end
86
+
69
87
  def merge_with(other_validator)
70
- raise NotImplementedError, "Dont know how to merge #{self.inspect} with #{other_validator.inspect}"
88
+ return self if self == other_validator
89
+ raise NotImplementedError, "Don't know how to merge #{self.inspect} with #{other_validator.inspect}"
71
90
  end
72
91
 
73
92
  def params_ordered
74
93
  nil
75
94
  end
76
95
 
96
+ def ==(other)
97
+ return false unless self.class == other.class
98
+ if param_description == other.param_description
99
+ true
100
+ else
101
+ false
102
+ end
103
+ end
77
104
  end
78
105
 
79
106
  # validate arguments type
@@ -96,7 +123,7 @@ module Apipie
96
123
  end
97
124
 
98
125
  def description
99
- "Must be #{@type}"
126
+ "Must be a #{@type}"
100
127
  end
101
128
 
102
129
  def expected_type
@@ -106,6 +133,8 @@ module Apipie
106
133
  'array'
107
134
  elsif @type.ancestors.include? Numeric
108
135
  'numeric'
136
+ elsif @type.ancestors.include? File
137
+ 'file'
109
138
  else
110
139
  'string'
111
140
  end
@@ -129,7 +158,7 @@ module Apipie
129
158
  end
130
159
 
131
160
  def description
132
- "Must match regular expression <code>/#{@regexp.source}/</code>."
161
+ "Must match regular expression #{format_description_value("/#{@regexp.source}/")}."
133
162
  end
134
163
  end
135
164
 
@@ -148,8 +177,12 @@ module Apipie
148
177
  self.new(param_description, argument) if argument.is_a?(Array)
149
178
  end
150
179
 
180
+ def values
181
+ @array
182
+ end
183
+
151
184
  def description
152
- string = @array.map { |value| "<code>#{value}</code>" }.join(', ')
185
+ string = @array.map { |value| format_description_value(value) }.join(', ')
153
186
  "Must be one of: #{string}."
154
187
  end
155
188
  end
@@ -202,7 +235,13 @@ module Apipie
202
235
 
203
236
  def has_valid_type?(value)
204
237
  if @items_type
205
- value.kind_of?(@items_type)
238
+ item_validator = BaseValidator.find('', @items_type, nil, nil)
239
+
240
+ if item_validator
241
+ item_validator.valid?(value)
242
+ else
243
+ value.kind_of?(@items_type)
244
+ end
206
245
  else
207
246
  true
208
247
  end
@@ -243,7 +282,8 @@ module Apipie
243
282
  end
244
283
 
245
284
  def description
246
- "Must be one of: #{@array.join(', ')}."
285
+ string = @array.map { |value| format_description_value(value) }.join(', ')
286
+ "Must be one of: #{string}."
247
287
  end
248
288
  end
249
289
 
@@ -297,6 +337,7 @@ module Apipie
297
337
  @params_ordered ||= _apipie_dsl_data[:params].map do |args|
298
338
  options = args.find { |arg| arg.is_a? Hash }
299
339
  options[:parent] = self.param_description
340
+ options[:param_group] = @param_group
300
341
  Apipie::ParamDescription.from_dsl_data(param_description.method_description, args)
301
342
  end
302
343
  end
@@ -375,6 +416,31 @@ module Apipie
375
416
  end
376
417
  end
377
418
 
419
+ class DecimalValidator < BaseValidator
420
+
421
+ def validate(value)
422
+ self.class.validate(value)
423
+ end
424
+
425
+ def self.build(param_description, argument, options, block)
426
+ if argument == :decimal
427
+ self.new(param_description)
428
+ end
429
+ end
430
+
431
+ def description
432
+ "Must be a decimal number."
433
+ end
434
+
435
+ def expected_type
436
+ 'numeric'
437
+ end
438
+
439
+ def self.validate(value)
440
+ value.to_s =~ /\A^[-+]?[0-9]+([,.][0-9]+)?\Z$/
441
+ end
442
+ end
443
+
378
444
  class NumberValidator < BaseValidator
379
445
 
380
446
  def validate(value)
@@ -391,6 +457,10 @@ module Apipie
391
457
  "Must be a number."
392
458
  end
393
459
 
460
+ def expected_type
461
+ 'numeric'
462
+ end
463
+
394
464
  def self.validate(value)
395
465
  value.to_s =~ /\A(0|[1-9]\d*)\Z$/
396
466
  end
@@ -413,7 +483,12 @@ module Apipie
413
483
  end
414
484
 
415
485
  def description
416
- "Must be 'true' or 'false' or '1' or '0'"
486
+ string = %w(true false 1 0).map { |value| format_description_value(value) }.join(', ')
487
+ "Must be one of: #{string}."
488
+ end
489
+
490
+ def ignore_allow_blank?
491
+ true
417
492
  end
418
493
  end
419
494
 
@@ -464,4 +539,3 @@ module Apipie
464
539
 
465
540
  end
466
541
  end
467
-
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.3.6'
2
+ VERSION = "0.9.1"
3
3
  end
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'
6
+
4
7
  require "apipie/routing"
5
8
  require "apipie/markup"
6
9
  require "apipie/apipie_module"
@@ -9,14 +12,22 @@ require "apipie/configuration"
9
12
  require "apipie/method_description"
10
13
  require "apipie/resource_description"
11
14
  require "apipie/param_description"
15
+ require "apipie/method_description/api"
16
+ require "apipie/method_description/apis_service"
12
17
  require "apipie/errors"
13
18
  require "apipie/error_description"
19
+ require "apipie/response_description"
20
+ require "apipie/response_description_adapter"
14
21
  require "apipie/see_description"
22
+ require "apipie/tag_list_description"
15
23
  require "apipie/validator"
16
24
  require "apipie/railtie"
17
25
  require 'apipie/extractor'
18
26
  require "apipie/version"
19
-
20
- if Rails.version.start_with?("3.0")
21
- warn 'Warning: apipie-rails is not going to support Rails 3.0 anymore in future versions'
22
- end
27
+ require "apipie/swagger_generator"
28
+ require "apipie/generator/generator"
29
+ require "apipie/generator/swagger/swagger"
30
+ require "apipie/generator/swagger/warning"
31
+ require "apipie/generator/swagger/warning_writer"
32
+ require "apipie/generator/swagger/type"
33
+ require "apipie/generator/swagger/type_extractor"
@@ -1,6 +1,6 @@
1
1
  module Apipie
2
2
  class InstallGenerator < ::Rails::Generators::Base
3
- source_root File.expand_path("../templates", __FILE__)
3
+ source_root File.expand_path('templates', __dir__)
4
4
 
5
5
  class_option(:route,
6
6
  :aliases => "-r",
@@ -1,6 +1,6 @@
1
1
  module Apipie
2
2
  class ViewsGenerator < ::Rails::Generators::Base
3
- source_root File.expand_path("../../../../app/views", __FILE__)
3
+ source_root File.expand_path('../../../app/views', __dir__)
4
4
  desc 'Copy Apipie views to your application'
5
5
 
6
6
  def copy_views
@@ -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!(&: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(&: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,19 @@ 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
- base_path = if File.directory?("#{Rails.root}/app/views/apipie/apipies")
104
- "#{Rails.root}/app/views/apipie/apipies"
105
- else
106
- File.expand_path("../../../app/views/apipie/apipies", __FILE__)
107
- end
108
- layouts_path = File.expand_path("../../../app/views/layouts", __FILE__)
109
- @apipie_renderer = ActionView::Base.new([base_path, layouts_path])
168
+
169
+ base_paths = [File.expand_path('../../app/views/apipie/apipies', __dir__)]
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', __dir__)]
173
+ layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie")
174
+
175
+ if ActionView::Base.respond_to?(:with_empty_template_cache) && ActionView::Base.respond_to?(:with_view_paths)
176
+ @apipie_renderer = ActionView::Base.with_empty_template_cache.with_view_paths(base_paths + layouts_paths)
177
+ else
178
+ @apipie_renderer = ActionView::Base.new(base_paths + layouts_paths)
179
+ end
180
+
110
181
  @apipie_renderer.singleton_class.send(:include, ApipieHelper)
111
182
  return @apipie_renderer
112
183
  end
@@ -123,29 +194,58 @@ namespace :apipie do
123
194
  end
124
195
  end
125
196
 
197
+ def generate_swagger_using_args(args, out)
198
+ args.with_defaults(:version => Apipie.configuration.default_version,
199
+ :swagger_content_type_input => Apipie.configuration.swagger_content_type_input || :form_data,
200
+ :filename_suffix => nil)
201
+ Apipie.configuration.swagger_content_type_input = args[:swagger_content_type_input].to_sym
202
+ count = 0
203
+
204
+ sfx = args[:filename_suffix] || "_#{args[:swagger_content_type_input]}"
205
+
206
+ paths = []
207
+
208
+ ([nil] + Apipie.configuration.languages).each do |lang|
209
+ doc = Apipie.to_swagger_json(args[:version], nil, nil, lang, count==0)
210
+ paths << generate_swagger_json_page(out, doc, sfx, lang)
211
+ count+=1
212
+ end
213
+
214
+ paths
215
+ end
216
+
126
217
  def generate_json_page(file_base, doc, lang = nil)
127
- FileUtils.mkdir_p(file_base) unless File.exists?(file_base)
218
+ FileUtils.mkdir_p(file_base) unless File.exist?(file_base)
128
219
 
129
220
  filename = "schema_apipie#{lang_ext(lang)}.json"
130
221
  File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
131
222
  end
132
223
 
224
+ def generate_swagger_json_page(file_base, doc, sfx="", lang = nil)
225
+ FileUtils.mkdir_p(file_base) unless File.exist?(file_base)
226
+
227
+ path = Pathname.new("#{file_base}/schema_swagger#{sfx}#{lang_ext(lang)}.json")
228
+ File.open(path, 'w') { |file| file.write(JSON.pretty_generate(doc)) }
229
+
230
+ path
231
+ end
232
+
133
233
  def generate_one_page(file_base, doc, lang = nil)
134
- FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
234
+ FileUtils.mkdir_p(File.dirname(file_base)) unless File.exist?(File.dirname(file_base))
135
235
 
136
236
  render_page("#{file_base}-onepage#{lang_ext(lang)}.html", "static", {:doc => doc[:docs],
137
237
  :language => lang, :languages => Apipie.configuration.languages})
138
238
  end
139
239
 
140
240
  def generate_plain_page(file_base, doc, lang = nil)
141
- FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
241
+ FileUtils.mkdir_p(File.dirname(file_base)) unless File.exist?(File.dirname(file_base))
142
242
 
143
243
  render_page("#{file_base}-plain#{lang_ext(lang)}.html", "plain", {:doc => doc[:docs],
144
244
  :language => lang, :languages => Apipie.configuration.languages}, nil)
145
245
  end
146
246
 
147
247
  def generate_index_page(file_base, doc, include_json = false, show_versions = false, lang = nil)
148
- FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
248
+ FileUtils.mkdir_p(File.dirname(file_base)) unless File.exist?(File.dirname(file_base))
149
249
  versions = show_versions && Apipie.available_versions
150
250
  render_page("#{file_base}#{lang_ext(lang)}.html", "index", {:doc => doc[:docs],
151
251
  :versions => versions, :language => lang, :languages => Apipie.configuration.languages})
@@ -156,7 +256,7 @@ namespace :apipie do
156
256
  def generate_resource_pages(version, file_base, doc, include_json = false, lang = nil)
157
257
  doc[:docs][:resources].each do |resource_name, _|
158
258
  resource_file_base = File.join(file_base, resource_name.to_s)
159
- FileUtils.mkdir_p(File.dirname(resource_file_base)) unless File.exists?(File.dirname(resource_file_base))
259
+ FileUtils.mkdir_p(File.dirname(resource_file_base)) unless File.exist?(File.dirname(resource_file_base))
160
260
 
161
261
  doc = Apipie.to_json(version, resource_name, nil, lang)
162
262
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
@@ -170,7 +270,7 @@ namespace :apipie do
170
270
  doc[:docs][:resources].each do |resource_name, resource_params|
171
271
  resource_params[:methods].each do |method|
172
272
  method_file_base = File.join(file_base, resource_name.to_s, method[:name].to_s)
173
- FileUtils.mkdir_p(File.dirname(method_file_base)) unless File.exists?(File.dirname(method_file_base))
273
+ FileUtils.mkdir_p(File.dirname(method_file_base)) unless File.exist?(File.dirname(method_file_base))
174
274
 
175
275
  doc = Apipie.to_json(version, resource_name, method[:name], lang)
176
276
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
@@ -224,7 +324,7 @@ MESSAGE
224
324
  apis_from_routes.each do |(controller, action), apis|
225
325
  next if ignored.include?(controller)
226
326
  next if ignored.include?("#{controller}##{action}")
227
- Apipie::Extractor::Writer.update_action_description(controller.constantize, action) do |u|
327
+ Apipie::Extractor::Writer.update_action_description((controller.safe_constantize || next), action) do |u|
228
328
  u.update_apis(apis)
229
329
  end
230
330
  end
@@ -234,7 +334,7 @@ MESSAGE
234
334
  desc "Convert your examples from the old yaml into the new json format"
235
335
  task :convert_examples => :environment do
236
336
  yaml_examples_file = File.join(Rails.root, Apipie.configuration.doc_path, "apipie_examples.yml")
237
- if File.exists?(yaml_examples_file)
337
+ if File.exist?(yaml_examples_file)
238
338
  #if SafeYAML gem is enabled, it will load examples as an array of Hash, instead of hash
239
339
  if defined? SafeYAML
240
340
  examples = YAML.load_file(yaml_examples_file, :safe=>false)