apipie-rails 0.3.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -3
  3. data/CHANGELOG.md +33 -0
  4. data/Gemfile +3 -3
  5. data/Gemfile.rails41 +1 -0
  6. data/Gemfile.rails42 +7 -1
  7. data/Gemfile.rails50 +7 -0
  8. data/Gemfile.rails51 +7 -0
  9. data/README.rst +12 -12
  10. data/apipie-rails.gemspec +2 -3
  11. data/app/controllers/apipie/apipies_controller.rb +10 -6
  12. data/config/locales/it.yml +31 -0
  13. data/config/locales/ja.yml +31 -0
  14. data/lib/apipie/apipie_module.rb +6 -4
  15. data/lib/apipie/application.rb +6 -11
  16. data/lib/apipie/dsl_definition.rb +2 -2
  17. data/lib/apipie/extractor/recorder.rb +5 -9
  18. data/lib/apipie/extractor/writer.rb +18 -13
  19. data/lib/apipie/extractor.rb +2 -2
  20. data/lib/apipie/param_description.rb +16 -1
  21. data/lib/apipie/validator.rb +3 -3
  22. data/lib/apipie/version.rb +1 -1
  23. data/lib/apipie-rails.rb +1 -0
  24. data/lib/tasks/apipie.rake +5 -1
  25. data/spec/controllers/apipies_controller_spec.rb +12 -12
  26. data/spec/controllers/concerns_controller_spec.rb +2 -2
  27. data/spec/controllers/users_controller_spec.rb +93 -74
  28. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  29. data/spec/dummy/app/controllers/concerns/sample_controller.rb +5 -5
  30. data/spec/dummy/app/controllers/users_controller.rb +11 -10
  31. data/spec/dummy/config/environments/development.rb +3 -0
  32. data/spec/dummy/config/environments/production.rb +3 -0
  33. data/spec/dummy/config/environments/test.rb +3 -0
  34. data/spec/dummy/config/initializers/apipie.rb +1 -1
  35. data/spec/dummy/config/routes.rb +1 -1
  36. data/spec/spec_helper.rb +27 -0
  37. metadata +10 -22
  38. data/Gemfile.rails32 +0 -6
  39. data/Gemfile.rails40 +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d6fc12663b63923153a8f238fac0c7556257aeb
4
- data.tar.gz: 2271e183d1319d0d42df3d909285d7ded70970aa
3
+ metadata.gz: 8f1836e9d470aab5a5fd2592c5bd020670d7644f
4
+ data.tar.gz: 915e53c2aed478f60375817066e059dc0b955e66
5
5
  SHA512:
6
- metadata.gz: 7864fe236a067ce5a0a3068a51d01a53b641ade349f6f5dc8b2d9ebc242e8c078de8601d82e62c4560770e9c537bfe98771e1f24c4b693fb31cb5fc32148d91d
7
- data.tar.gz: fb902c9fc943fb6f3067576af5db940b015009810d908ccb02d684e9364e9cb293dc257d73848c7fee42cf356ad9756189734e0e5811e8f3ee07083535f483c2
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
- # load local gemfile
6
- local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
7
- self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
5
+ gem 'rails', '~> 5.0'
6
+ gem 'mime-types', '~> 2.99.3'
7
+ gem 'rails-controller-testing'
data/Gemfile.rails41 CHANGED
@@ -3,3 +3,4 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
+ gem 'mime-types', '~> 2.99.3'
data/Gemfile.rails42 CHANGED
@@ -2,4 +2,10 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 4.2.5.1'
5
+ gem 'rails', '~> 4.2.5'
6
+ gem 'mime-types', '~> 2.99.3'
7
+
8
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1.0')
9
+ gem 'nokogiri', '~> 1.6.8'
10
+ gem 'rdoc', '~> 4.2.2'
11
+ end
data/Gemfile.rails50 ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.0'
6
+ gem 'mime-types', '~> 2.99.3'
7
+ gem 'rails-controller-testing'
data/Gemfile.rails51 ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.1.0.rc1'
6
+ gem 'mime-types', '~> 2.99.3'
7
+ gem 'rails-controller-testing'
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.png?branch=master
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.png
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 before_filter).
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 before_filters, just before
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
- before_filter: :apipie_validations
739
+ before_action: :apipie_validations
737
740
 
738
- This is useful if you have before_filters which use parameter values: just add them
739
- after the ``apipie_validations`` before_filter.
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
- old_loc = I18n.locale
1072
- I18n.locale = loc
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.add_development_dependency "rails", ">= 3.0.20"
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
- around_filter :set_script_name
9
- before_filter :authenticate
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
- if params[par]
118
- params[:format] = :html unless params[par].sub!('.html', '').nil?
119
- params[:format] = :json unless params[par].sub!('.json', '').nil?
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: "ヘッダー名"
@@ -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
- Apipie.markup_to_html(self.configuration.app_info[version])
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
- Apipie.markup_to_html(self.configuration.app_info[Apipie.configuration.default_version])
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)
@@ -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
- visited_apps << app
58
- if app.respond_to?(:controller)
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 => translate(Apipie.app_info(version), lang),
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.nil?
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
- ActionDispatch::Reloader.cleanup!
427
+ Rails.application.reloader.reload!
433
428
  init_env
434
429
  reload_examples
435
- ActionDispatch::Reloader.prepare!
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
- :resouce_id => nil,
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) }.each_key do |param|
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.to_s =~ /^\s*$/
51
+ return nil if data.strip.blank?
52
52
  JSON.parse(data)
53
- rescue StandardError => e
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 self.included(base)
149
- base.alias_method_chain :process, :api_recording
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
- when ActiveSupport::HashWithIndifferentAccess
82
- # UploadedFiles break the to_json call, turn them into a string so they don't break
83
- call[k].each do |pkey, pval|
84
- if (pval.is_a?(Rack::Test::UploadedFile) || pval.is_a?(ActionDispatch::Http::UploadedFile))
85
- call[k][pkey] = "<FILE CONTENT '#{pval.original_filename}'>"
86
- end
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
@@ -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
- before_filter do |controller|
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
- include Apipie::Extractor::Recorder::FunctionalTestRecording
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,
@@ -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
- "Must be 'true' or 'false' or '1' or '0'"
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
-
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.3.6'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/apipie-rails.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'i18n'
2
+ require 'json'
2
3
  require 'active_support/hash_with_indifferent_access'
3
4
 
4
5
  require "apipie/routing"
@@ -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.expand_path("../../../app/views/layouts", __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