apipie-rails 0.3.6 → 0.5.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +23 -7
- data/CHANGELOG.md +147 -2
- data/Gemfile +1 -0
- data/Gemfile.rails41 +2 -0
- data/Gemfile.rails42 +10 -1
- data/Gemfile.rails50 +9 -0
- data/Gemfile.rails51 +9 -0
- data/Gemfile.rails60 +14 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +570 -17
- data/apipie-rails.gemspec +3 -3
- data/app/controllers/apipie/apipies_controller.rb +48 -17
- 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/lib/apipie/apipie_module.rb +22 -4
- data/lib/apipie/application.rb +55 -28
- data/lib/apipie/configuration.rb +19 -3
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +151 -10
- 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 +13 -12
- data/lib/apipie/extractor/writer.rb +83 -55
- data/lib/apipie/extractor.rb +10 -4
- data/lib/apipie/method_description.rb +51 -4
- data/lib/apipie/param_description.rb +56 -2
- data/lib/apipie/resource_description.rb +10 -3
- 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 +3 -2
- data/lib/apipie/swagger_generator.rb +708 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +69 -8
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +7 -0
- data/lib/tasks/apipie.rake +103 -8
- data/spec/controllers/apipies_controller_spec.rb +52 -12
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/memes_controller_spec.rb +10 -0
- data/spec/controllers/users_controller_spec.rb +115 -75
- data/spec/dummy/app/controllers/application_controller.rb +5 -1
- data/spec/dummy/app/controllers/concerns/extending_concern.rb +12 -0
- data/spec/dummy/app/controllers/concerns/sample_controller.rb +5 -5
- data/spec/dummy/app/controllers/extended_controller.rb +14 -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 +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +19 -11
- 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 +5 -0
- data/spec/dummy/config/environments/development.rb +3 -0
- data/spec/dummy/config/environments/production.rb +3 -0
- data/spec/dummy/config/environments/test.rb +3 -0
- data/spec/dummy/config/initializers/apipie.rb +3 -1
- data/spec/dummy/config/routes.rb +24 -1
- data/spec/lib/extractor/writer_spec.rb +32 -4
- data/spec/lib/file_handler_spec.rb +18 -0
- data/spec/lib/method_description_spec.rb +34 -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 +58 -0
- data/spec/lib/validators/array_validator_spec.rb +28 -8
- data/spec/spec_helper.rb +68 -0
- metadata +75 -23
- data/Gemfile +0 -7
- data/Gemfile.rails32 +0 -6
- data/Gemfile.rails40 +0 -5
- data/lib/apipie/client/generator.rb +0 -135
data/apipie-rails.gemspec
CHANGED
@@ -10,14 +10,13 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/Apipie/apipie-rails"
|
11
11
|
s.summary = %q{Rails REST API documentation tool}
|
12
12
|
s.description = %q{Rails REST API documentation tool}
|
13
|
-
|
13
|
+
s.required_ruby_version = '>= 2.0.0'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.
|
20
|
-
s.add_dependency 'json'
|
19
|
+
s.add_dependency "rails", ">= 4.1"
|
21
20
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
22
21
|
s.add_development_dependency "sqlite3"
|
23
22
|
s.add_development_dependency "minitest"
|
@@ -25,4 +24,5 @@ Gem::Specification.new do |s|
|
|
25
24
|
s.add_development_dependency "RedCloth"
|
26
25
|
s.add_development_dependency "rake"
|
27
26
|
s.add_development_dependency "rdoc"
|
27
|
+
s.add_development_dependency "json-schema", "~> 2.8"
|
28
28
|
end
|
@@ -5,8 +5,8 @@ module Apipie
|
|
5
5
|
|
6
6
|
layout Apipie.configuration.layout
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
around_action :set_script_name
|
9
|
+
before_action :authenticate
|
10
10
|
|
11
11
|
def authenticate
|
12
12
|
if Apipie.configuration.authenticate
|
@@ -14,11 +14,17 @@ module Apipie
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
|
17
18
|
def index
|
18
19
|
params[:version] ||= Apipie.configuration.default_version
|
19
20
|
|
20
21
|
get_format
|
21
22
|
|
23
|
+
if params[:type].to_s == 'swagger' && params[:format].to_s == 'json'
|
24
|
+
head :forbidden and return if Apipie.configuration.authorize
|
25
|
+
should_render_swagger = true
|
26
|
+
end
|
27
|
+
|
22
28
|
respond_to do |format|
|
23
29
|
|
24
30
|
if Apipie.configuration.use_cache?
|
@@ -31,9 +37,19 @@ module Apipie
|
|
31
37
|
Apipie.load_documentation if Apipie.configuration.reload_controllers? || (Rails.version.to_i >= 4.0 && !Rails.application.config.eager_load)
|
32
38
|
|
33
39
|
I18n.locale = @language
|
34
|
-
@doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
|
35
40
|
|
36
|
-
|
41
|
+
if should_render_swagger
|
42
|
+
prev_warning_value = Apipie.configuration.swagger_suppress_warnings
|
43
|
+
begin
|
44
|
+
Apipie.configuration.swagger_suppress_warnings = true
|
45
|
+
@doc = Apipie.to_swagger_json(params[:version], params[:resource], params[:method], @language)
|
46
|
+
ensure
|
47
|
+
Apipie.configuration.swagger_suppress_warnings = prev_warning_value
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
|
51
|
+
@doc = authorized_doc
|
52
|
+
end
|
37
53
|
|
38
54
|
format.json do
|
39
55
|
if @doc
|
@@ -79,7 +95,8 @@ module Apipie
|
|
79
95
|
helper_method :heading
|
80
96
|
|
81
97
|
def get_language
|
82
|
-
|
98
|
+
return nil unless Apipie.configuration.translate
|
99
|
+
lang = Apipie.configuration.default_locale
|
83
100
|
[:resource, :method, :version].each do |par|
|
84
101
|
if params[par]
|
85
102
|
splitted = params[par].split('.')
|
@@ -93,30 +110,44 @@ module Apipie
|
|
93
110
|
end
|
94
111
|
|
95
112
|
def authorized_doc
|
96
|
-
|
113
|
+
return if @doc.nil?
|
97
114
|
return @doc unless Apipie.configuration.authorize
|
98
115
|
|
99
116
|
new_doc = { :docs => @doc[:docs].clone }
|
100
117
|
|
101
|
-
new_doc[:docs][:resources] = @doc[:docs][:resources].
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
false
|
118
|
+
new_doc[:docs][:resources] = if @doc[:docs][:resources].kind_of?(Array)
|
119
|
+
@doc[:docs][:resources].select do |resource|
|
120
|
+
authorize_resource(resource)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
@doc[:docs][:resources].select do |_resource_name, resource|
|
124
|
+
authorize_resource(resource)
|
109
125
|
end
|
110
126
|
end
|
111
127
|
|
112
128
|
new_doc
|
113
129
|
end
|
114
130
|
|
131
|
+
def authorize_resource resource
|
132
|
+
if instance_exec(resource[:id], nil, resource, &Apipie.configuration.authorize)
|
133
|
+
resource[:methods] = resource[:methods].select do |m|
|
134
|
+
instance_exec(resource[:id], m[:name], m, &Apipie.configuration.authorize)
|
135
|
+
end
|
136
|
+
true
|
137
|
+
else
|
138
|
+
false
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
115
142
|
def get_format
|
116
143
|
[:resource, :method, :version].each do |par|
|
117
|
-
|
118
|
-
|
119
|
-
|
144
|
+
next unless params[par]
|
145
|
+
[:html, :json].each do |format|
|
146
|
+
extension = ".#{format}"
|
147
|
+
if params[par].include?(extension)
|
148
|
+
params[par] = params[par].sub(extension, '')
|
149
|
+
params[:format] = format
|
150
|
+
end
|
120
151
|
end
|
121
152
|
end
|
122
153
|
request.format = params[:format] if params[:format]
|
@@ -36,5 +36,26 @@
|
|
36
36
|
</tbody>
|
37
37
|
</table>
|
38
38
|
<% end %>
|
39
|
+
<% unless method[:returns].blank? %>
|
40
|
+
<%= heading(t('apipie.returns'), h_level) %>
|
41
|
+
<% method[:returns].each do |item| %>
|
42
|
+
<%= heading("#{t('apipie.code')}: #{item[:code]}", h_level + 1) %>
|
43
|
+
<% if item[:description] %>
|
44
|
+
<%= heading("#{t('apipie.description')}:", h_level + 2) %>
|
45
|
+
<p><%= item[:description] %></p>
|
46
|
+
<% end %>
|
47
|
+
<table class='table'>
|
48
|
+
<thead>
|
49
|
+
<tr>
|
50
|
+
<th><%= t('apipie.param_name') %></th>
|
51
|
+
<th><%= t('apipie.description') %></th>
|
52
|
+
</tr>
|
53
|
+
</thead>
|
54
|
+
<tbody>
|
55
|
+
<%= render(:partial => "params", :locals => {:params => item[:returns_object]}) %>
|
56
|
+
</tbody>
|
57
|
+
</table>
|
58
|
+
<% end %>
|
59
|
+
<% end %>
|
39
60
|
|
40
61
|
<%= render(:partial => "headers", :locals => {:headers => method[:headers], :h_level => h_level }) %>
|
@@ -21,8 +21,10 @@
|
|
21
21
|
<%- if param[:validator].present? %>
|
22
22
|
<li><%= Apipie.markup_to_html(param[:validator]).html_safe %></li>
|
23
23
|
<%- end %>
|
24
|
-
<%- param[:validations].
|
25
|
-
|
24
|
+
<%- if param[:validations].present? %>
|
25
|
+
<%- param[:validations].each do |item| %>
|
26
|
+
<li><%= item.html_safe %></li>
|
27
|
+
<%- end %>
|
26
28
|
<%- end %>
|
27
29
|
</ul>
|
28
30
|
<%- end %>
|
@@ -16,7 +16,11 @@
|
|
16
16
|
<h2>
|
17
17
|
<a href='<%= api[:doc_url] %><%= @doc[:link_extension] %>'>
|
18
18
|
<%= api[:name] %>
|
19
|
-
</a
|
19
|
+
</a>
|
20
|
+
<% if api[:deprecated] %>
|
21
|
+
<code>DEPRECATED</code>
|
22
|
+
<% end %>
|
23
|
+
<br>
|
20
24
|
<small><%= api[:short_description] %></small>
|
21
25
|
</h2>
|
22
26
|
<table class='table'>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title><%= t('apipie.api_documentation') %></title>
|
4
|
+
<title><%= t('apipie.api_documentation', :default => 'Api Documentation') %></title>
|
5
5
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
7
7
|
<%= Apipie.include_stylesheets %>
|
data/config/locales/en.yml
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
fr:
|
2
|
+
apipie:
|
3
|
+
resources: Ressources
|
4
|
+
resource: Ressource
|
5
|
+
description: Description
|
6
|
+
no_docs_found: Aucune documentation trouvée
|
7
|
+
no_docs_found_descr: Aucune documentation pour cette API
|
8
|
+
follow_instructions_html: Suivez ces %{href} sur la façon dont décrire vos controlleurs.
|
9
|
+
follow_instructions_href: instructions supplémentaires
|
10
|
+
oops: Oops!!
|
11
|
+
resource_not_found_html: Ressource %{resource} not found.
|
12
|
+
method_not_found_html: Méthode %{method} non trouvée pour la ressource %{resource}.
|
13
|
+
goto_homepage_html: Essayez de regarder %{href}
|
14
|
+
goto_homepage_href: "la page d'accueil %{app_name} API documentation homepage"
|
15
|
+
required: requis
|
16
|
+
optional: optionel
|
17
|
+
nil_allowed: nil autorisé
|
18
|
+
param_name: Nom du paramètre
|
19
|
+
params: Paramètres
|
20
|
+
examples: Exemples
|
21
|
+
metadata: Metadata
|
22
|
+
errors: Erreurs
|
23
|
+
error_code: Code
|
24
|
+
error_description: Description
|
25
|
+
error_metadata: Metadata
|
26
|
+
supported_formats: Formats supportés
|
27
|
+
enable_javascript_html: Activez JavaScript SVP pour afficher la %{comments_href}.
|
28
|
+
comments_powered_by_disqus: section commentaires par %{disqus}
|
29
|
+
api_documentation: documentation API
|
30
|
+
headers: Headers
|
31
|
+
header_name: Nom du header
|
@@ -0,0 +1,31 @@
|
|
1
|
+
it:
|
2
|
+
apipie:
|
3
|
+
resources: Risorse
|
4
|
+
resource: Risorsa
|
5
|
+
description: Descrizione
|
6
|
+
no_docs_found: Nessuna documentazione trovata
|
7
|
+
no_docs_found_descr: Non abbiamo trovato nessuna documentazione per la tua API.
|
8
|
+
follow_instructions_html: Leggi su %{href} come descrivere i tuoi controller.
|
9
|
+
follow_instructions_href: ulteriori istruzioni
|
10
|
+
oops: Ops!!
|
11
|
+
resource_not_found_html: Risorsa %{resource} non trovata.
|
12
|
+
method_not_found_html: Metodo %{method} non trovato per la risorsa %{resource}.
|
13
|
+
goto_homepage_html: Prova ad andare su %{href}
|
14
|
+
goto_homepage_href: "%{app_name} Homepage della documentazione API"
|
15
|
+
required: richiesto
|
16
|
+
optional: opzionale
|
17
|
+
nil_allowed: consentito nil
|
18
|
+
param_name: Nome parametro
|
19
|
+
params: Parametri
|
20
|
+
examples: Esempi
|
21
|
+
metadata: Metadata
|
22
|
+
errors: Errori
|
23
|
+
error_code: Codice
|
24
|
+
error_description: Descrizione
|
25
|
+
error_metadata: Metadata
|
26
|
+
supported_formats: Formati supportati
|
27
|
+
enable_javascript_html: Abilita i JavaScript per vedere %{comments_href}.
|
28
|
+
comments_powered_by_disqus: commenti forniti da %{disqus}
|
29
|
+
api_documentation: Documentazione API
|
30
|
+
headers: Header
|
31
|
+
header_name: Nome Header
|
@@ -0,0 +1,31 @@
|
|
1
|
+
ja:
|
2
|
+
apipie:
|
3
|
+
resources: "リソース"
|
4
|
+
resource: "リソース"
|
5
|
+
description: "記述"
|
6
|
+
no_docs_found: "ドキュメントが見つかりませんでした。"
|
7
|
+
no_docs_found_descr: "あなたのAPIにあう資料が見つかりませんでした。"
|
8
|
+
follow_instructions_html: "コントローラーをどう説明するのか%{href}を参考にしてください。"
|
9
|
+
follow_instructions_href: "具体的な説明"
|
10
|
+
oops: "おっと!"
|
11
|
+
resource_not_found_html: "リソース%{resource}が見つかりませんでした。"
|
12
|
+
method_not_found_html: "リソース%{resource}のためのメソッド%{method}が見つかりませんでした。 ."
|
13
|
+
goto_homepage_html: "%{href}へ移ります。"
|
14
|
+
goto_homepage_href: "%{app_name}APIドキュメントのホームページ"
|
15
|
+
required: "必須"
|
16
|
+
optional: "任意"
|
17
|
+
nil_allowed: "nil可"
|
18
|
+
param_name: "パラメーター名"
|
19
|
+
params: "パラメーター"
|
20
|
+
examples: "例"
|
21
|
+
metadata: "メタデータ"
|
22
|
+
errors: "エラー"
|
23
|
+
error_code: "エラーコード"
|
24
|
+
error_description: "エラー説明"
|
25
|
+
error_metadata: "エラーメタデータ"
|
26
|
+
supported_formats: "サポートフォーマット"
|
27
|
+
enable_javascript_html: "%{comments_href}のJavaScriptをオンにしてください。"
|
28
|
+
comments_powered_by_disqus: "%{disqus}によるコメント"
|
29
|
+
api_documentation: "APIドキュメント"
|
30
|
+
headers: "ヘッダー"
|
31
|
+
header_name: "ヘッダー名"
|
data/lib/apipie/apipie_module.rb
CHANGED
@@ -13,6 +13,22 @@ module Apipie
|
|
13
13
|
app.to_json(version, resource_name, method_name, lang)
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.to_swagger_json(version = nil, resource_name = nil, method_name = nil, lang = nil, clear_warnings=true)
|
17
|
+
version ||= Apipie.configuration.default_version
|
18
|
+
app.to_swagger_json(version, resource_name, method_name, lang, clear_warnings)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.json_schema_for_method_response(controller_name, method_name, return_code, allow_nulls)
|
22
|
+
# note: this does not support versions (only the default version is queried)!
|
23
|
+
version ||= Apipie.configuration.default_version
|
24
|
+
app.json_schema_for_method_response(version, controller_name, method_name, return_code, allow_nulls)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.json_schema_for_self_describing_class(cls, allow_nulls=true)
|
28
|
+
app.json_schema_for_self_describing_class(cls, allow_nulls)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
16
32
|
# all calls delegated to Apipie::Application instance
|
17
33
|
def self.method_missing(method, *args, &block)
|
18
34
|
app.respond_to?(method) ? app.send(method, *args, &block) : super
|
@@ -31,14 +47,16 @@ module Apipie
|
|
31
47
|
end
|
32
48
|
|
33
49
|
# get application description for given or default version
|
34
|
-
def self.app_info(version = nil)
|
35
|
-
if app_info_version_valid? version
|
36
|
-
|
50
|
+
def self.app_info(version = nil, lang = nil)
|
51
|
+
info = if app_info_version_valid? version
|
52
|
+
translate(self.configuration.app_info[version], lang)
|
37
53
|
elsif app_info_version_valid? Apipie.configuration.default_version
|
38
|
-
|
54
|
+
translate(self.configuration.app_info[Apipie.configuration.default_version], lang)
|
39
55
|
else
|
40
56
|
"Another API description"
|
41
57
|
end
|
58
|
+
|
59
|
+
Apipie.markup_to_html info
|
42
60
|
end
|
43
61
|
|
44
62
|
def self.api_base_url(version = nil)
|
data/lib/apipie/application.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'apipie/static_dispatcher'
|
2
2
|
require 'apipie/routes_formatter'
|
3
3
|
require 'yaml'
|
4
|
-
require 'digest/
|
4
|
+
require 'digest/sha1'
|
5
5
|
require 'json'
|
6
6
|
|
7
7
|
module Apipie
|
@@ -29,7 +29,7 @@ module Apipie
|
|
29
29
|
@controller_to_resource_id[controller] = resource_id
|
30
30
|
end
|
31
31
|
|
32
|
-
def rails_routes(route_set = nil)
|
32
|
+
def rails_routes(route_set = nil, base_url = "")
|
33
33
|
if route_set.nil? && @rails_routes
|
34
34
|
return @rails_routes
|
35
35
|
end
|
@@ -40,10 +40,13 @@ module Apipie
|
|
40
40
|
flatten_routes = []
|
41
41
|
|
42
42
|
route_set.routes.each do |route|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
# This is a hack to workaround a bug in apipie with Rails 4.2.5.1 or newer. See https://github.com/Apipie/apipie-rails/issues/415
|
44
|
+
route_app = Rails::VERSION::STRING.to_f >= 4.2 ? route.app.app : route.app
|
45
|
+
if route_app.respond_to?(:routes) && route_app.routes.is_a?(ActionDispatch::Routing::RouteSet)
|
46
|
+
# recursively go though the mounted engines
|
47
|
+
flatten_routes.concat(rails_routes(route_app.routes, File.join(base_url, route.path.spec.to_s)))
|
46
48
|
else
|
49
|
+
route.base_url = base_url
|
47
50
|
flatten_routes << route
|
48
51
|
end
|
49
52
|
end
|
@@ -54,14 +57,10 @@ module Apipie
|
|
54
57
|
# the app might be nested when using contraints, namespaces etc.
|
55
58
|
# this method does in depth search for the route controller
|
56
59
|
def route_app_controller(app, route, visited_apps = [])
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
elsif app.respond_to?(:app) && !visited_apps.include?(app.app)
|
61
|
-
return route_app_controller(app.app, route, visited_apps)
|
60
|
+
if route.defaults[:controller]
|
61
|
+
controller_name = "#{route.defaults[:controller]}_controller".camelize
|
62
|
+
controller_name.safe_constantize
|
62
63
|
end
|
63
|
-
rescue ActionController::RoutingError
|
64
|
-
# some errors in the routes will not stop us here: just ignoring
|
65
64
|
end
|
66
65
|
|
67
66
|
def routes_for_action(controller, method, args)
|
@@ -126,17 +125,17 @@ module Apipie
|
|
126
125
|
# resource_description? It's used to derivate the default value of
|
127
126
|
# versions for methods.
|
128
127
|
def controller_versions(controller)
|
129
|
-
ret = @controller_versions[controller]
|
128
|
+
ret = @controller_versions[controller.to_s]
|
130
129
|
return ret unless ret.empty?
|
131
130
|
if controller == ActionController::Base || controller.nil?
|
132
131
|
return [Apipie.configuration.default_version]
|
133
132
|
else
|
134
|
-
return controller_versions(controller.superclass)
|
133
|
+
return controller_versions(controller.to_s.constantize.superclass)
|
135
134
|
end
|
136
135
|
end
|
137
136
|
|
138
137
|
def set_controller_versions(controller, versions)
|
139
|
-
@controller_versions[controller] = versions
|
138
|
+
@controller_versions[controller.to_s] = versions
|
140
139
|
end
|
141
140
|
|
142
141
|
def add_param_group(controller, name, &block)
|
@@ -210,7 +209,7 @@ module Apipie
|
|
210
209
|
return nil
|
211
210
|
end
|
212
211
|
resource_description = get_resource_description(resource_name)
|
213
|
-
if resource_description && resource_description.controller == resource
|
212
|
+
if resource_description && resource_description.controller.to_s == resource.to_s
|
214
213
|
return resource_description
|
215
214
|
end
|
216
215
|
end
|
@@ -241,12 +240,13 @@ module Apipie
|
|
241
240
|
|
242
241
|
# initialize variables for gathering dsl data
|
243
242
|
def init_env
|
244
|
-
@resource_descriptions
|
245
|
-
@controller_to_resource_id
|
246
|
-
@param_groups
|
243
|
+
@resource_descriptions ||= HashWithIndifferentAccess.new { |h, version| h[version] = {} }
|
244
|
+
@controller_to_resource_id ||= {}
|
245
|
+
@param_groups ||= {}
|
246
|
+
@swagger_generator = Apipie::SwaggerGenerator.new(self)
|
247
247
|
|
248
248
|
# what versions does the controller belong in (specified by resource_description)?
|
249
|
-
@controller_versions
|
249
|
+
@controller_versions ||= Hash.new { |h, controller| h[controller.to_s] = [] }
|
250
250
|
end
|
251
251
|
|
252
252
|
def recorded_examples
|
@@ -258,6 +258,34 @@ module Apipie
|
|
258
258
|
@recorded_examples = nil
|
259
259
|
end
|
260
260
|
|
261
|
+
def json_schema_for_method_response(version, controller_name, method_name, return_code, allow_nulls)
|
262
|
+
method = @resource_descriptions[version][controller_name].method_description(method_name)
|
263
|
+
raise NoDocumentedMethod.new(controller_name, method_name) if method.nil?
|
264
|
+
@swagger_generator.json_schema_for_method_response(method, return_code, allow_nulls)
|
265
|
+
end
|
266
|
+
|
267
|
+
def json_schema_for_self_describing_class(cls, allow_nulls)
|
268
|
+
@swagger_generator.json_schema_for_self_describing_class(cls, allow_nulls)
|
269
|
+
end
|
270
|
+
|
271
|
+
def to_swagger_json(version, resource_name, method_name, lang, clear_warnings=false)
|
272
|
+
return unless valid_search_args?(version, resource_name, method_name)
|
273
|
+
|
274
|
+
# if resource_name is blank, take just resources which have some methods because
|
275
|
+
# we dont want to show eg ApplicationController as resource
|
276
|
+
# otherwise, take only the specified resource
|
277
|
+
_resources = resource_descriptions[version].inject({}) do |result, (k,v)|
|
278
|
+
if resource_name.blank?
|
279
|
+
result[k] = v unless v._methods.blank?
|
280
|
+
else
|
281
|
+
result[k] = v if k == resource_name
|
282
|
+
end
|
283
|
+
result
|
284
|
+
end
|
285
|
+
|
286
|
+
@swagger_generator.generate_from_resources(version,_resources, method_name, lang, clear_warnings)
|
287
|
+
end
|
288
|
+
|
261
289
|
def to_json(version, resource_name, method_name, lang)
|
262
290
|
|
263
291
|
return unless valid_search_args?(version, resource_name, method_name)
|
@@ -278,7 +306,7 @@ module Apipie
|
|
278
306
|
{
|
279
307
|
:docs => {
|
280
308
|
:name => Apipie.configuration.app_name,
|
281
|
-
:info =>
|
309
|
+
:info => Apipie.app_info(version, lang),
|
282
310
|
:copyright => Apipie.configuration.copyright,
|
283
311
|
:doc_url => Apipie.full_url(url_args),
|
284
312
|
:api_url => Apipie.api_base_url(version),
|
@@ -326,7 +354,7 @@ module Apipie
|
|
326
354
|
all.update(version => Apipie.to_json(version))
|
327
355
|
end
|
328
356
|
end
|
329
|
-
Digest::
|
357
|
+
Digest::SHA1.hexdigest(JSON.dump(all_docs))
|
330
358
|
end
|
331
359
|
|
332
360
|
def checksum
|
@@ -390,9 +418,9 @@ module Apipie
|
|
390
418
|
end
|
391
419
|
|
392
420
|
def version_prefix(klass)
|
393
|
-
version = controller_versions(klass).first
|
421
|
+
version = controller_versions(klass.to_s).first
|
394
422
|
base_url = get_base_url(version)
|
395
|
-
return "/" if base_url.
|
423
|
+
return "/" if base_url.blank?
|
396
424
|
base_url[1..-1] + "/"
|
397
425
|
end
|
398
426
|
|
@@ -409,8 +437,7 @@ module Apipie
|
|
409
437
|
end
|
410
438
|
|
411
439
|
def load_controller_from_file(controller_file)
|
412
|
-
|
413
|
-
controller_class_name.constantize
|
440
|
+
require_dependency controller_file
|
414
441
|
end
|
415
442
|
|
416
443
|
def ignored?(controller, method = nil)
|
@@ -429,10 +456,10 @@ module Apipie
|
|
429
456
|
# as this would break loading of the controllers.
|
430
457
|
def rails_mark_classes_for_reload
|
431
458
|
unless Rails.application.config.cache_classes
|
432
|
-
ActionDispatch::Reloader.cleanup!
|
459
|
+
Rails::VERSION::MAJOR == 4 ? ActionDispatch::Reloader.cleanup! : Rails.application.reloader.reload!
|
433
460
|
init_env
|
434
461
|
reload_examples
|
435
|
-
ActionDispatch::Reloader.prepare!
|
462
|
+
Rails::VERSION::MAJOR == 4 ? ActionDispatch::Reloader.prepare! : Rails.application.reloader.prepare!
|
436
463
|
end
|
437
464
|
end
|
438
465
|
|
data/lib/apipie/configuration.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
module Apipie
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
attr_accessor :app_name, :app_info, :copyright, :
|
4
|
+
attr_accessor :app_name, :app_info, :copyright, :compress_examples,
|
5
|
+
:markup, :disqus_shortname,
|
5
6
|
:api_base_url, :doc_base_url, :required_by_default, :layout,
|
6
7
|
:default_version, :debug, :version_in_url, :namespaced_resources,
|
7
8
|
:validate, :validate_value, :validate_presence, :validate_key, :authenticate, :doc_path,
|
8
9
|
:show_all_examples, :process_params, :update_checksum, :checksum_path,
|
9
10
|
:link_extension, :record, :languages, :translate, :locale, :default_locale,
|
10
|
-
:persist_show_in_doc, :authorize
|
11
|
+
:persist_show_in_doc, :authorize,
|
12
|
+
:swagger_include_warning_tags, :swagger_content_type_input, :swagger_json_input_uses_refs,
|
13
|
+
:swagger_suppress_warnings, :swagger_api_host, :swagger_generate_x_computed_id_field,
|
14
|
+
:swagger_allow_additional_properties_in_response, :swagger_responses_use_refs
|
11
15
|
|
12
16
|
alias_method :validate?, :validate
|
13
17
|
alias_method :required_by_default?, :required_by_default
|
14
18
|
alias_method :namespaced_resources?, :namespaced_resources
|
19
|
+
alias_method :swagger_include_warning_tags?, :swagger_include_warning_tags
|
20
|
+
alias_method :swagger_json_input_uses_refs?, :swagger_json_input_uses_refs
|
21
|
+
alias_method :swagger_responses_use_refs?, :swagger_responses_use_refs
|
22
|
+
alias_method :swagger_generate_x_computed_id_field?, :swagger_generate_x_computed_id_field
|
15
23
|
|
16
24
|
# matcher to be used in Dir.glob to find controllers to be reloaded e.g.
|
17
25
|
#
|
@@ -108,7 +116,7 @@ module Apipie
|
|
108
116
|
# the line above the docs.
|
109
117
|
attr_writer :generated_doc_disclaimer
|
110
118
|
def generated_doc_disclaimer
|
111
|
-
@generated_doc_disclaimer ||= "# DOC GENERATED AUTOMATICALLY: REMOVE THIS LINE TO PREVENT
|
119
|
+
@generated_doc_disclaimer ||= "# DOC GENERATED AUTOMATICALLY: REMOVE THIS LINE TO PREVENT REGENERATING NEXT TIME"
|
112
120
|
end
|
113
121
|
|
114
122
|
def use_disqus?
|
@@ -165,6 +173,14 @@ module Apipie
|
|
165
173
|
@translate = lambda { |str, locale| str }
|
166
174
|
@persist_show_in_doc = false
|
167
175
|
@routes_formatter = RoutesFormatter.new
|
176
|
+
@swagger_content_type_input = :form_data # this can be :json or :form_data
|
177
|
+
@swagger_json_input_uses_refs = false
|
178
|
+
@swagger_include_warning_tags = false
|
179
|
+
@swagger_suppress_warnings = false #[105,100,102]
|
180
|
+
@swagger_api_host = "localhost:3000"
|
181
|
+
@swagger_generate_x_computed_id_field = false
|
182
|
+
@swagger_allow_additional_properties_in_response = false
|
183
|
+
@swagger_responses_use_refs = true
|
168
184
|
end
|
169
185
|
end
|
170
186
|
end
|