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
@@ -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: "ヘッダー名"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
ko:
|
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: Param 이름
|
19
|
+
params: Params
|
20
|
+
examples: 예시
|
21
|
+
metadata: Metadata
|
22
|
+
errors: 에러
|
23
|
+
error_code: 코드
|
24
|
+
error_description: 설명
|
25
|
+
error_metadata: Metadata
|
26
|
+
supported_formats: 지원 포멧
|
27
|
+
enable_javascript_html: "%{comments_href}를 보기 위해서 JavaScript를 허용해주세요."
|
28
|
+
comments_powered_by_disqus: comments powered by %{disqus}
|
29
|
+
api_documentation: API 문서
|
30
|
+
headers: 헤더
|
31
|
+
header_name: 헤더 이름
|
data/config/locales/pt-BR.yml
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '..'
|
4
|
+
|
5
|
+
gem 'actionpack', '~> 5.0.0'
|
6
|
+
gem 'activesupport', '~> 5.0.0'
|
7
|
+
gem 'mime-types', '~> 2.99.3'
|
8
|
+
gem 'rails-controller-testing'
|
9
|
+
|
10
|
+
gem 'test_engine', path: '../spec/dummy/components/test_engine', group: :test
|
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '..'
|
4
|
+
|
5
|
+
gem 'actionpack', '~> 5.1.0'
|
6
|
+
gem 'activesupport', '~> 5.1.0'
|
7
|
+
gem 'mime-types', '~> 2.99.3'
|
8
|
+
gem 'rails-controller-testing'
|
9
|
+
|
10
|
+
gem 'test_engine', path: '../spec/dummy/components/test_engine', group: :test
|
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '..'
|
4
|
+
|
5
|
+
gem 'actionpack', '~> 5.2.6'
|
6
|
+
gem 'activesupport', '~> 5.2.6'
|
7
|
+
gem 'mime-types', '~> 2.99.3'
|
8
|
+
gem 'rails-controller-testing'
|
9
|
+
|
10
|
+
gem 'test_engine', path: '../spec/dummy/components/test_engine', group: :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '..'
|
4
|
+
|
5
|
+
gem 'actionpack', '~> 6.0.4'
|
6
|
+
gem 'activesupport', '~> 6.0.4'
|
7
|
+
gem 'mime-types', '~> 3.0'
|
8
|
+
gem 'rails-controller-testing'
|
9
|
+
gem 'rspec-rails', '~> 5.0'
|
10
|
+
|
11
|
+
# net-smtp not included by default in Ruby 3.1
|
12
|
+
# Will be fixed by https://github.com/mikel/mail/pull/1439
|
13
|
+
if Gem.ruby_version >= Gem::Version.new("3.1.0")
|
14
|
+
gem 'net-smtp', require: false
|
15
|
+
end
|
16
|
+
|
17
|
+
gem 'test_engine', path: '../spec/dummy/components/test_engine', group: :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '..'
|
4
|
+
|
5
|
+
gem 'actionpack', '~> 6.1.5'
|
6
|
+
gem 'activesupport', '~> 6.1.5'
|
7
|
+
gem 'mime-types', '~> 3.0'
|
8
|
+
gem 'rails-controller-testing'
|
9
|
+
gem 'rspec-rails', '~> 5.0'
|
10
|
+
|
11
|
+
# net-smtp not included by default in Ruby 3.1
|
12
|
+
# Will be fixed by https://github.com/mikel/mail/pull/1439
|
13
|
+
if Gem.ruby_version >= Gem::Version.new("3.1.0")
|
14
|
+
gem 'net-smtp', require: false
|
15
|
+
end
|
16
|
+
|
17
|
+
gem 'test_engine', path: '../spec/dummy/components/test_engine', group: :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '..'
|
4
|
+
|
5
|
+
gem 'actionpack', '~> 7.0.2'
|
6
|
+
gem 'activesupport', '~> 7.0.2'
|
7
|
+
gem 'mime-types', '~> 3.0'
|
8
|
+
gem 'rails-controller-testing'
|
9
|
+
gem 'rspec-rails', '~> 5.0'
|
10
|
+
|
11
|
+
# net-smtp not included by default in Ruby 3.1
|
12
|
+
# Will be fixed by https://github.com/mikel/mail/pull/1439
|
13
|
+
if Gem.ruby_version >= Gem::Version.new("3.1.0")
|
14
|
+
gem 'net-smtp', require: false
|
15
|
+
end
|
16
|
+
|
17
|
+
gem 'test_engine', path: '../spec/dummy/components/test_engine', group: :test
|
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,15 @@ module Apipie
|
|
40
40
|
flatten_routes = []
|
41
41
|
|
42
42
|
route_set.routes.each do |route|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
# route is_a ActionDispatch::Journey::Route
|
44
|
+
# route.app is_a ActionDispatch::Routing::Mapper::Constraints
|
45
|
+
# route.app.app is_a TestEngine::Engine
|
46
|
+
route_app = route.app.app
|
47
|
+
if route_app.respond_to?(:routes) && route_app.routes.is_a?(ActionDispatch::Routing::RouteSet)
|
48
|
+
# recursively go though the mounted engines
|
49
|
+
flatten_routes.concat(rails_routes(route_app.routes, File.join(base_url, route.path.spec.to_s)))
|
46
50
|
else
|
51
|
+
route.base_url = base_url
|
47
52
|
flatten_routes << route
|
48
53
|
end
|
49
54
|
end
|
@@ -54,14 +59,10 @@ module Apipie
|
|
54
59
|
# the app might be nested when using contraints, namespaces etc.
|
55
60
|
# this method does in depth search for the route controller
|
56
61
|
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)
|
62
|
+
if route.defaults[:controller]
|
63
|
+
controller_name = "#{route.defaults[:controller]}_controller".camelize
|
64
|
+
controller_name.safe_constantize
|
62
65
|
end
|
63
|
-
rescue ActionController::RoutingError
|
64
|
-
# some errors in the routes will not stop us here: just ignoring
|
65
66
|
end
|
66
67
|
|
67
68
|
def routes_for_action(controller, method, args)
|
@@ -126,17 +127,17 @@ module Apipie
|
|
126
127
|
# resource_description? It's used to derivate the default value of
|
127
128
|
# versions for methods.
|
128
129
|
def controller_versions(controller)
|
129
|
-
ret = @controller_versions[controller]
|
130
|
+
ret = @controller_versions[controller.to_s]
|
130
131
|
return ret unless ret.empty?
|
131
132
|
if controller == ActionController::Base || controller.nil?
|
132
133
|
return [Apipie.configuration.default_version]
|
133
134
|
else
|
134
|
-
return controller_versions(controller.superclass)
|
135
|
+
return controller_versions(controller.to_s.constantize.superclass)
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
138
139
|
def set_controller_versions(controller, versions)
|
139
|
-
@controller_versions[controller] = versions
|
140
|
+
@controller_versions[controller.to_s] = versions
|
140
141
|
end
|
141
142
|
|
142
143
|
def add_param_group(controller, name, &block)
|
@@ -210,7 +211,7 @@ module Apipie
|
|
210
211
|
return nil
|
211
212
|
end
|
212
213
|
resource_description = get_resource_description(resource_name)
|
213
|
-
if resource_description && resource_description.controller == resource
|
214
|
+
if resource_description && resource_description.controller.to_s == resource.to_s
|
214
215
|
return resource_description
|
215
216
|
end
|
216
217
|
end
|
@@ -244,9 +245,10 @@ module Apipie
|
|
244
245
|
@resource_descriptions = HashWithIndifferentAccess.new { |h, version| h[version] = {} }
|
245
246
|
@controller_to_resource_id = {}
|
246
247
|
@param_groups = {}
|
248
|
+
@swagger_generator = Apipie::SwaggerGenerator.new(self)
|
247
249
|
|
248
250
|
# what versions does the controller belong in (specified by resource_description)?
|
249
|
-
@controller_versions = Hash.new { |h, controller| h[controller] = [] }
|
251
|
+
@controller_versions = Hash.new { |h, controller| h[controller.to_s] = [] }
|
250
252
|
end
|
251
253
|
|
252
254
|
def recorded_examples
|
@@ -258,6 +260,34 @@ module Apipie
|
|
258
260
|
@recorded_examples = nil
|
259
261
|
end
|
260
262
|
|
263
|
+
def json_schema_for_method_response(version, controller_name, method_name, return_code, allow_nulls)
|
264
|
+
method = @resource_descriptions[version][controller_name].method_description(method_name)
|
265
|
+
raise NoDocumentedMethod.new(controller_name, method_name) if method.nil?
|
266
|
+
@swagger_generator.json_schema_for_method_response(method, return_code, allow_nulls)
|
267
|
+
end
|
268
|
+
|
269
|
+
def json_schema_for_self_describing_class(cls, allow_nulls)
|
270
|
+
@swagger_generator.json_schema_for_self_describing_class(cls, allow_nulls)
|
271
|
+
end
|
272
|
+
|
273
|
+
def to_swagger_json(version, resource_name, method_name, lang, clear_warnings=false)
|
274
|
+
return unless valid_search_args?(version, resource_name, method_name)
|
275
|
+
|
276
|
+
# if resource_name is blank, take just resources which have some methods because
|
277
|
+
# we dont want to show eg ApplicationController as resource
|
278
|
+
# otherwise, take only the specified resource
|
279
|
+
_resources = resource_descriptions[version].inject({}) do |result, (k,v)|
|
280
|
+
if resource_name.blank?
|
281
|
+
result[k] = v unless v._methods.blank?
|
282
|
+
else
|
283
|
+
result[k] = v if k == resource_name
|
284
|
+
end
|
285
|
+
result
|
286
|
+
end
|
287
|
+
|
288
|
+
@swagger_generator.generate_from_resources(version,_resources, method_name, lang, clear_warnings)
|
289
|
+
end
|
290
|
+
|
261
291
|
def to_json(version, resource_name, method_name, lang)
|
262
292
|
|
263
293
|
return unless valid_search_args?(version, resource_name, method_name)
|
@@ -278,7 +308,7 @@ module Apipie
|
|
278
308
|
{
|
279
309
|
:docs => {
|
280
310
|
:name => Apipie.configuration.app_name,
|
281
|
-
:info =>
|
311
|
+
:info => Apipie.app_info(version, lang),
|
282
312
|
:copyright => Apipie.configuration.copyright,
|
283
313
|
:doc_url => Apipie.full_url(url_args),
|
284
314
|
:api_url => Apipie.api_base_url(version),
|
@@ -326,7 +356,7 @@ module Apipie
|
|
326
356
|
all.update(version => Apipie.to_json(version))
|
327
357
|
end
|
328
358
|
end
|
329
|
-
Digest::
|
359
|
+
Digest::SHA1.hexdigest(JSON.dump(all_docs))
|
330
360
|
end
|
331
361
|
|
332
362
|
def checksum
|
@@ -390,9 +420,9 @@ module Apipie
|
|
390
420
|
end
|
391
421
|
|
392
422
|
def version_prefix(klass)
|
393
|
-
version = controller_versions(klass).first
|
423
|
+
version = controller_versions(klass.to_s).first
|
394
424
|
base_url = get_base_url(version)
|
395
|
-
return "/" if base_url.
|
425
|
+
return "/" if base_url.blank?
|
396
426
|
base_url[1..-1] + "/"
|
397
427
|
end
|
398
428
|
|
@@ -409,8 +439,7 @@ module Apipie
|
|
409
439
|
end
|
410
440
|
|
411
441
|
def load_controller_from_file(controller_file)
|
412
|
-
|
413
|
-
controller_class_name.constantize
|
442
|
+
require_dependency controller_file
|
414
443
|
end
|
415
444
|
|
416
445
|
def ignored?(controller, method = nil)
|
@@ -429,10 +458,10 @@ module Apipie
|
|
429
458
|
# as this would break loading of the controllers.
|
430
459
|
def rails_mark_classes_for_reload
|
431
460
|
unless Rails.application.config.cache_classes
|
432
|
-
|
461
|
+
Rails.application.reloader.reload!
|
433
462
|
init_env
|
434
463
|
reload_examples
|
435
|
-
|
464
|
+
Rails.application.reloader.prepare!
|
436
465
|
end
|
437
466
|
end
|
438
467
|
|
data/lib/apipie/configuration.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
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
|
-
:validate, :validate_value, :validate_presence, :validate_key, :authenticate, :doc_path,
|
8
|
+
:validate, :validate_value, :validate_presence, :validate_key, :action_on_non_validated_keys, :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, :ignore_allow_blank_false,
|
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,
|
15
|
+
:swagger_schemes, :swagger_security_definitions, :swagger_global_security
|
11
16
|
|
12
17
|
alias_method :validate?, :validate
|
13
18
|
alias_method :required_by_default?, :required_by_default
|
14
19
|
alias_method :namespaced_resources?, :namespaced_resources
|
20
|
+
alias_method :swagger_include_warning_tags?, :swagger_include_warning_tags
|
21
|
+
alias_method :swagger_json_input_uses_refs?, :swagger_json_input_uses_refs
|
22
|
+
alias_method :swagger_responses_use_refs?, :swagger_responses_use_refs
|
23
|
+
alias_method :swagger_generate_x_computed_id_field?, :swagger_generate_x_computed_id_field
|
15
24
|
|
16
25
|
# matcher to be used in Dir.glob to find controllers to be reloaded e.g.
|
17
26
|
#
|
@@ -108,7 +117,7 @@ module Apipie
|
|
108
117
|
# the line above the docs.
|
109
118
|
attr_writer :generated_doc_disclaimer
|
110
119
|
def generated_doc_disclaimer
|
111
|
-
@generated_doc_disclaimer ||= "# DOC GENERATED AUTOMATICALLY: REMOVE THIS LINE TO PREVENT
|
120
|
+
@generated_doc_disclaimer ||= "# DOC GENERATED AUTOMATICALLY: REMOVE THIS LINE TO PREVENT REGENERATING NEXT TIME"
|
112
121
|
end
|
113
122
|
|
114
123
|
def use_disqus?
|
@@ -144,6 +153,7 @@ module Apipie
|
|
144
153
|
@validate_value = true
|
145
154
|
@validate_presence = true
|
146
155
|
@validate_key = false
|
156
|
+
@action_on_non_validated_keys = :raise
|
147
157
|
@required_by_default = false
|
148
158
|
@api_base_url = HashWithIndifferentAccess.new
|
149
159
|
@doc_base_url = "/apipie"
|
@@ -151,6 +161,7 @@ module Apipie
|
|
151
161
|
@disqus_shortname = nil
|
152
162
|
@default_version = "1.0"
|
153
163
|
@debug = false
|
164
|
+
@ignore_allow_blank_false = false
|
154
165
|
@version_in_url = true
|
155
166
|
@namespaced_resources = false
|
156
167
|
@doc_path = "doc"
|
@@ -165,6 +176,17 @@ module Apipie
|
|
165
176
|
@translate = lambda { |str, locale| str }
|
166
177
|
@persist_show_in_doc = false
|
167
178
|
@routes_formatter = RoutesFormatter.new
|
179
|
+
@swagger_content_type_input = :form_data # this can be :json or :form_data
|
180
|
+
@swagger_json_input_uses_refs = false
|
181
|
+
@swagger_include_warning_tags = false
|
182
|
+
@swagger_suppress_warnings = false #[105,100,102]
|
183
|
+
@swagger_api_host = "localhost:3000"
|
184
|
+
@swagger_generate_x_computed_id_field = false
|
185
|
+
@swagger_allow_additional_properties_in_response = false
|
186
|
+
@swagger_responses_use_refs = true
|
187
|
+
@swagger_schemes = [:https]
|
188
|
+
@swagger_security_definitions = {}
|
189
|
+
@swagger_global_security = []
|
168
190
|
end
|
169
191
|
end
|
170
192
|
end
|