apipierails3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +17 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +27 -0
- data/APACHE-LICENSE-2.0 +202 -0
- data/CHANGELOG.md +469 -0
- data/Gemfile +1 -0
- data/Gemfile.rails32 +6 -0
- data/Gemfile.rails41 +6 -0
- data/Gemfile.rails42 +11 -0
- data/Gemfile.rails50 +6 -0
- data/Gemfile.rails51 +7 -0
- data/MIT-LICENSE +20 -0
- data/NOTICE +4 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +1874 -0
- data/Rakefile +13 -0
- data/apipierails3.gemspec +27 -0
- data/app/controllers/apipie/apipies_controller.rb +199 -0
- data/app/helpers/apipie_helper.rb +10 -0
- data/app/public/apipie/javascripts/apipie.js +6 -0
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +138 -0
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1726 -0
- data/app/public/apipie/javascripts/bundled/jquery.js +5 -0
- data/app/public/apipie/javascripts/bundled/prettify.js +28 -0
- data/app/public/apipie/stylesheets/application.css +7 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +12 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +689 -0
- data/app/public/apipie/stylesheets/bundled/prettify.css +30 -0
- data/app/views/apipie/apipies/_disqus.html.erb +13 -0
- data/app/views/apipie/apipies/_errors.html.erb +23 -0
- data/app/views/apipie/apipies/_headers.html.erb +26 -0
- data/app/views/apipie/apipies/_languages.erb +6 -0
- data/app/views/apipie/apipies/_metadata.erb +1 -0
- data/app/views/apipie/apipies/_method_detail.erb +61 -0
- data/app/views/apipie/apipies/_params.html.erb +42 -0
- data/app/views/apipie/apipies/_params_plain.html.erb +20 -0
- data/app/views/apipie/apipies/apipie_404.html.erb +17 -0
- data/app/views/apipie/apipies/apipie_checksum.json.erb +1 -0
- data/app/views/apipie/apipies/getting_started.html.erb +6 -0
- data/app/views/apipie/apipies/index.html.erb +56 -0
- data/app/views/apipie/apipies/method.html.erb +41 -0
- data/app/views/apipie/apipies/plain.html.erb +77 -0
- data/app/views/apipie/apipies/resource.html.erb +80 -0
- data/app/views/apipie/apipies/static.html.erb +103 -0
- data/app/views/layouts/apipie/apipie.html.erb +27 -0
- data/config/locales/de.yml +28 -0
- data/config/locales/en.yml +32 -0
- data/config/locales/es.yml +28 -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/pl.yml +28 -0
- data/config/locales/pt-BR.yml +28 -0
- data/config/locales/ru.yml +28 -0
- data/config/locales/tr.yml +28 -0
- data/config/locales/zh-CN.yml +28 -0
- data/config/locales/zh-TW.yml +28 -0
- data/images/screenshot-1.png +0 -0
- data/images/screenshot-2.png +0 -0
- data/lib/apipie/apipie_module.rb +83 -0
- data/lib/apipie/application.rb +462 -0
- data/lib/apipie/configuration.rb +186 -0
- data/lib/apipie/dsl_definition.rb +607 -0
- data/lib/apipie/error_description.rb +44 -0
- data/lib/apipie/errors.rb +86 -0
- data/lib/apipie/extractor.rb +177 -0
- data/lib/apipie/extractor/collector.rb +117 -0
- data/lib/apipie/extractor/recorder.rb +166 -0
- data/lib/apipie/extractor/writer.rb +454 -0
- data/lib/apipie/helpers.rb +73 -0
- data/lib/apipie/markup.rb +48 -0
- data/lib/apipie/method_description.rb +273 -0
- data/lib/apipie/middleware/checksum_in_headers.rb +35 -0
- data/lib/apipie/param_description.rb +280 -0
- data/lib/apipie/railtie.rb +9 -0
- data/lib/apipie/resource_description.rb +124 -0
- data/lib/apipie/response_description.rb +131 -0
- data/lib/apipie/response_description_adapter.rb +200 -0
- data/lib/apipie/routes_formatter.rb +33 -0
- data/lib/apipie/routing.rb +16 -0
- data/lib/apipie/rspec/response_validation_helper.rb +192 -0
- data/lib/apipie/see_description.rb +39 -0
- data/lib/apipie/static_dispatcher.rb +69 -0
- data/lib/apipie/swagger_generator.rb +707 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +526 -0
- data/lib/apipie/version.rb +3 -0
- data/lib/apipierails3.rb +25 -0
- data/lib/generators/apipie/install/README +6 -0
- data/lib/generators/apipie/install/install_generator.rb +25 -0
- data/lib/generators/apipie/install/templates/initializer.rb.erb +7 -0
- data/lib/generators/apipie/views_generator.rb +11 -0
- data/lib/tasks/apipie.rake +345 -0
- data/rel-eng/packages/.readme +3 -0
- data/rel-eng/packages/rubygem-apipie-rails +1 -0
- data/rel-eng/tito.props +5 -0
- data/spec/controllers/api/v1/architectures_controller_spec.rb +29 -0
- data/spec/controllers/api/v2/architectures_controller_spec.rb +12 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +11 -0
- data/spec/controllers/apipies_controller_spec.rb +273 -0
- data/spec/controllers/concerns_controller_spec.rb +42 -0
- data/spec/controllers/extended_controller_spec.rb +11 -0
- data/spec/controllers/users_controller_spec.rb +740 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/api/base_controller.rb +4 -0
- data/spec/dummy/app/controllers/api/v1/architectures_controller.rb +43 -0
- data/spec/dummy/app/controllers/api/v1/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +30 -0
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/v2/nested/architectures_controller.rb +32 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +33 -0
- data/spec/dummy/app/controllers/application_controller.rb +18 -0
- data/spec/dummy/app/controllers/concerns/extending_concern.rb +11 -0
- data/spec/dummy/app/controllers/concerns/sample_controller.rb +41 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +8 -0
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- data/spec/dummy/app/controllers/files_controller.rb +5 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +31 -0
- data/spec/dummy/app/controllers/pets_controller.rb +408 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +307 -0
- data/spec/dummy/app/controllers/users_controller.rb +297 -0
- data/spec/dummy/app/views/layouts/application.html.erb +21 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +49 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +8 -0
- data/spec/dummy/config/environments/development.rb +28 -0
- data/spec/dummy/config/environments/production.rb +52 -0
- data/spec/dummy/config/environments/test.rb +38 -0
- data/spec/dummy/config/initializers/apipie.rb +110 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +51 -0
- data/spec/dummy/db/.gitkeep +0 -0
- data/spec/dummy/doc/apipie_examples.json +1 -0
- data/spec/dummy/doc/users/desc_from_file.md +1 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/lib/application_spec.rb +49 -0
- data/spec/lib/extractor/extractor_spec.rb +9 -0
- data/spec/lib/extractor/middleware_spec.rb +44 -0
- data/spec/lib/extractor/writer_spec.rb +110 -0
- data/spec/lib/file_handler_spec.rb +18 -0
- data/spec/lib/method_description_spec.rb +98 -0
- data/spec/lib/param_description_spec.rb +345 -0
- data/spec/lib/param_group_spec.rb +60 -0
- data/spec/lib/rake_spec.rb +71 -0
- data/spec/lib/resource_description_spec.rb +48 -0
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +139 -0
- data/spec/lib/swagger/response_validation_spec.rb +104 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
- data/spec/lib/validator_spec.rb +113 -0
- data/spec/lib/validators/array_validator_spec.rb +85 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/support/rake.rb +21 -0
- metadata +415 -0
data/lib/apipierails3.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
4
|
+
|
5
|
+
require "apipie/routing"
|
6
|
+
require "apipie/markup"
|
7
|
+
require "apipie/apipie_module"
|
8
|
+
require "apipie/dsl_definition"
|
9
|
+
require "apipie/configuration"
|
10
|
+
require "apipie/method_description"
|
11
|
+
require "apipie/resource_description"
|
12
|
+
require "apipie/param_description"
|
13
|
+
require "apipie/errors"
|
14
|
+
require "apipie/error_description"
|
15
|
+
require "apipie/response_description"
|
16
|
+
require "apipie/response_description_adapter"
|
17
|
+
require "apipie/see_description"
|
18
|
+
require "apipie/tag_list_description"
|
19
|
+
require "apipie/validator"
|
20
|
+
require "apipie/railtie"
|
21
|
+
require 'apipie/extractor'
|
22
|
+
require "apipie/version"
|
23
|
+
require "apipie/swagger_generator"
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Apipie
|
2
|
+
class InstallGenerator < ::Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
class_option(:route,
|
6
|
+
:aliases => "-r",
|
7
|
+
:type => :string,
|
8
|
+
:desc => "What path should be the doc available on",
|
9
|
+
:default => "/apipie")
|
10
|
+
|
11
|
+
class_option(:api_path,
|
12
|
+
:alias => "-a",
|
13
|
+
:type => :string,
|
14
|
+
:desc => "What path are API requests on",
|
15
|
+
:default => "/api")
|
16
|
+
|
17
|
+
def create_initializer
|
18
|
+
template 'initializer.rb.erb', 'config/initializers/apipie.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_route
|
22
|
+
route("apipie")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Apipie.configure do |config|
|
2
|
+
config.app_name = "<%= Rails.application.class.name[/^\w+/] %>"
|
3
|
+
config.api_base_url = "<%= options.api_path %>"
|
4
|
+
config.doc_base_url = "<%= options.route %>"
|
5
|
+
# where is your API defined?
|
6
|
+
config.api_controllers_matcher = "#{Rails.root}/app/controllers/**/*.rb"
|
7
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Apipie
|
2
|
+
class ViewsGenerator < ::Rails::Generators::Base
|
3
|
+
source_root File.expand_path("../../../../app/views", __FILE__)
|
4
|
+
desc 'Copy Apipie views to your application'
|
5
|
+
|
6
|
+
def copy_views
|
7
|
+
directory 'apipie', 'app/views/apipie'
|
8
|
+
directory 'layouts/apipie', 'app/views/layouts/apipie'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,345 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
namespace :apipie do
|
5
|
+
|
6
|
+
desc "Generate static documentation"
|
7
|
+
# You can specify OUT=output_base_file to have the following structure:
|
8
|
+
#
|
9
|
+
# output_base_file.html
|
10
|
+
# output_base_file-onepage.html
|
11
|
+
# output_base_file
|
12
|
+
# | - resource1.html
|
13
|
+
# | - resource1
|
14
|
+
# | - | - method1.html
|
15
|
+
# | - | - method2.html
|
16
|
+
# | - resource2.html
|
17
|
+
#
|
18
|
+
# By default OUT="#{Rails.root}/doc/apidoc"
|
19
|
+
task :static, [:version] => :environment do |t, args|
|
20
|
+
with_loaded_documentation do
|
21
|
+
args.with_defaults(:version => Apipie.configuration.default_version)
|
22
|
+
out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
|
23
|
+
subdir = File.basename(out)
|
24
|
+
copy_jscss(out)
|
25
|
+
Apipie.configuration.version_in_url = false
|
26
|
+
([nil] + Apipie.configuration.languages).each do |lang|
|
27
|
+
I18n.locale = lang || Apipie.configuration.default_locale
|
28
|
+
Apipie.url_prefix = "./#{subdir}"
|
29
|
+
doc = Apipie.to_json(args[:version], nil, nil, lang)
|
30
|
+
doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
|
31
|
+
generate_one_page(out, doc, lang)
|
32
|
+
generate_plain_page(out, doc, lang)
|
33
|
+
generate_index_page(out, doc, false, false, lang)
|
34
|
+
Apipie.url_prefix = "../#{subdir}"
|
35
|
+
generate_resource_pages(args[:version], out, doc, false, lang)
|
36
|
+
Apipie.url_prefix = "../../#{subdir}"
|
37
|
+
generate_method_pages(args[:version], out, doc, false, lang)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Generate static documentation json"
|
43
|
+
task :static_json, [:version] => :environment do |t, args|
|
44
|
+
with_loaded_documentation do
|
45
|
+
args.with_defaults(:version => Apipie.configuration.default_version)
|
46
|
+
out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
|
47
|
+
([nil] + Apipie.configuration.languages).each do |lang|
|
48
|
+
doc = Apipie.to_json(args[:version], nil, nil, lang)
|
49
|
+
generate_json_page(out, doc, lang)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Generate static swagger json"
|
55
|
+
task :static_swagger_json, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
|
56
|
+
with_loaded_documentation do
|
57
|
+
out = ENV["OUT"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc')
|
58
|
+
generate_swagger_using_args(args, out)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# The following task compares the currently-generated swagger output to a reference copy generated
|
63
|
+
# by the previous execution of this task.
|
64
|
+
# if a difference is detected, the current output will be stored as a reference.
|
65
|
+
# reference files have the
|
66
|
+
# if more than 3 references are detected, the older ones will be purged
|
67
|
+
desc "Did swagger output change since the last execution of this task?"
|
68
|
+
task :did_swagger_change, [:version, :swagger_content_type_input, :filename_suffix] => :environment do |t, args|
|
69
|
+
with_loaded_documentation do
|
70
|
+
out = ENV["OUT_REF"] || File.join(::Rails.root, Apipie.configuration.doc_path, 'apidoc_ref')
|
71
|
+
paths = generate_swagger_using_args(args, out)
|
72
|
+
paths.each {|path|
|
73
|
+
existing_files_in_dir = Pathname(out).children(true)
|
74
|
+
|
75
|
+
make_reference = false
|
76
|
+
|
77
|
+
# reference filenames have the format <basename>.<counter>.swagger_ref
|
78
|
+
reference_files = existing_files_in_dir.select{|f|
|
79
|
+
f.extname == '.swagger_ref' &&
|
80
|
+
f.basename.sub_ext("").extname.delete('.').to_i > 0 &&
|
81
|
+
f.basename.sub_ext("").sub_ext("") == path.basename.sub_ext("")
|
82
|
+
}
|
83
|
+
if reference_files.empty?
|
84
|
+
print "Reference file does not exist for [#{path}]\n"
|
85
|
+
counter = 1
|
86
|
+
make_reference = true
|
87
|
+
else
|
88
|
+
reference_files.sort_by! {|f| f.ctime }
|
89
|
+
last_ref = reference_files[-1]
|
90
|
+
print "Comparing [#{path}] to reference file: [#{last_ref.basename}]: "
|
91
|
+
if !FileUtils.compare_file(path, last_ref)
|
92
|
+
print("\n ---> Differences detected\n")
|
93
|
+
counter = last_ref.sub_ext("").extname.delete('.').to_i + 1
|
94
|
+
make_reference = true
|
95
|
+
else
|
96
|
+
print("identical\n")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if make_reference
|
101
|
+
new_path = path.sub_ext(".#{counter}.swagger_ref")
|
102
|
+
print " ---> Keeping current output as [#{new_path}]\n"
|
103
|
+
path.rename(new_path)
|
104
|
+
reference_files << new_path
|
105
|
+
else
|
106
|
+
path.delete
|
107
|
+
end
|
108
|
+
|
109
|
+
num_refs_to_keep = 3
|
110
|
+
if reference_files.length > num_refs_to_keep
|
111
|
+
(reference_files - reference_files[-num_refs_to_keep..-1]).each{|f| f.delete}
|
112
|
+
end
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
# By default the full cache is built.
|
120
|
+
# It is possible to generate index resp. resources only with
|
121
|
+
# rake apipie:cache cache_part=index (resources resp.)
|
122
|
+
# Default output dir ('public/apipie_cache') can be changed with OUT=/some/dir
|
123
|
+
desc "Generate cache to avoid production dependencies on markup languages"
|
124
|
+
task :cache => :environment do
|
125
|
+
puts "#{Time.now} | Started"
|
126
|
+
cache_part = ENV['cache_part']
|
127
|
+
generate_index = (cache_part == 'resources' ? false : true)
|
128
|
+
generate_resources = (cache_part == 'index' ? false : true)
|
129
|
+
with_loaded_documentation do
|
130
|
+
puts "#{Time.now} | Documents loaded..."
|
131
|
+
([nil] + Apipie.configuration.languages).each do |lang|
|
132
|
+
I18n.locale = lang || Apipie.configuration.default_locale
|
133
|
+
puts "#{Time.now} | Processing docs for #{lang}"
|
134
|
+
cache_dir = ENV["OUT"] || Apipie.configuration.cache_dir
|
135
|
+
subdir = Apipie.configuration.doc_base_url.sub(/\A\//,"")
|
136
|
+
subdir_levels = subdir.split('/').length
|
137
|
+
subdir_traversal_prefix = '../' * subdir_levels
|
138
|
+
file_base = File.join(cache_dir, Apipie.configuration.doc_base_url)
|
139
|
+
|
140
|
+
if generate_index
|
141
|
+
Apipie.url_prefix = "./#{subdir}"
|
142
|
+
doc = Apipie.to_json(Apipie.configuration.default_version, nil, nil, lang)
|
143
|
+
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
|
144
|
+
generate_index_page(file_base, doc, true, false, lang)
|
145
|
+
end
|
146
|
+
Apipie.available_versions.each do |version|
|
147
|
+
file_base_version = File.join(file_base, version)
|
148
|
+
Apipie.url_prefix = "#{subdir_traversal_prefix}#{subdir}"
|
149
|
+
doc = Apipie.to_json(version, nil, nil, lang)
|
150
|
+
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
|
151
|
+
|
152
|
+
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
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
puts "#{Time.now} | Finished"
|
163
|
+
end
|
164
|
+
|
165
|
+
# Attempt to use the Rails application views, otherwise default to built in views
|
166
|
+
def renderer
|
167
|
+
return @apipie_renderer if @apipie_renderer
|
168
|
+
|
169
|
+
base_paths = [File.expand_path("../../../app/views/apipie/apipies", __FILE__)]
|
170
|
+
base_paths.unshift("#{Rails.root}/app/views/apipie/apipies") if File.directory?("#{Rails.root}/app/views/apipie/apipies")
|
171
|
+
|
172
|
+
layouts_paths = [File.expand_path("../../../app/views/layouts", __FILE__)]
|
173
|
+
layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie")
|
174
|
+
|
175
|
+
@apipie_renderer = ActionView::Base.new(base_paths + layouts_paths)
|
176
|
+
@apipie_renderer.singleton_class.send(:include, ApipieHelper)
|
177
|
+
return @apipie_renderer
|
178
|
+
end
|
179
|
+
|
180
|
+
def render_page(file_name, template, variables, layout = 'apipie')
|
181
|
+
av = renderer
|
182
|
+
File.open(file_name, "w") do |f|
|
183
|
+
variables.each do |var, val|
|
184
|
+
av.instance_variable_set("@#{var}", val)
|
185
|
+
end
|
186
|
+
f.write av.render(
|
187
|
+
:template => "#{template}",
|
188
|
+
:layout => (layout && "apipie/#{layout}"))
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def generate_swagger_using_args(args, out)
|
193
|
+
args.with_defaults(:version => Apipie.configuration.default_version,
|
194
|
+
:swagger_content_type_input => Apipie.configuration.swagger_content_type_input || :form_data,
|
195
|
+
:filename_suffix => nil)
|
196
|
+
Apipie.configuration.swagger_content_type_input = args[:swagger_content_type_input].to_sym
|
197
|
+
count = 0
|
198
|
+
|
199
|
+
sfx = args[:filename_suffix] || "_#{args[:swagger_content_type_input]}"
|
200
|
+
|
201
|
+
paths = []
|
202
|
+
|
203
|
+
([nil] + Apipie.configuration.languages).each do |lang|
|
204
|
+
doc = Apipie.to_swagger_json(args[:version], nil, nil, lang, count==0)
|
205
|
+
paths << generate_swagger_json_page(out, doc, sfx, lang)
|
206
|
+
count+=1
|
207
|
+
end
|
208
|
+
|
209
|
+
paths
|
210
|
+
end
|
211
|
+
|
212
|
+
def generate_json_page(file_base, doc, lang = nil)
|
213
|
+
FileUtils.mkdir_p(file_base) unless File.exists?(file_base)
|
214
|
+
|
215
|
+
filename = "schema_apipie#{lang_ext(lang)}.json"
|
216
|
+
File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
|
217
|
+
end
|
218
|
+
|
219
|
+
def generate_swagger_json_page(file_base, doc, sfx="", lang = nil)
|
220
|
+
FileUtils.mkdir_p(file_base) unless File.exists?(file_base)
|
221
|
+
|
222
|
+
path = Pathname.new("#{file_base}/schema_swagger#{sfx}#{lang_ext(lang)}.json")
|
223
|
+
File.open(path, 'w') { |file| file.write(JSON.pretty_generate(doc)) }
|
224
|
+
|
225
|
+
path
|
226
|
+
end
|
227
|
+
|
228
|
+
def generate_one_page(file_base, doc, lang = nil)
|
229
|
+
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
|
230
|
+
|
231
|
+
render_page("#{file_base}-onepage#{lang_ext(lang)}.html", "static", {:doc => doc[:docs],
|
232
|
+
:language => lang, :languages => Apipie.configuration.languages})
|
233
|
+
end
|
234
|
+
|
235
|
+
def generate_plain_page(file_base, doc, lang = nil)
|
236
|
+
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
|
237
|
+
|
238
|
+
render_page("#{file_base}-plain#{lang_ext(lang)}.html", "plain", {:doc => doc[:docs],
|
239
|
+
:language => lang, :languages => Apipie.configuration.languages}, nil)
|
240
|
+
end
|
241
|
+
|
242
|
+
def generate_index_page(file_base, doc, include_json = false, show_versions = false, lang = nil)
|
243
|
+
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))
|
244
|
+
versions = show_versions && Apipie.available_versions
|
245
|
+
render_page("#{file_base}#{lang_ext(lang)}.html", "index", {:doc => doc[:docs],
|
246
|
+
:versions => versions, :language => lang, :languages => Apipie.configuration.languages})
|
247
|
+
|
248
|
+
File.open("#{file_base}#{lang_ext(lang)}.json", "w") { |f| f << doc.to_json } if include_json
|
249
|
+
end
|
250
|
+
|
251
|
+
def generate_resource_pages(version, file_base, doc, include_json = false, lang = nil)
|
252
|
+
doc[:docs][:resources].each do |resource_name, _|
|
253
|
+
resource_file_base = File.join(file_base, resource_name.to_s)
|
254
|
+
FileUtils.mkdir_p(File.dirname(resource_file_base)) unless File.exists?(File.dirname(resource_file_base))
|
255
|
+
|
256
|
+
doc = Apipie.to_json(version, resource_name, nil, lang)
|
257
|
+
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
|
258
|
+
render_page("#{resource_file_base}#{lang_ext(lang)}.html", "resource", {:doc => doc[:docs],
|
259
|
+
:resource => doc[:docs][:resources].first, :language => lang, :languages => Apipie.configuration.languages})
|
260
|
+
File.open("#{resource_file_base}#{lang_ext(lang)}.json", "w") { |f| f << doc.to_json } if include_json
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def generate_method_pages(version, file_base, doc, include_json = false, lang = nil)
|
265
|
+
doc[:docs][:resources].each do |resource_name, resource_params|
|
266
|
+
resource_params[:methods].each do |method|
|
267
|
+
method_file_base = File.join(file_base, resource_name.to_s, method[:name].to_s)
|
268
|
+
FileUtils.mkdir_p(File.dirname(method_file_base)) unless File.exists?(File.dirname(method_file_base))
|
269
|
+
|
270
|
+
doc = Apipie.to_json(version, resource_name, method[:name], lang)
|
271
|
+
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
|
272
|
+
render_page("#{method_file_base}#{lang_ext(lang)}.html", "method", {:doc => doc[:docs],
|
273
|
+
:resource => doc[:docs][:resources].first,
|
274
|
+
:method => doc[:docs][:resources].first[:methods].first,
|
275
|
+
:language => lang,
|
276
|
+
:languages => Apipie.configuration.languages})
|
277
|
+
|
278
|
+
File.open("#{method_file_base}#{lang_ext(lang)}.json", "w") { |f| f << doc.to_json } if include_json
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def with_loaded_documentation
|
284
|
+
Apipie.configuration.use_cache = false # we don't want to skip DSL evaluation
|
285
|
+
Apipie.reload_documentation
|
286
|
+
yield
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
def copy_jscss(dest)
|
291
|
+
src = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'app', 'public', 'apipie'))
|
292
|
+
FileUtils.mkdir_p dest
|
293
|
+
FileUtils.cp_r "#{src}/.", dest
|
294
|
+
end
|
295
|
+
|
296
|
+
def lang_ext(lang = nil)
|
297
|
+
lang ? ".#{lang}" : ""
|
298
|
+
end
|
299
|
+
|
300
|
+
desc "Generate CLI client for API documented with apipie gem. (deprecated)"
|
301
|
+
task :client do
|
302
|
+
puts <<MESSAGE
|
303
|
+
The apipie gem itself doesn't provide client code generator. See
|
304
|
+
https://github.com/Pajk/apipie-rails/wiki/CLI-client for more information on
|
305
|
+
how to write your own generator.
|
306
|
+
MESSAGE
|
307
|
+
end
|
308
|
+
|
309
|
+
def plaintext(text)
|
310
|
+
text.gsub(/<.*?>/, '').gsub("\n",' ').strip
|
311
|
+
end
|
312
|
+
|
313
|
+
desc "Update api description in controllers base on routes"
|
314
|
+
task :update_from_routes => [:environment] do
|
315
|
+
Apipie.configuration.force_dsl = true
|
316
|
+
ignored = Apipie.configuration.ignored_by_recorder
|
317
|
+
with_loaded_documentation do
|
318
|
+
apis_from_routes = Apipie::Extractor.apis_from_routes
|
319
|
+
apis_from_routes.each do |(controller, action), apis|
|
320
|
+
next if ignored.include?(controller)
|
321
|
+
next if ignored.include?("#{controller}##{action}")
|
322
|
+
Apipie::Extractor::Writer.update_action_description((controller.safe_constantize || next), action) do |u|
|
323
|
+
u.update_apis(apis)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
desc "Convert your examples from the old yaml into the new json format"
|
330
|
+
task :convert_examples => :environment do
|
331
|
+
yaml_examples_file = File.join(Rails.root, Apipie.configuration.doc_path, "apipie_examples.yml")
|
332
|
+
if File.exists?(yaml_examples_file)
|
333
|
+
#if SafeYAML gem is enabled, it will load examples as an array of Hash, instead of hash
|
334
|
+
if defined? SafeYAML
|
335
|
+
examples = YAML.load_file(yaml_examples_file, :safe=>false)
|
336
|
+
else
|
337
|
+
examples = YAML.load_file(yaml_examples_file)
|
338
|
+
end
|
339
|
+
else
|
340
|
+
examples = {}
|
341
|
+
end
|
342
|
+
Apipie::Extractor::Writer.write_recorded_examples(examples)
|
343
|
+
end
|
344
|
+
|
345
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
0.0.7-1 /
|
data/rel-eng/tito.props
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api::V1::ArchitecturesController do
|
4
|
+
describe "resource description" do
|
5
|
+
subject { Apipie.get_resource_description(Api::V1::ArchitecturesController, "1.0") }
|
6
|
+
|
7
|
+
it "should be version 1.0" do
|
8
|
+
expect(subject._version).to eq('1.0')
|
9
|
+
|
10
|
+
expect(Apipie.resource_descriptions['1.0'].size).to eq(2)
|
11
|
+
expect(Apipie.resource_descriptions['1.0'].keys).to include('architectures', 'base')
|
12
|
+
end
|
13
|
+
|
14
|
+
context "there is another version" do
|
15
|
+
let(:v2) { archv2 = Apipie.get_resource_description(Api::V2::ArchitecturesController, "2.0") }
|
16
|
+
|
17
|
+
it "should have unique doc url" do
|
18
|
+
expect(subject.doc_url).not_to eq(v2.doc_url)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have unique methods" do
|
22
|
+
expect(subject._methods.keys).to include(:index)
|
23
|
+
expect(v2._methods.keys).to include(:index)
|
24
|
+
expect(subject._methods[:index]).not_to eq(v2._methods[:index])
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|