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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +31 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +128 -0
- data/.rubocop_todo.yml +2056 -0
- data/.vscode/settings.json +3 -0
- data/CHANGELOG.md +161 -0
- data/Gemfile +20 -0
- data/README.rst +117 -23
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +18 -9
- data/app/controllers/apipie/apipies_controller.rb +14 -29
- data/app/helpers/apipie_helper.rb +1 -1
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
- data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
- data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
- data/app/views/apipie/apipies/_params.html.erb +7 -1
- data/config/locales/en.yml +8 -0
- data/config/locales/ko.yml +31 -0
- data/gemfiles/Gemfile.tools +9 -0
- data/lib/apipie/apipie_module.rb +7 -7
- data/lib/apipie/application.rb +132 -97
- data/lib/apipie/configuration.rb +43 -33
- data/lib/apipie/dsl_definition.rb +44 -33
- data/lib/apipie/error_description.rb +3 -3
- data/lib/apipie/errors.rb +17 -17
- data/lib/apipie/extractor/collector.rb +5 -6
- data/lib/apipie/extractor/recorder.rb +35 -8
- data/lib/apipie/extractor/writer.rb +15 -15
- data/lib/apipie/extractor.rb +6 -9
- data/lib/apipie/generator/config.rb +12 -0
- data/lib/apipie/generator/generator.rb +2 -0
- data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
- data/lib/apipie/generator/swagger/config.rb +80 -0
- data/lib/apipie/generator/swagger/context.rb +38 -0
- data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
- data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
- data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
- data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
- data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
- data/lib/apipie/generator/swagger/method_description.rb +2 -0
- data/lib/apipie/generator/swagger/operation_id.rb +51 -0
- data/lib/apipie/generator/swagger/param_description/builder.rb +114 -0
- data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
- data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
- data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
- data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
- data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
- data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
- data/lib/apipie/generator/swagger/param_description/type.rb +128 -0
- data/lib/apipie/generator/swagger/param_description.rb +18 -0
- data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
- data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
- data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
- data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
- data/lib/apipie/generator/swagger/schema.rb +63 -0
- data/lib/apipie/generator/swagger/swagger.rb +2 -0
- data/lib/apipie/generator/swagger/type.rb +16 -0
- data/lib/apipie/generator/swagger/type_extractor.rb +51 -0
- data/lib/apipie/generator/swagger/warning.rb +74 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
- data/lib/apipie/helpers.rb +3 -3
- data/lib/apipie/markup.rb +9 -8
- data/lib/apipie/method_description/api.rb +12 -0
- data/lib/apipie/method_description/apis_service.rb +82 -0
- data/lib/apipie/method_description.rb +12 -56
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +57 -24
- data/lib/apipie/resource_description.rb +42 -14
- data/lib/apipie/response_description.rb +3 -3
- data/lib/apipie/response_description_adapter.rb +12 -10
- data/lib/apipie/routing.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +3 -3
- data/lib/apipie/static_dispatcher.rb +10 -2
- data/lib/apipie/swagger_generator.rb +28 -691
- data/lib/apipie/validator.rb +41 -11
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +36 -5
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +37 -32
- data/rel-eng/gem_release.ipynb +41 -9
- data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
- data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
- data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
- data/spec/controllers/users_controller_spec.rb +47 -6
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
- data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
- data/spec/dummy/app/controllers/pets_controller.rb +5 -5
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
- data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
- data/spec/dummy/app/controllers/users_controller.rb +17 -5
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
- data/spec/dummy/config/application.rb +2 -5
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +0 -3
- data/spec/dummy/config/environments/production.rb +0 -3
- data/spec/dummy/config/environments/test.rb +0 -5
- data/spec/dummy/config/initializers/apipie.rb +2 -2
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
- data/spec/lib/apipie/application_spec.rb +62 -0
- data/spec/lib/apipie/configuration_spec.rb +38 -0
- data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
- data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
- data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
- data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
- data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
- data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
- data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
- data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -0
- data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
- data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
- data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
- data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +183 -0
- data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
- data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
- data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
- data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
- data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
- data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
- data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/apipie/method_description_spec.rb +133 -0
- data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
- data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
- data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
- data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
- data/spec/lib/apipie/resource_description_spec.rb +91 -0
- data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
- data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
- data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
- data/spec/lib/rake_spec.rb +3 -5
- data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
- data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
- data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
- data/spec/lib/validators/array_validator_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -32
- data/spec/support/custom_bool_validator.rb +17 -0
- data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
- metadata +173 -125
- data/.travis.yml +0 -41
- data/Gemfile +0 -1
- data/Gemfile.rails41 +0 -7
- data/Gemfile.rails42 +0 -14
- data/Gemfile.rails50 +0 -9
- data/Gemfile.rails51 +0 -9
- data/Gemfile.rails60 +0 -10
- data/Gemfile.rails61 +0 -10
- data/spec/lib/application_spec.rb +0 -49
- data/spec/lib/method_description_spec.rb +0 -98
- data/spec/lib/resource_description_spec.rb +0 -48
- /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
data/lib/apipie/validator.rb
CHANGED
@@ -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::
|
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
|
-
|
343
|
-
|
358
|
+
|
359
|
+
BaseValidator.raise_if_missing_params do |missing|
|
360
|
+
@hash_params&.each do |k, p|
|
344
361
|
if Apipie.configuration.validate_presence?
|
345
|
-
|
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.
|
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.
|
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
|
473
|
-
|
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::
|
516
|
+
@validator = Apipie::Validator::HashValidator.new(param_description, argument, param_group)
|
487
517
|
@type = argument
|
488
518
|
end
|
489
519
|
|
data/lib/apipie/version.rb
CHANGED
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
|
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
|
-
|
28
|
-
|
29
|
-
|
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"
|
data/lib/tasks/apipie.rake
CHANGED
@@ -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(
|
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(
|
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(
|
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(
|
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!
|
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
|
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(
|
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
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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(
|
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(
|
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 =>
|
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(
|
199
|
-
|
200
|
-
|
201
|
-
|
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].
|
258
|
-
resource_file_base = File.join(file_base,
|
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,
|
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 |
|
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,
|
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,
|
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,
|
data/rel-eng/gem_release.ipynb
CHANGED
@@ -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
|
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.
|
45
|
-
"LAST_VERSION = '0.5.
|
54
|
+
"NEW_VERSION = '0.5.20'\n",
|
55
|
+
"LAST_VERSION = '0.5.19'\n",
|
46
56
|
"GIT_REMOTE_UPSTREAM = 'origin'\n",
|
47
|
-
"
|
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
|
-
"###
|
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
|
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
|
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
|
-
|
7
|
+
describe 'version' do
|
8
|
+
subject { resource_description._version }
|
6
9
|
|
7
|
-
|
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
|
-
|
5
|
-
|
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
|