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.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +67 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +1991 -0
- data/CHANGELOG.md +246 -2
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +646 -25
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +14 -9
- data/app/controllers/apipie/apipies_controller.rb +51 -20
- 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/_method_detail.erb +21 -0
- data/app/views/apipie/apipies/_params.html.erb +4 -2
- data/app/views/apipie/apipies/index.html.erb +5 -1
- data/app/views/apipie/apipies/resource.html.erb +3 -0
- data/app/views/layouts/apipie/apipie.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/config/locales/fr.yml +31 -0
- data/config/locales/it.yml +31 -0
- data/config/locales/ja.yml +31 -0
- data/config/locales/ko.yml +31 -0
- data/config/locales/pt-BR.yml +1 -1
- data/gemfiles/Gemfile.rails50 +10 -0
- data/gemfiles/Gemfile.rails51 +10 -0
- data/gemfiles/Gemfile.rails52 +10 -0
- data/gemfiles/Gemfile.rails60 +17 -0
- data/gemfiles/Gemfile.rails61 +17 -0
- data/gemfiles/Gemfile.rails70 +17 -0
- data/lib/apipie/apipie_module.rb +22 -4
- data/lib/apipie/application.rb +54 -25
- data/lib/apipie/configuration.rb +26 -4
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +168 -16
- data/lib/apipie/error_description.rb +9 -2
- data/lib/apipie/errors.rb +34 -0
- data/lib/apipie/extractor/collector.rb +4 -0
- data/lib/apipie/extractor/recorder.rb +14 -12
- data/lib/apipie/extractor/writer.rb +86 -58
- data/lib/apipie/extractor.rb +5 -5
- data/lib/apipie/generator/generator.rb +2 -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 +70 -0
- data/lib/apipie/generator/swagger/warning.rb +77 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
- data/lib/apipie/markup.rb +14 -11
- 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 +51 -49
- data/lib/apipie/param_description.rb +63 -5
- data/lib/apipie/resource_description.rb +11 -4
- data/lib/apipie/response_description.rb +131 -0
- data/lib/apipie/response_description_adapter.rb +200 -0
- data/lib/apipie/routes_formatter.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +194 -0
- data/lib/apipie/static_dispatcher.rb +5 -2
- data/lib/apipie/swagger_generator.rb +717 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +83 -9
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +15 -4
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +115 -15
- data/rel-eng/gem_release.ipynb +398 -0
- data/spec/controllers/apipies_controller_spec.rb +79 -14
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/controllers/memes_controller_spec.rb +10 -0
- data/spec/controllers/users_controller_spec.rb +139 -76
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/application_controller.rb +5 -1
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- data/spec/dummy/app/controllers/extending_concern.rb +10 -0
- 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 +408 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +5 -7
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +26 -12
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/Gemfile +6 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
- data/spec/dummy/components/test_engine/config/routes.rb +3 -0
- data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
- data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
- data/spec/dummy/config/application.rb +6 -4
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/environments/production.rb +3 -3
- data/spec/dummy/config/environments/test.rb +3 -5
- data/spec/dummy/config/initializers/apipie.rb +5 -3
- data/spec/dummy/config/routes.rb +25 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/lib/application_spec.rb +1 -1
- data/spec/lib/extractor/writer_spec.rb +37 -7
- data/spec/lib/file_handler_spec.rb +25 -0
- data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
- data/spec/lib/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
- data/spec/lib/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/method_description_spec.rb +34 -0
- data/spec/lib/param_description_spec.rb +90 -4
- data/spec/lib/rake_spec.rb +2 -4
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +154 -0
- data/spec/lib/swagger/response_validation_spec.rb +104 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
- data/spec/lib/validator_spec.rb +59 -1
- data/spec/lib/validators/array_validator_spec.rb +28 -8
- data/spec/spec_helper.rb +49 -3
- data/spec/support/custom_bool_validator.rb +17 -0
- metadata +104 -99
- data/.travis.yml +0 -12
- data/Gemfile +0 -7
- data/Gemfile.rails32 +0 -6
- data/Gemfile.rails40 +0 -5
- data/Gemfile.rails41 +0 -5
- data/Gemfile.rails42 +0 -5
- data/lib/apipie/client/generator.rb +0 -135
data/lib/apipie/validator.rb
CHANGED
@@ -3,7 +3,7 @@ module Apipie
|
|
3
3
|
|
4
4
|
module Validator
|
5
5
|
|
6
|
-
# to create new validator, inherit from Apipie::Validator::
|
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
|
-
|
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
|
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|
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
data/lib/apipie/version.rb
CHANGED
data/lib/apipie-rails.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'i18n'
|
2
|
+
require 'json'
|
2
3
|
require 'active_support/hash_with_indifferent_access'
|
3
4
|
|
5
|
+
require 'apipie/core_ext/route'
|
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
|
-
|
21
|
-
|
22
|
-
|
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"
|
data/lib/tasks/apipie.rake
CHANGED
@@ -51,6 +51,71 @@ namespace :apipie do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
desc "Generate static swagger json"
|
55
|
+
task :static_swagger_json, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
|
56
|
+
with_loaded_documentation do
|
57
|
+
out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
|
58
|
+
generate_swagger_using_args(args, out)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# The following task compares the currently-generated swagger output to a reference copy generated
|
63
|
+
# by the previous execution of this task.
|
64
|
+
# if a difference is detected, the current output will be stored as a reference.
|
65
|
+
# reference files have the
|
66
|
+
# if more than 3 references are detected, the older ones will be purged
|
67
|
+
desc "Did swagger output change since the last execution of this task?"
|
68
|
+
task :did_swagger_change, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
|
69
|
+
with_loaded_documentation do
|
70
|
+
out = ENV["OUT_REF"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc_ref')
|
71
|
+
paths = generate_swagger_using_args(args, out)
|
72
|
+
paths.each {|path|
|
73
|
+
existing_files_in_dir = Pathname(out).children(true)
|
74
|
+
|
75
|
+
make_reference = false
|
76
|
+
|
77
|
+
# reference filenames have the format <basename>.<counter>.swagger_ref
|
78
|
+
reference_files = existing_files_in_dir.select{|f|
|
79
|
+
f.extname == '.swagger_ref' &&
|
80
|
+
f.basename.sub_ext("").extname.delete('.').to_i > 0 &&
|
81
|
+
f.basename.sub_ext("").sub_ext("") == path.basename.sub_ext("")
|
82
|
+
}
|
83
|
+
if reference_files.empty?
|
84
|
+
print "Reference file does not exist for [#{path}]\n"
|
85
|
+
counter = 1
|
86
|
+
make_reference = true
|
87
|
+
else
|
88
|
+
reference_files.sort_by!(&: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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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)
|