apipie-rails 0.3.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/CHANGELOG.md +33 -0
- data/Gemfile +3 -3
- data/Gemfile.rails41 +1 -0
- data/Gemfile.rails42 +7 -1
- data/Gemfile.rails50 +7 -0
- data/Gemfile.rails51 +7 -0
- data/README.rst +12 -12
- data/apipie-rails.gemspec +2 -3
- data/app/controllers/apipie/apipies_controller.rb +10 -6
- data/config/locales/it.yml +31 -0
- data/config/locales/ja.yml +31 -0
- data/lib/apipie/apipie_module.rb +6 -4
- data/lib/apipie/application.rb +6 -11
- data/lib/apipie/dsl_definition.rb +2 -2
- data/lib/apipie/extractor/recorder.rb +5 -9
- data/lib/apipie/extractor/writer.rb +18 -13
- data/lib/apipie/extractor.rb +2 -2
- data/lib/apipie/param_description.rb +16 -1
- data/lib/apipie/validator.rb +3 -3
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +1 -0
- data/lib/tasks/apipie.rake +5 -1
- data/spec/controllers/apipies_controller_spec.rb +12 -12
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/users_controller_spec.rb +93 -74
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/app/controllers/concerns/sample_controller.rb +5 -5
- data/spec/dummy/app/controllers/users_controller.rb +11 -10
- 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 +1 -1
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/spec_helper.rb +27 -0
- metadata +10 -22
- data/Gemfile.rails32 +0 -6
- data/Gemfile.rails40 +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f1836e9d470aab5a5fd2592c5bd020670d7644f
|
4
|
+
data.tar.gz: 915e53c2aed478f60375817066e059dc0b955e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc7d88e8c09ada1e11c86ce87e2535876c9c553532eb4ef07b66b862583308352e80ca47c2e656a43e85a9764725cea834c46bc20e5eae6321364509b5f9e21f
|
7
|
+
data.tar.gz: c6580080b5dc965477997baba13787948d2c749657156a02ab771a2890adab3195f04791fa736f832cdc4c1c20b6f4157edddace1441e7e453a87fe23c2126d2
|
data/.travis.yml
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
- 1.9.3
|
5
4
|
- 2.0.0
|
6
5
|
- 2.1.7
|
7
6
|
- 2.2.3
|
7
|
+
- 2.3.3
|
8
8
|
gemfile:
|
9
|
-
- Gemfile.rails32
|
10
|
-
- Gemfile.rails40
|
11
9
|
- Gemfile.rails41
|
12
10
|
- Gemfile.rails42
|
11
|
+
- Gemfile.rails50 # Min ruby 2.2.2
|
12
|
+
- Gemfile.rails51 # Min ruby 2.2.2
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
- rvm: 2.0.0
|
16
|
+
gemfile: Gemfile.rails50
|
17
|
+
- rvm: 2.0.0
|
18
|
+
gemfile: Gemfile.rails51
|
19
|
+
- rvm: 2.1.7
|
20
|
+
gemfile: Gemfile.rails50
|
21
|
+
- rvm: 2.1.7
|
22
|
+
gemfile: Gemfile.rails51
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,39 @@
|
|
2
2
|
Changelog
|
3
3
|
===========
|
4
4
|
|
5
|
+
v0.5.0
|
6
|
+
------
|
7
|
+
|
8
|
+
- Fix Rails 5.1 deprecations [\#530](https://github.com/Apipie/apipie-rails/pull/530) ([@Onumis](https://github.com/Onumis) [@sedx](https://github.com/sedx))
|
9
|
+
- **This release is no longer compatible with Ruby 1.9.x**
|
10
|
+
- Do not mutate strings passed as config options, fixes \#461 [\#537](https://github.com/Apipie/apipie-rails/pull/537) ([samphilipd](https://github.com/samphilipd))
|
11
|
+
- Added recursion for documentation, fixed bug in examples with paperclip [\#531](https://github.com/Apipie/apipie-rails/pull/531) ([blddmnd](https://github.com/blddmnd))
|
12
|
+
- Added locales/ja.yml for Japanese [\#529](https://github.com/Apipie/apipie-rails/pull/529) ([kikuchi0808](https://github.com/kikuchi0808))
|
13
|
+
|
14
|
+
|
15
|
+
v0.4.0
|
16
|
+
------
|
17
|
+
|
18
|
+
- Rails 5 compatibility [\#527](https://github.com/Apipie/apipie-rails/pull/527) ([iNecas](https://github.com/iNecas)) [\#420](https://github.com/Apipie/apipie-rails/pull/420) ([buren](https://github.com/buren)) [\#473](https://github.com/Apipie/apipie-rails/pull/473)([domcleal](https://github.com/domcleal))
|
19
|
+
- **This release is no longer compatible with Rails 3.x**
|
20
|
+
- Include delete request parmeters in generated documentation [\#524](https://github.com/Apipie/apipie-rails/pull/524) ([johnnaegle](https://github.com/johnnaegle))
|
21
|
+
- Allow a blank, not just nil, base\_url. [\#521](https://github.com/Apipie/apipie-rails/pull/521) ([johnnaegle](https://github.com/johnnaegle))
|
22
|
+
- Adds allow\_blank option [\#508](https://github.com/Apipie/apipie-rails/pull/508) ([MrLeebo](https://github.com/MrLeebo))
|
23
|
+
- Boolean Validator uses \<code\> instead of ' [\#502](https://github.com/Apipie/apipie-rails/pull/502) ([berfarah](https://github.com/berfarah))
|
24
|
+
- Fix type validator message [\#501](https://github.com/Apipie/apipie-rails/pull/501) ([cindygu-itglue](https://github.com/cindygu-itglue))
|
25
|
+
- Add IT locale [\#496](https://github.com/Apipie/apipie-rails/pull/496) ([alepore](https://github.com/alepore))
|
26
|
+
- Fix small typo on dsl\_definition data init [\#494](https://github.com/Apipie/apipie-rails/pull/494) ([begault](https://github.com/begault))
|
27
|
+
- Localize app info message [\#491](https://github.com/Apipie/apipie-rails/pull/491) ([belousovAV](https://github.com/belousovAV))
|
28
|
+
- Fix travis build [\#489](https://github.com/Apipie/apipie-rails/pull/489) ([mtparet](https://github.com/mtparet))
|
29
|
+
- Handle blank data when parsing a example's response [\#453](https://github.com/Apipie/apipie-rails/pull/453) ([stbenjam](https://github.com/stbenjam))
|
30
|
+
- Allow layouts to be overridable. Fixes a regression introduced in \#425. [\#447](https://github.com/Apipie/apipie-rails/pull/447) ([nilsojes](https://github.com/nilsojes))
|
31
|
+
|
32
|
+
v0.3.7
|
33
|
+
------
|
34
|
+
|
35
|
+
- Handle blank data when parsing a example's response [\#453](https://github.com/Apipie/apipie-rails/pull/453) ([stbenjam](https://github.com/stbenjam))
|
36
|
+
- Allow layouts to be overridable. Fixes a regression introduced in \#425. [\#447](https://github.com/Apipie/apipie-rails/pull/447) ([nilseriksson](https://github.com/nilseriksson))
|
37
|
+
|
5
38
|
v0.3.6
|
6
39
|
------
|
7
40
|
|
data/Gemfile
CHANGED
@@ -2,6 +2,6 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
gem 'rails', '~> 5.0'
|
6
|
+
gem 'mime-types', '~> 2.99.3'
|
7
|
+
gem 'rails-controller-testing'
|
data/Gemfile.rails41
CHANGED
data/Gemfile.rails42
CHANGED
data/Gemfile.rails50
ADDED
data/Gemfile.rails51
ADDED
data/README.rst
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
API Documentation Tool
|
3
3
|
========================
|
4
4
|
|
5
|
-
.. image:: https://travis-ci.org/Apipie/apipie-rails.
|
5
|
+
.. image:: https://travis-ci.org/Apipie/apipie-rails.svg?branch=master
|
6
6
|
:target: https://travis-ci.org/Apipie/apipie-rails
|
7
|
-
.. image:: https://codeclimate.com/github/Apipie/apipie-rails.
|
7
|
+
.. image:: https://codeclimate.com/github/Apipie/apipie-rails.svg
|
8
8
|
:target: https://codeclimate.com/github/Apipie/apipie-rails
|
9
9
|
.. image:: https://badges.gitter.im/Apipie/apipie-rails.svg
|
10
10
|
:alt: Join the chat at https://gitter.im/Apipie/apipie-rails
|
@@ -288,6 +288,9 @@ required
|
|
288
288
|
allow_nil
|
289
289
|
Setting this to true means that ``nil`` can be passed.
|
290
290
|
|
291
|
+
allow_blank
|
292
|
+
Like ``allow_nil``, but for blank values. ``false``, ``""``, ``' '``, ``nil``, ``[]``, and ``{}`` are all blank.
|
293
|
+
|
291
294
|
as
|
292
295
|
Used by the processing functionality to change the name of a key params.
|
293
296
|
|
@@ -528,7 +531,7 @@ default_version
|
|
528
531
|
validate
|
529
532
|
Parameters validation is turned off when set to false. When set to
|
530
533
|
``:explicitly``, you must invoke parameter validation yourself by calling
|
531
|
-
controller method ``apipie_validations`` (typically in a
|
534
|
+
controller method ``apipie_validations`` (typically in a before_action).
|
532
535
|
When set to ``:implicitly`` (or just true), your controller's action
|
533
536
|
methods are wrapped with generated methods which call ``apipie_validations``,
|
534
537
|
and then call the action method. (``:implicitly`` by default)
|
@@ -726,17 +729,17 @@ is raised and can be rescued and processed. It contains a description
|
|
726
729
|
of the parameter value expectations. Validations can be turned off
|
727
730
|
in the configuration file.
|
728
731
|
|
729
|
-
Parameter validation normally happens after
|
732
|
+
Parameter validation normally happens after before_actions, just before
|
730
733
|
your controller method is invoked. If you prefer to control when parameter
|
731
734
|
validation occurs, set the configuration parameter ``validate`` to ``:explicitly``.
|
732
735
|
You must then call the ``apipie_validations`` method yourself, e.g.:
|
733
736
|
|
734
737
|
.. code:: ruby
|
735
738
|
|
736
|
-
|
739
|
+
before_action: :apipie_validations
|
737
740
|
|
738
|
-
This is useful if you have
|
739
|
-
after the ``apipie_validations``
|
741
|
+
This is useful if you have before_actions which use parameter values: just add them
|
742
|
+
after the ``apipie_validations`` before_action.
|
740
743
|
|
741
744
|
TypeValidator
|
742
745
|
-------------
|
@@ -1068,11 +1071,8 @@ When your project use I18n, localization related configuration could appear as f
|
|
1068
1071
|
config.default_locale = 'en'
|
1069
1072
|
config.locale = lambda { |loc| loc ? I18n.locale = loc : I18n.locale }
|
1070
1073
|
config.translate = lambda do |str, loc|
|
1071
|
-
|
1072
|
-
I18n.locale
|
1073
|
-
trans = I18n.t(str)
|
1074
|
-
I18n.locale = old_loc
|
1075
|
-
trans
|
1074
|
+
return '' if str.blank?
|
1075
|
+
I18n.t str, locale: loc, scope: 'doc'
|
1076
1076
|
end
|
1077
1077
|
end
|
1078
1078
|
|
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"
|
@@ -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
|
@@ -93,7 +93,7 @@ module Apipie
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def authorized_doc
|
96
|
-
|
96
|
+
return if @doc.nil?
|
97
97
|
return @doc unless Apipie.configuration.authorize
|
98
98
|
|
99
99
|
new_doc = { :docs => @doc[:docs].clone }
|
@@ -114,9 +114,13 @@ module Apipie
|
|
114
114
|
|
115
115
|
def get_format
|
116
116
|
[:resource, :method, :version].each do |par|
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
next unless params[par]
|
118
|
+
[:html, :json].each do |format|
|
119
|
+
extension = ".#{format}"
|
120
|
+
if params[par].include?(extension)
|
121
|
+
params[par] = params[par].sub(extension, '')
|
122
|
+
params[:format] = format
|
123
|
+
end
|
120
124
|
end
|
121
125
|
end
|
122
126
|
request.format = params[:format] if params[:format]
|
@@ -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
@@ -31,14 +31,16 @@ module Apipie
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# get application description for given or default version
|
34
|
-
def self.app_info(version = nil)
|
35
|
-
if app_info_version_valid? version
|
36
|
-
|
34
|
+
def self.app_info(version = nil, lang = nil)
|
35
|
+
info = if app_info_version_valid? version
|
36
|
+
translate(self.configuration.app_info[version], lang)
|
37
37
|
elsif app_info_version_valid? Apipie.configuration.default_version
|
38
|
-
|
38
|
+
translate(self.configuration.app_info[Apipie.configuration.default_version], lang)
|
39
39
|
else
|
40
40
|
"Another API description"
|
41
41
|
end
|
42
|
+
|
43
|
+
Apipie.markup_to_html info
|
42
44
|
end
|
43
45
|
|
44
46
|
def self.api_base_url(version = nil)
|
data/lib/apipie/application.rb
CHANGED
@@ -54,14 +54,9 @@ module Apipie
|
|
54
54
|
# the app might be nested when using contraints, namespaces etc.
|
55
55
|
# this method does in depth search for the route controller
|
56
56
|
def route_app_controller(app, route, visited_apps = [])
|
57
|
-
|
58
|
-
|
59
|
-
return app.controller(route.defaults)
|
60
|
-
elsif app.respond_to?(:app) && !visited_apps.include?(app.app)
|
61
|
-
return route_app_controller(app.app, route, visited_apps)
|
57
|
+
if route.defaults[:controller]
|
58
|
+
(route.defaults[:controller].camelize + "Controller").constantize
|
62
59
|
end
|
63
|
-
rescue ActionController::RoutingError
|
64
|
-
# some errors in the routes will not stop us here: just ignoring
|
65
60
|
end
|
66
61
|
|
67
62
|
def routes_for_action(controller, method, args)
|
@@ -278,7 +273,7 @@ module Apipie
|
|
278
273
|
{
|
279
274
|
:docs => {
|
280
275
|
:name => Apipie.configuration.app_name,
|
281
|
-
:info =>
|
276
|
+
:info => Apipie.app_info(version, lang),
|
282
277
|
:copyright => Apipie.configuration.copyright,
|
283
278
|
:doc_url => Apipie.full_url(url_args),
|
284
279
|
:api_url => Apipie.api_base_url(version),
|
@@ -392,7 +387,7 @@ module Apipie
|
|
392
387
|
def version_prefix(klass)
|
393
388
|
version = controller_versions(klass).first
|
394
389
|
base_url = get_base_url(version)
|
395
|
-
return "/" if base_url.
|
390
|
+
return "/" if base_url.blank?
|
396
391
|
base_url[1..-1] + "/"
|
397
392
|
end
|
398
393
|
|
@@ -429,10 +424,10 @@ module Apipie
|
|
429
424
|
# as this would break loading of the controllers.
|
430
425
|
def rails_mark_classes_for_reload
|
431
426
|
unless Rails.application.config.cache_classes
|
432
|
-
|
427
|
+
Rails.application.reloader.reload!
|
433
428
|
init_env
|
434
429
|
reload_examples
|
435
|
-
|
430
|
+
Rails.application.reloader.prepare!
|
436
431
|
end
|
437
432
|
end
|
438
433
|
|
@@ -26,7 +26,7 @@ module Apipie
|
|
26
26
|
:errors => [],
|
27
27
|
:params => [],
|
28
28
|
:headers => [],
|
29
|
-
:
|
29
|
+
:resource_id => nil,
|
30
30
|
:short_description => nil,
|
31
31
|
:description => nil,
|
32
32
|
:examples => [],
|
@@ -237,7 +237,7 @@ module Apipie
|
|
237
237
|
# Only allow params passed in that are defined keys in the api
|
238
238
|
# Auto skip the default params (format, controller, action)
|
239
239
|
if Apipie.configuration.validate_key?
|
240
|
-
params.reject{|k,_| %w[format controller action].include?(k.to_s) }.
|
240
|
+
params.reject{|k,_| %w[format controller action].include?(k.to_s) }.each_pair do |param, _|
|
241
241
|
# params allowed
|
242
242
|
raise UnknownParam.new(param) if method_params.select {|_,p| p.name.to_s == param.to_s}.empty?
|
243
243
|
end
|
@@ -38,7 +38,7 @@ module Apipie
|
|
38
38
|
@verb = request.request_method.to_sym
|
39
39
|
@path = request.path
|
40
40
|
@params = request.request_parameters
|
41
|
-
if [:POST, :PUT, :PATCH].include?(@verb)
|
41
|
+
if [:POST, :PUT, :PATCH, :DELETE].include?(@verb)
|
42
42
|
@request_data = @params
|
43
43
|
else
|
44
44
|
@query = request.query_string
|
@@ -48,9 +48,9 @@ module Apipie
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def parse_data(data)
|
51
|
-
return nil if data.
|
51
|
+
return nil if data.strip.blank?
|
52
52
|
JSON.parse(data)
|
53
|
-
rescue StandardError
|
53
|
+
rescue StandardError
|
54
54
|
data
|
55
55
|
end
|
56
56
|
|
@@ -145,12 +145,8 @@ module Apipie
|
|
145
145
|
end
|
146
146
|
|
147
147
|
module FunctionalTestRecording
|
148
|
-
def
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
def process_with_api_recording(*args) # action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
|
153
|
-
ret = process_without_api_recording(*args)
|
148
|
+
def process(*args) # action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
|
149
|
+
ret = super(*args)
|
154
150
|
if Apipie.configuration.record
|
155
151
|
Apipie::Extractor.call_recorder.analyze_functional_test(self)
|
156
152
|
Apipie::Extractor.call_finished
|
@@ -78,21 +78,26 @@ module Apipie
|
|
78
78
|
%w[title verb path versions query request_data response_data code show_in_doc recorded].each do |k|
|
79
79
|
next unless call.has_key?(k)
|
80
80
|
ordered_call[k] = case call[k]
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
JSON.parse(call[k].to_json) # to_hash doesn't work recursively and I'm too lazy to write the recursion:)
|
89
|
-
else
|
90
|
-
call[k]
|
91
|
-
end
|
92
|
-
end
|
81
|
+
when ActiveSupport::HashWithIndifferentAccess
|
82
|
+
convert_file_value(call[k]).to_hash
|
83
|
+
else
|
84
|
+
call[k]
|
85
|
+
end
|
86
|
+
end
|
93
87
|
return ordered_call
|
94
88
|
end
|
95
89
|
|
90
|
+
def convert_file_value hash
|
91
|
+
hash.each do |k, v|
|
92
|
+
if (v.is_a?(Rack::Test::UploadedFile) || v.is_a?(ActionDispatch::Http::UploadedFile))
|
93
|
+
hash[k] = "<FILE CONTENT '#{v.original_filename}'>"
|
94
|
+
elsif v.is_a?(Hash)
|
95
|
+
hash[k] = convert_file_value(v)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
hash
|
99
|
+
end
|
100
|
+
|
96
101
|
def load_recorded_examples
|
97
102
|
self.class.load_recorded_examples
|
98
103
|
end
|
@@ -131,7 +136,7 @@ module Apipie
|
|
131
136
|
new_example[:title] ||= old_example["title"] if old_example["title"].present?
|
132
137
|
end
|
133
138
|
new_example
|
134
|
-
end
|
139
|
+
end
|
135
140
|
end
|
136
141
|
|
137
142
|
def load_new_examples
|
data/lib/apipie/extractor.rb
CHANGED
@@ -9,7 +9,7 @@ require 'apipie/extractor/collector'
|
|
9
9
|
class Apipie::Railtie
|
10
10
|
initializer 'apipie.extractor' do |app|
|
11
11
|
ActiveSupport.on_load :action_controller do
|
12
|
-
|
12
|
+
before_action do |controller|
|
13
13
|
if Apipie.configuration.record
|
14
14
|
Apipie::Extractor.call_recorder.analyse_controller(controller)
|
15
15
|
end
|
@@ -17,7 +17,7 @@ class Apipie::Railtie
|
|
17
17
|
end
|
18
18
|
app.middleware.use ::Apipie::Extractor::Recorder::Middleware
|
19
19
|
ActionController::TestCase::Behavior.instance_eval do
|
20
|
-
|
20
|
+
prepend Apipie::Extractor::Recorder::FunctionalTestRecording
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -8,7 +8,7 @@ module Apipie
|
|
8
8
|
# validator - Validator::BaseValidator subclass
|
9
9
|
class ParamDescription
|
10
10
|
|
11
|
-
attr_reader :method_description, :name, :desc, :allow_nil, :validator, :options, :metadata, :show, :as, :validations
|
11
|
+
attr_reader :method_description, :name, :desc, :allow_nil, :allow_blank, :validator, :options, :metadata, :show, :as, :validations
|
12
12
|
attr_accessor :parent, :required
|
13
13
|
|
14
14
|
def self.from_dsl_data(method_description, args)
|
@@ -56,6 +56,7 @@ module Apipie
|
|
56
56
|
end
|
57
57
|
|
58
58
|
@allow_nil = @options[:allow_nil] || false
|
59
|
+
@allow_blank = @options[:allow_blank] || false
|
59
60
|
|
60
61
|
action_awareness
|
61
62
|
|
@@ -71,8 +72,20 @@ module Apipie
|
|
71
72
|
method_description.from_concern? || @from_concern
|
72
73
|
end
|
73
74
|
|
75
|
+
def normalized_value(value)
|
76
|
+
if value.is_a?(ActionController::Parameters) && !value.is_a?(Hash)
|
77
|
+
value.to_unsafe_hash
|
78
|
+
elsif value.is_a? Array
|
79
|
+
value.map { |v| normalized_value (v) }
|
80
|
+
else
|
81
|
+
value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
74
85
|
def validate(value)
|
75
86
|
return true if @allow_nil && value.nil?
|
87
|
+
return true if @allow_blank && value.blank?
|
88
|
+
value = normalized_value(value)
|
76
89
|
if (!@allow_nil && value.nil?) || !@validator.valid?(value)
|
77
90
|
error = @validator.error
|
78
91
|
error = ParamError.new(error) unless error.is_a? StandardError
|
@@ -81,6 +94,7 @@ module Apipie
|
|
81
94
|
end
|
82
95
|
|
83
96
|
def process_value(value)
|
97
|
+
value = normalized_value(value)
|
84
98
|
if @validator.respond_to?(:process_value)
|
85
99
|
@validator.process_value(value)
|
86
100
|
else
|
@@ -111,6 +125,7 @@ module Apipie
|
|
111
125
|
:description => preformat_text(Apipie.app.translate(@options[:desc], lang)),
|
112
126
|
:required => required,
|
113
127
|
:allow_nil => allow_nil,
|
128
|
+
:allow_blank => allow_blank,
|
114
129
|
:validator => validator.to_s,
|
115
130
|
:expected_type => validator.expected_type,
|
116
131
|
:metadata => metadata,
|
data/lib/apipie/validator.rb
CHANGED
@@ -96,7 +96,7 @@ module Apipie
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def description
|
99
|
-
"Must be #{@type}"
|
99
|
+
"Must be a #{@type}"
|
100
100
|
end
|
101
101
|
|
102
102
|
def expected_type
|
@@ -413,7 +413,8 @@ module Apipie
|
|
413
413
|
end
|
414
414
|
|
415
415
|
def description
|
416
|
-
|
416
|
+
string = %w(true false 1 0).map { |value| "<code>#{value}</code>" }.join(', ')
|
417
|
+
"Must be one of: #{string}"
|
417
418
|
end
|
418
419
|
end
|
419
420
|
|
@@ -464,4 +465,3 @@ module Apipie
|
|
464
465
|
|
465
466
|
end
|
466
467
|
end
|
467
|
-
|
data/lib/apipie/version.rb
CHANGED
data/lib/apipie-rails.rb
CHANGED
data/lib/tasks/apipie.rake
CHANGED
@@ -105,7 +105,11 @@ namespace :apipie do
|
|
105
105
|
else
|
106
106
|
File.expand_path("../../../app/views/apipie/apipies", __FILE__)
|
107
107
|
end
|
108
|
-
layouts_path = File.
|
108
|
+
layouts_path = if File.directory?("#{Rails.root}/app/views/layouts/apipie")
|
109
|
+
"#{Rails.root}/app/views/layouts"
|
110
|
+
else
|
111
|
+
File.expand_path("../../../app/views/layouts", __FILE__)
|
112
|
+
end
|
109
113
|
@apipie_renderer = ActionView::Base.new([base_path, layouts_path])
|
110
114
|
@apipie_renderer.singleton_class.send(:include, ApipieHelper)
|
111
115
|
return @apipie_renderer
|