apipie-rails 0.5.19 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +31 -0
  3. data/.github/workflows/rubocop-challenger.yml +28 -0
  4. data/.github/workflows/rubocop.yml +18 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +128 -0
  7. data/.rubocop_todo.yml +2056 -0
  8. data/.vscode/settings.json +3 -0
  9. data/CHANGELOG.md +161 -0
  10. data/Gemfile +20 -0
  11. data/README.rst +117 -23
  12. data/Rakefile +0 -5
  13. data/apipie-rails.gemspec +18 -9
  14. data/app/controllers/apipie/apipies_controller.rb +14 -29
  15. data/app/helpers/apipie_helper.rb +1 -1
  16. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
  17. data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
  18. data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
  19. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
  20. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
  21. data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
  22. data/app/views/apipie/apipies/_params.html.erb +7 -1
  23. data/config/locales/en.yml +8 -0
  24. data/config/locales/ko.yml +31 -0
  25. data/gemfiles/Gemfile.tools +9 -0
  26. data/lib/apipie/apipie_module.rb +7 -7
  27. data/lib/apipie/application.rb +132 -97
  28. data/lib/apipie/configuration.rb +43 -33
  29. data/lib/apipie/dsl_definition.rb +44 -33
  30. data/lib/apipie/error_description.rb +3 -3
  31. data/lib/apipie/errors.rb +17 -17
  32. data/lib/apipie/extractor/collector.rb +5 -6
  33. data/lib/apipie/extractor/recorder.rb +35 -8
  34. data/lib/apipie/extractor/writer.rb +15 -15
  35. data/lib/apipie/extractor.rb +6 -9
  36. data/lib/apipie/generator/config.rb +12 -0
  37. data/lib/apipie/generator/generator.rb +2 -0
  38. data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
  39. data/lib/apipie/generator/swagger/config.rb +80 -0
  40. data/lib/apipie/generator/swagger/context.rb +38 -0
  41. data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
  42. data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
  43. data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
  44. data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
  45. data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
  46. data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
  47. data/lib/apipie/generator/swagger/method_description.rb +2 -0
  48. data/lib/apipie/generator/swagger/operation_id.rb +51 -0
  49. data/lib/apipie/generator/swagger/param_description/builder.rb +114 -0
  50. data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
  51. data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
  52. data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
  53. data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
  54. data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
  55. data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
  56. data/lib/apipie/generator/swagger/param_description/type.rb +128 -0
  57. data/lib/apipie/generator/swagger/param_description.rb +18 -0
  58. data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
  59. data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
  60. data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
  61. data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
  62. data/lib/apipie/generator/swagger/schema.rb +63 -0
  63. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  64. data/lib/apipie/generator/swagger/type.rb +16 -0
  65. data/lib/apipie/generator/swagger/type_extractor.rb +51 -0
  66. data/lib/apipie/generator/swagger/warning.rb +74 -0
  67. data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
  68. data/lib/apipie/helpers.rb +3 -3
  69. data/lib/apipie/markup.rb +9 -8
  70. data/lib/apipie/method_description/api.rb +12 -0
  71. data/lib/apipie/method_description/apis_service.rb +82 -0
  72. data/lib/apipie/method_description.rb +12 -56
  73. data/lib/apipie/param_description/deprecation.rb +24 -0
  74. data/lib/apipie/param_description.rb +57 -24
  75. data/lib/apipie/resource_description.rb +42 -14
  76. data/lib/apipie/response_description.rb +3 -3
  77. data/lib/apipie/response_description_adapter.rb +12 -10
  78. data/lib/apipie/routing.rb +1 -1
  79. data/lib/apipie/rspec/response_validation_helper.rb +3 -3
  80. data/lib/apipie/static_dispatcher.rb +10 -2
  81. data/lib/apipie/swagger_generator.rb +28 -691
  82. data/lib/apipie/validator.rb +41 -11
  83. data/lib/apipie/version.rb +1 -1
  84. data/lib/apipie-rails.rb +36 -5
  85. data/lib/generators/apipie/install/install_generator.rb +1 -1
  86. data/lib/generators/apipie/views_generator.rb +1 -1
  87. data/lib/tasks/apipie.rake +37 -32
  88. data/rel-eng/gem_release.ipynb +41 -9
  89. data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
  90. data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
  91. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
  92. data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
  93. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  94. data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
  95. data/spec/controllers/users_controller_spec.rb +47 -6
  96. data/spec/dummy/Rakefile +1 -1
  97. data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
  98. data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
  99. data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
  100. data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
  101. data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
  102. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  103. data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
  104. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  105. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  106. data/spec/dummy/app/controllers/pets_controller.rb +5 -5
  107. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  108. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
  109. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  110. data/spec/dummy/app/controllers/users_controller.rb +17 -5
  111. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  112. data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
  113. data/spec/dummy/config/application.rb +2 -5
  114. data/spec/dummy/config/boot.rb +2 -2
  115. data/spec/dummy/config/environment.rb +1 -1
  116. data/spec/dummy/config/environments/development.rb +0 -3
  117. data/spec/dummy/config/environments/production.rb +0 -3
  118. data/spec/dummy/config/environments/test.rb +0 -5
  119. data/spec/dummy/config/initializers/apipie.rb +2 -2
  120. data/spec/dummy/config/routes.rb +8 -0
  121. data/spec/dummy/config.ru +1 -1
  122. data/spec/dummy/script/rails +2 -2
  123. data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
  124. data/spec/lib/apipie/application_spec.rb +62 -0
  125. data/spec/lib/apipie/configuration_spec.rb +38 -0
  126. data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
  127. data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
  128. data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
  129. data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
  130. data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
  131. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  132. data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
  133. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
  134. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  135. data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
  136. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -0
  137. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
  138. data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
  139. data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
  140. data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
  141. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +183 -0
  142. data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
  143. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  144. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  145. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  146. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  147. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  148. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
  149. data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
  150. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
  151. data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
  152. data/spec/lib/apipie/method_description_spec.rb +133 -0
  153. data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
  154. data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
  155. data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
  156. data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
  157. data/spec/lib/apipie/resource_description_spec.rb +91 -0
  158. data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
  159. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  160. data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
  161. data/spec/lib/rake_spec.rb +3 -5
  162. data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
  163. data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
  164. data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
  165. data/spec/lib/validators/array_validator_spec.rb +1 -1
  166. data/spec/spec_helper.rb +10 -32
  167. data/spec/support/custom_bool_validator.rb +17 -0
  168. data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
  169. metadata +173 -125
  170. data/.travis.yml +0 -41
  171. data/Gemfile +0 -1
  172. data/Gemfile.rails41 +0 -7
  173. data/Gemfile.rails42 +0 -14
  174. data/Gemfile.rails50 +0 -9
  175. data/Gemfile.rails51 +0 -9
  176. data/Gemfile.rails60 +0 -10
  177. data/Gemfile.rails61 +0 -10
  178. data/spec/lib/application_spec.rb +0 -49
  179. data/spec/lib/method_description_spec.rb +0 -98
  180. data/spec/lib/resource_description_spec.rb +0 -48
  181. /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
@@ -1,9 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  module Apipie
3
4
 
4
5
  module Validator
5
6
 
6
- # to create new validator, inherit from Apipie::Validator::Base
7
+ # to create new validator, inherit from Apipie::Validator::BaseValidator
7
8
  # and implement class method build and instance method validate
8
9
  class BaseValidator
9
10
 
@@ -37,6 +38,16 @@ module Apipie
37
38
  return nil
38
39
  end
39
40
 
41
+ def self.raise_if_missing_params
42
+ missing_params = []
43
+ yield missing_params
44
+ if missing_params.size > 1
45
+ raise ParamMultipleMissing.new(missing_params)
46
+ elsif missing_params.size == 1
47
+ raise ParamMissing.new(missing_params.first)
48
+ end
49
+ end
50
+
40
51
  # check if value is valid
41
52
  def valid?(value)
42
53
  if self.validate(value)
@@ -80,6 +91,10 @@ module Apipie
80
91
  'string'
81
92
  end
82
93
 
94
+ def ignore_allow_blank?
95
+ false
96
+ end
97
+
83
98
  def merge_with(other_validator)
84
99
  return self if self == other_validator
85
100
  raise NotImplementedError, "Don't know how to merge #{self.inspect} with #{other_validator.inspect}"
@@ -185,7 +200,7 @@ module Apipie
185
200
 
186
201
  # arguments value must be an array
187
202
  class ArrayValidator < Apipie::Validator::BaseValidator
188
- def initialize(param_description, argument, options={})
203
+ def initialize(param_description, argument, options = {})
189
204
  super(param_description)
190
205
  @type = argument
191
206
  @items_type = options[:of]
@@ -333,29 +348,32 @@ module Apipie
333
348
  @params_ordered ||= _apipie_dsl_data[:params].map do |args|
334
349
  options = args.find { |arg| arg.is_a? Hash }
335
350
  options[:parent] = self.param_description
351
+ options[:param_group] = @param_group
336
352
  Apipie::ParamDescription.from_dsl_data(param_description.method_description, args)
337
353
  end
338
354
  end
339
355
 
340
356
  def validate(value)
341
357
  return false if !value.is_a? Hash
342
- if @hash_params
343
- @hash_params.each do |k, p|
358
+
359
+ BaseValidator.raise_if_missing_params do |missing|
360
+ @hash_params&.each do |k, p|
344
361
  if Apipie.configuration.validate_presence?
345
- raise ParamMissing.new(p) if p.required && !value.has_key?(k)
362
+ missing << p if p.required && !value.key?(k)
346
363
  end
347
364
  if Apipie.configuration.validate_value?
348
- p.validate(value[k]) if value.has_key?(k)
365
+ p.validate(value[k]) if value.key?(k)
349
366
  end
350
367
  end
351
368
  end
369
+
352
370
  return true
353
371
  end
354
372
 
355
373
  def process_value(value)
356
374
  if @hash_params && value
357
375
  return @hash_params.each_with_object({}) do |(key, param), api_params|
358
- if value.has_key?(key)
376
+ if value.key?(key)
359
377
  api_params[param.as] = param.process_value(value[key])
360
378
  end
361
379
  end
@@ -427,6 +445,10 @@ module Apipie
427
445
  "Must be a decimal number."
428
446
  end
429
447
 
448
+ def expected_type
449
+ 'numeric'
450
+ end
451
+
430
452
  def self.validate(value)
431
453
  value.to_s =~ /\A^[-+]?[0-9]+([,.][0-9]+)?\Z$/
432
454
  end
@@ -464,26 +486,34 @@ module Apipie
464
486
  end
465
487
 
466
488
  def self.build(param_description, argument, options, block)
467
- if argument == :bool || argument == :boolean
489
+ if argument == :bool || argument == :boolean || boolean_array?(argument)
468
490
  self.new(param_description)
469
491
  end
470
492
  end
471
493
 
472
- def expected_type
473
- 'boolean'
494
+ private_class_method def self.boolean_array?(argument)
495
+ argument.is_a?(Array) && (argument - [true, false]) == []
474
496
  end
475
497
 
476
498
  def description
477
499
  string = %w(true false 1 0).map { |value| format_description_value(value) }.join(', ')
478
500
  "Must be one of: #{string}."
479
501
  end
502
+
503
+ def ignore_allow_blank?
504
+ true
505
+ end
506
+
507
+ def expected_type
508
+ 'boolean'
509
+ end
480
510
  end
481
511
 
482
512
  class NestedValidator < BaseValidator
483
513
 
484
514
  def initialize(param_description, argument, param_group)
485
515
  super(param_description)
486
- @validator = Apipie::Validator:: HashValidator.new(param_description, argument, param_group)
516
+ @validator = Apipie::Validator::HashValidator.new(param_description, argument, param_group)
487
517
  @type = argument
488
518
  end
489
519
 
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = "0.5.19"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/apipie-rails.rb CHANGED
@@ -2,16 +2,20 @@ require 'i18n'
2
2
  require 'json'
3
3
  require 'active_support/hash_with_indifferent_access'
4
4
 
5
- require 'apipie/core_ext/route.rb'
5
+ require 'apipie/core_ext/route'
6
6
 
7
7
  require "apipie/routing"
8
8
  require "apipie/markup"
9
9
  require "apipie/apipie_module"
10
10
  require "apipie/dsl_definition"
11
+ require "apipie/generator/swagger/config"
11
12
  require "apipie/configuration"
12
13
  require "apipie/method_description"
13
14
  require "apipie/resource_description"
14
15
  require "apipie/param_description"
16
+ require "apipie/param_description/deprecation"
17
+ require "apipie/method_description/api"
18
+ require "apipie/method_description/apis_service"
15
19
  require "apipie/errors"
16
20
  require "apipie/error_description"
17
21
  require "apipie/response_description"
@@ -23,7 +27,34 @@ require "apipie/railtie"
23
27
  require 'apipie/extractor'
24
28
  require "apipie/version"
25
29
  require "apipie/swagger_generator"
26
-
27
- if Rails.version.start_with?("3.0")
28
- warn 'Warning: apipie-rails is not going to support Rails 3.0 anymore in future versions'
29
- end
30
+ require "apipie/generator/generator"
31
+ require "apipie/generator/config"
32
+ require "apipie/generator/swagger/swagger"
33
+ require "apipie/generator/swagger/schema"
34
+ require "apipie/generator/swagger/operation_id"
35
+ require "apipie/generator/swagger/warning"
36
+ require "apipie/generator/swagger/warning_writer"
37
+ require "apipie/generator/swagger/type"
38
+ require "apipie/generator/swagger/type_extractor"
39
+ require "apipie/generator/swagger/context"
40
+ require "apipie/generator/swagger/computed_interface_id"
41
+ require "apipie/generator/swagger/path_decorator"
42
+ require "apipie/generator/swagger/referenced_definitions"
43
+ require "apipie/generator/swagger/resource_description_composite"
44
+ require "apipie/generator/swagger/resource_description_collection"
45
+ require "apipie/generator/swagger/method_description"
46
+ require "apipie/generator/swagger/method_description/parameters_service"
47
+ require "apipie/generator/swagger/method_description/response_service"
48
+ require "apipie/generator/swagger/method_description/response_schema_service"
49
+ require "apipie/generator/swagger/method_description/decorator"
50
+ require "apipie/generator/swagger/method_description/api_decorator"
51
+ require "apipie/generator/swagger/method_description/api_schema_service"
52
+ require "apipie/generator/swagger/param_description"
53
+ require "apipie/generator/swagger/param_description/builder"
54
+ require "apipie/generator/swagger/param_description/composite"
55
+ require "apipie/generator/swagger/param_description/description"
56
+ require "apipie/generator/swagger/param_description/in"
57
+ require "apipie/generator/swagger/param_description/name"
58
+ require "apipie/generator/swagger/param_description/path_params_composite"
59
+ require "apipie/generator/swagger/param_description/referenced_composite"
60
+ require "apipie/generator/swagger/param_description/type"
@@ -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
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require 'fileutils'
3
4
 
4
5
  namespace :apipie do
@@ -19,7 +20,7 @@ namespace :apipie do
19
20
  task :static, [:version] => :environment do |t, args|
20
21
  with_loaded_documentation do
21
22
  args.with_defaults(:version => Apipie.configuration.default_version)
22
- out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
23
+ out = ENV["OUT"] || File.join(Rails.root, Apipie.configuration.doc_path, 'apidoc')
23
24
  subdir = File.basename(out)
24
25
  copy_jscss(out)
25
26
  Apipie.configuration.version_in_url = false
@@ -43,7 +44,7 @@ namespace :apipie do
43
44
  task :static_json, [:version] => :environment do |t, args|
44
45
  with_loaded_documentation do
45
46
  args.with_defaults(:version => Apipie.configuration.default_version)
46
- out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
47
+ out = ENV["OUT"] || File.join(Rails.root, Apipie.configuration.doc_path, 'apidoc')
47
48
  ([nil] + Apipie.configuration.languages).each do |lang|
48
49
  doc = Apipie.to_json(args[:version], nil, nil, lang)
49
50
  generate_json_page(out, doc, lang)
@@ -54,7 +55,7 @@ namespace :apipie do
54
55
  desc "Generate static swagger json"
55
56
  task :static_swagger_json, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
56
57
  with_loaded_documentation do
57
- out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
58
+ out = ENV["OUT"] || File.join(Rails.root, Apipie.configuration.doc_path, 'apidoc')
58
59
  generate_swagger_using_args(args, out)
59
60
  end
60
61
  end
@@ -67,7 +68,7 @@ namespace :apipie do
67
68
  desc "Did swagger output change since the last execution of this task?"
68
69
  task :did_swagger_change, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
69
70
  with_loaded_documentation do
70
- out = ENV["OUT_REF"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc_ref')
71
+ out = ENV["OUT_REF"] || File.join(Rails.root, Apipie.configuration.doc_path, 'apidoc_ref')
71
72
  paths = generate_swagger_using_args(args, out)
72
73
  paths.each {|path|
73
74
  existing_files_in_dir = Pathname(out).children(true)
@@ -85,7 +86,7 @@ namespace :apipie do
85
86
  counter = 1
86
87
  make_reference = true
87
88
  else
88
- reference_files.sort_by! {|f| f.ctime }
89
+ reference_files.sort_by!(&:ctime)
89
90
  last_ref = reference_files[-1]
90
91
  print "Comparing [#{path}] to reference file: [#{last_ref.basename}]: "
91
92
  if !FileUtils.compare_file(path, last_ref)
@@ -108,7 +109,7 @@ namespace :apipie do
108
109
 
109
110
  num_refs_to_keep = 3
110
111
  if reference_files.length > num_refs_to_keep
111
- (reference_files - reference_files[-num_refs_to_keep..-1]).each{|f| f.delete}
112
+ (reference_files - reference_files[-num_refs_to_keep..-1]).each(&:delete)
112
113
  end
113
114
  }
114
115
  end
@@ -122,17 +123,17 @@ namespace :apipie do
122
123
  # Default output dir ('public/apipie_cache') can be changed with OUT=/some/dir
123
124
  desc "Generate cache to avoid production dependencies on markup languages"
124
125
  task :cache => :environment do
125
- puts "#{Time.now} | Started"
126
+ puts "#{Time.zone.now} | Started"
126
127
  cache_part = ENV['cache_part']
127
128
  generate_index = (cache_part == 'resources' ? false : true)
128
129
  generate_resources = (cache_part == 'index' ? false : true)
129
130
  with_loaded_documentation do
130
- puts "#{Time.now} | Documents loaded..."
131
+ puts "#{Time.zone.now} | Documents loaded..."
131
132
  ([nil] + Apipie.configuration.languages).each do |lang|
132
133
  I18n.locale = lang || Apipie.configuration.default_locale
133
- puts "#{Time.now} | Processing docs for #{lang}"
134
+ puts "#{Time.zone.now} | Processing docs for #{lang}"
134
135
  cache_dir = ENV["OUT"] || Apipie.configuration.cache_dir
135
- subdir = Apipie.configuration.doc_base_url.sub(/\A\//,"")
136
+ subdir = Apipie.configuration.doc_base_url.sub(%r{\A/},"")
136
137
  subdir_levels = subdir.split('/').length
137
138
  subdir_traversal_prefix = '../' * subdir_levels
138
139
  file_base = File.join(cache_dir, Apipie.configuration.doc_base_url)
@@ -150,26 +151,25 @@ namespace :apipie do
150
151
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
151
152
 
152
153
  generate_index_page(file_base_version, doc, true, true, lang) if generate_index
153
- if generate_resources
154
- Apipie.url_prefix = "../#{subdir_traversal_prefix}#{subdir}"
155
- generate_resource_pages(version, file_base_version, doc, true, lang)
156
- Apipie.url_prefix = "../../#{subdir_traversal_prefix}#{subdir}"
157
- generate_method_pages(version, file_base_version, doc, true, lang)
158
- end
154
+ next unless generate_resources
155
+ Apipie.url_prefix = "../#{subdir_traversal_prefix}#{subdir}"
156
+ generate_resource_pages(version, file_base_version, doc, true, lang)
157
+ Apipie.url_prefix = "../../#{subdir_traversal_prefix}#{subdir}"
158
+ generate_method_pages(version, file_base_version, doc, true, lang)
159
159
  end
160
160
  end
161
161
  end
162
- puts "#{Time.now} | Finished"
162
+ puts "#{Time.zone.now} | Finished"
163
163
  end
164
164
 
165
165
  # Attempt to use the Rails application views, otherwise default to built in views
166
166
  def renderer
167
167
  return @apipie_renderer if @apipie_renderer
168
168
 
169
- base_paths = [File.expand_path("../../../app/views/apipie/apipies", __FILE__)]
169
+ base_paths = [File.expand_path('../../app/views/apipie/apipies', __dir__)]
170
170
  base_paths.unshift("#{Rails.root}/app/views/apipie/apipies") if File.directory?("#{Rails.root}/app/views/apipie/apipies")
171
171
 
172
- layouts_paths = [File.expand_path("../../../app/views/layouts", __FILE__)]
172
+ layouts_paths = [File.expand_path('../../app/views/layouts', __dir__)]
173
173
  layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie")
174
174
 
175
175
  if ActionView::Base.respond_to?(:with_empty_template_cache) && ActionView::Base.respond_to?(:with_view_paths)
@@ -186,19 +186,24 @@ namespace :apipie do
186
186
  av = renderer
187
187
  File.open(file_name, "w") do |f|
188
188
  variables.each do |var, val|
189
- av.instance_variable_set("@#{var}", val)
189
+ av.instance_variable_set(:"@#{var}", val)
190
190
  end
191
191
  f.write av.render(
192
192
  :template => "#{template}",
193
- :layout => (layout && "apipie/#{layout}"))
193
+ :layout => layout && "apipie/#{layout}")
194
194
  end
195
195
  end
196
196
 
197
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
198
+ args.with_defaults(
199
+ version: Apipie.configuration.default_version,
200
+ swagger_content_type_input: Apipie.configuration.generator.swagger.content_type_input,
201
+ filename_suffix: nil
202
+ )
203
+
204
+ Apipie.configuration.generator.swagger.content_type_input =
205
+ args[:swagger_content_type_input].to_sym
206
+
202
207
  count = 0
203
208
 
204
209
  sfx = args[:filename_suffix] || "_#{args[:swagger_content_type_input]}"
@@ -221,7 +226,7 @@ namespace :apipie do
221
226
  File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
222
227
  end
223
228
 
224
- def generate_swagger_json_page(file_base, doc, sfx="", lang = nil)
229
+ def generate_swagger_json_page(file_base, doc, sfx = "", lang = nil)
225
230
  FileUtils.mkdir_p(file_base) unless File.exist?(file_base)
226
231
 
227
232
  path = Pathname.new("#{file_base}/schema_swagger#{sfx}#{lang_ext(lang)}.json")
@@ -254,11 +259,11 @@ namespace :apipie do
254
259
  end
255
260
 
256
261
  def generate_resource_pages(version, file_base, doc, include_json = false, lang = nil)
257
- doc[:docs][:resources].each do |resource_name, _|
258
- resource_file_base = File.join(file_base, resource_name.to_s)
262
+ doc[:docs][:resources].each_key do |resource_id|
263
+ resource_file_base = File.join(file_base, resource_id.to_s)
259
264
  FileUtils.mkdir_p(File.dirname(resource_file_base)) unless File.exist?(File.dirname(resource_file_base))
260
265
 
261
- doc = Apipie.to_json(version, resource_name, nil, lang)
266
+ doc = Apipie.to_json(version, resource_id, nil, lang)
262
267
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
263
268
  render_page("#{resource_file_base}#{lang_ext(lang)}.html", "resource", {:doc => doc[:docs],
264
269
  :resource => doc[:docs][:resources].first, :language => lang, :languages => Apipie.configuration.languages})
@@ -267,12 +272,12 @@ namespace :apipie do
267
272
  end
268
273
 
269
274
  def generate_method_pages(version, file_base, doc, include_json = false, lang = nil)
270
- doc[:docs][:resources].each do |resource_name, resource_params|
275
+ doc[:docs][:resources].each do |resource_id, resource_params|
271
276
  resource_params[:methods].each do |method|
272
- method_file_base = File.join(file_base, resource_name.to_s, method[:name].to_s)
277
+ method_file_base = File.join(file_base, resource_id.to_s, method[:name].to_s)
273
278
  FileUtils.mkdir_p(File.dirname(method_file_base)) unless File.exist?(File.dirname(method_file_base))
274
279
 
275
- doc = Apipie.to_json(version, resource_name, method[:name], lang)
280
+ doc = Apipie.to_json(version, resource_id, method[:name], lang)
276
281
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
277
282
  render_page("#{method_file_base}#{lang_ext(lang)}.html", "method", {:doc => doc[:docs],
278
283
  :resource => doc[:docs][:resources].first,
@@ -10,7 +10,8 @@
10
10
  "- push access to https://github.com/Apipie/apipie-rails\n",
11
11
  "- push access to rubygems.org for apipie-rails\n",
12
12
  "- sudo yum install python-slugify asciidoc\n",
13
- "- ensure neither the `git push` or `gem push` don't require interractive auth. If you can't use api key or ssh key to auth skip these steps and run them form the shell manually \n",
13
+ "- ensure neither the `git push` or `gem push` don't require interractive auth. If you can't use api key or ssh key to auth skip these steps and run them form the shell manually\n",
14
+ "- ensure all checks have passed on the branch you're about to release\n",
14
15
  "\n",
15
16
  "### Release process\n",
16
17
  "- Follow the steps with `<Shift>+<Enter>` or `<Ctrl>+<Enter>,<Down>`\n",
@@ -19,6 +20,15 @@
19
20
  "### Release settings"
20
21
  ]
21
22
  },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "%autosave 0"
30
+ ]
31
+ },
22
32
  {
23
33
  "cell_type": "code",
24
34
  "execution_count": null,
@@ -41,10 +51,14 @@
41
51
  "metadata": {},
42
52
  "outputs": [],
43
53
  "source": [
44
- "NEW_VERSION = '0.5.19'\n",
45
- "LAST_VERSION = '0.5.18'\n",
54
+ "NEW_VERSION = '0.5.20'\n",
55
+ "LAST_VERSION = '0.5.19'\n",
46
56
  "GIT_REMOTE_UPSTREAM = 'origin'\n",
47
- "WORK_BRANCH = 'master'\n"
57
+ "STABLE_RELEASE = False\n",
58
+ "WORK_BRANCH = 'stable' if STABLE_RELEASE else 'master'\n",
59
+ "# Array of strings, e.g. [\"21cbsc214g3\", \"21casc214g3\"]\n",
60
+ "CHERRY_PICKS = []\n",
61
+ "GEMFILE='Gemfile.rails61'"
48
62
  ]
49
63
  },
50
64
  {
@@ -85,7 +99,25 @@
85
99
  "cell_type": "markdown",
86
100
  "metadata": {},
87
101
  "source": [
88
- "### Run tests localy"
102
+ "### Cherry picks for stable release"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": null,
108
+ "metadata": {},
109
+ "outputs": [],
110
+ "source": [
111
+ "if STABLE_RELEASE:\n",
112
+ " for cp in CHERRY_PICKS:\n",
113
+ " ! git cherry-pick -x {cp}"
114
+ ]
115
+ },
116
+ {
117
+ "cell_type": "markdown",
118
+ "metadata": {},
119
+ "source": [
120
+ "### Run tests localy if your setup allows, otherwise ensure the HEAD is green"
89
121
  ]
90
122
  },
91
123
  {
@@ -94,7 +126,7 @@
94
126
  "metadata": {},
95
127
  "outputs": [],
96
128
  "source": [
97
- "! bundle update"
129
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle update"
98
130
  ]
99
131
  },
100
132
  {
@@ -105,7 +137,7 @@
105
137
  },
106
138
  "outputs": [],
107
139
  "source": [
108
- "! bundle exec rake"
140
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle exec rspec"
109
141
  ]
110
142
  },
111
143
  {
@@ -249,7 +281,7 @@
249
281
  "metadata": {},
250
282
  "outputs": [],
251
283
  "source": [
252
- "! git tag v{NEW_VERSION}"
284
+ "! git tag {NEW_VERSION}"
253
285
  ]
254
286
  },
255
287
  {
@@ -265,7 +297,7 @@
265
297
  "metadata": {},
266
298
  "outputs": [],
267
299
  "source": [
268
- "! rake build"
300
+ "! BUNDLE_GEMFILE=gemfiles/{GEMFILE} bundle exec rake build"
269
301
  ]
270
302
  },
271
303
  {
@@ -1,12 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Api::V2::ArchitecturesController do
4
+ let(:resource_description) { Apipie.get_resource_description(described_class, "2.0") }
5
+
4
6
  describe "resource description" do
5
- subject { Apipie.get_resource_description(Api::V2::ArchitecturesController, "2.0") }
7
+ describe 'version' do
8
+ subject { resource_description._version }
6
9
 
7
- it "should be version 2.0" do
8
- expect(subject._version).to eq('2.0')
10
+ it { is_expected.to eq('2.0') }
9
11
  end
10
12
 
13
+ describe 'name' do
14
+ subject { resource_description.name }
15
+
16
+ it { is_expected.to eq('Architectures') }
17
+ end
11
18
  end
12
19
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Api::V2::EmptyMiddleController do
4
+ let(:resource_description) { Apipie.get_resource_description(described_class, '2.0') }
5
+
6
+ describe 'resource description' do
7
+ subject { resource_description }
8
+
9
+ context 'when namespaced resources are enabled' do
10
+ before { Apipie.configuration.namespaced_resources = true }
11
+ after { Apipie.configuration.namespaced_resources = false }
12
+
13
+ # we don't actually expect the resource description to be nil, but resource IDs
14
+ # are computed at file load time, and altering the value of namespaced_resources
15
+ # after the fact doesn't change the resource ID, so it can't be found
16
+ it { is_expected.to be_nil }
17
+ end
18
+
19
+ context 'when namespaced resources are disabled' do
20
+ it { is_expected.to be_nil }
21
+ end
22
+ end
23
+ end
@@ -1,8 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Api::V2::Nested::ResourcesController do
4
- describe "resource id" do
5
- subject { Apipie.get_resource_name(Api::V2::Nested::ResourcesController) }
4
+ let(:resource_description) { Apipie.get_resource_description(described_class, "2.0") }
5
+
6
+ describe "resource description" do
7
+ describe 'version' do
8
+ subject { resource_description._version }
9
+
10
+ it { is_expected.to eq('2.0') }
11
+ end
12
+
13
+ describe 'name' do
14
+ subject { resource_description.name }
15
+
16
+ it { is_expected.to eq('Rsrcs') }
17
+ end
18
+ end
19
+
20
+ describe '.get_resource_id' do
21
+ subject { Apipie.get_resource_id(Api::V2::Nested::ResourcesController) }
6
22
 
7
23
  it "should have resource_id set" do
8
24
  expect(subject).to eq("resource")
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Api::V2::Sub::FootgunsController do
4
+ let(:resource_description) { Apipie.get_resource_description(described_class, '2.0') }
5
+
6
+ describe 'resource description' do
7
+ describe 'version' do
8
+ subject { resource_description._version }
9
+
10
+ it { is_expected.to eq('2.0') }
11
+ end
12
+
13
+ describe 'name' do
14
+ subject { resource_description.name }
15
+
16
+ it { is_expected.to eq('snugtooF') }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe IncludedParamGroupController do
5
+
6
+ let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
7
+
8
+ it "should not error when there is a param_group that is deeply nested in response description" do
9
+ subject = Apipie.get_resource_description(IncludedParamGroupController, Apipie.configuration.default_version)
10
+ expect(subject._methods.keys).to include(:show)
11
+ end
12
+
13
+ end