apipie-rails 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile +3 -3
- data/Gemfile.rails40 +2 -1
- data/Gemfile.rails41 +1 -1
- data/Gemfile.rails42 +6 -1
- data/Gemfile.rails50 +7 -0
- data/README.rst +12 -12
- data/apipie-rails.gemspec +1 -1
- data/app/controllers/apipie/apipies_controller.rb +2 -2
- data/config/locales/it.yml +31 -0
- data/lib/apipie/apipie_module.rb +6 -4
- data/lib/apipie/application.rb +4 -9
- data/lib/apipie/dsl_definition.rb +1 -1
- data/lib/apipie/extractor.rb +1 -1
- data/lib/apipie/extractor/recorder.rb +1 -1
- data/lib/apipie/param_description.rb +16 -1
- data/lib/apipie/validator.rb +3 -3
- data/lib/apipie/version.rb +1 -1
- data/spec/controllers/apipies_controller_spec.rb +12 -12
- data/spec/controllers/concerns_controller_spec.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +75 -60
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/app/controllers/users_controller.rb +1 -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/routes.rb +1 -1
- data/spec/spec_helper.rb +32 -0
- metadata +7 -6
- data/Gemfile.rails32 +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3557cb98f666126a55faa4fe95a955403adcaedf
|
4
|
+
data.tar.gz: 6fd75fb4ebd5e4b0652b81c77c0df65f6d96a41b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9c181cc455758e9411f0631f3e5a5d67953ce8eb6209ad079862ce2e4ab3c1550cd5deb05fae1541d8e48d6d4f27753c994876484d185551f3049583a2ec47
|
7
|
+
data.tar.gz: 77b58f2a00111e3dab471de451c9ddcf9ec82622dde6b3ba14d3e23f2138ec571157521092fdebc0a76c73ae22350a3c2d7693147d65b248285e5f608734398f
|
data/.travis.yml
CHANGED
@@ -5,8 +5,17 @@ rvm:
|
|
5
5
|
- 2.0.0
|
6
6
|
- 2.1.7
|
7
7
|
- 2.2.3
|
8
|
+
- 2.3.3
|
8
9
|
gemfile:
|
9
|
-
- Gemfile.rails32
|
10
10
|
- Gemfile.rails40
|
11
11
|
- Gemfile.rails41
|
12
12
|
- Gemfile.rails42
|
13
|
+
- Gemfile.rails50 # Min ruby 2.2.2
|
14
|
+
matrix:
|
15
|
+
exclude:
|
16
|
+
- rvm: 1.9.3
|
17
|
+
gemfile: Gemfile.rails50
|
18
|
+
- rvm: 2.0.0
|
19
|
+
gemfile: Gemfile.rails50
|
20
|
+
- rvm: 2.1.7
|
21
|
+
gemfile: Gemfile.rails50
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
Changelog
|
3
3
|
===========
|
4
4
|
|
5
|
+
v0.4.0
|
6
|
+
------
|
7
|
+
|
8
|
+
- 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))
|
9
|
+
- **This release is no longer compatible with Rails 3.x**
|
10
|
+
- Include delete request parmeters in generated documentation [\#524](https://github.com/Apipie/apipie-rails/pull/524) ([johnnaegle](https://github.com/johnnaegle))
|
11
|
+
- Allow a blank, not just nil, base\_url. [\#521](https://github.com/Apipie/apipie-rails/pull/521) ([johnnaegle](https://github.com/johnnaegle))
|
12
|
+
- Adds allow\_blank option [\#508](https://github.com/Apipie/apipie-rails/pull/508) ([MrLeebo](https://github.com/MrLeebo))
|
13
|
+
- Boolean Validator uses \<code\> instead of ' [\#502](https://github.com/Apipie/apipie-rails/pull/502) ([berfarah](https://github.com/berfarah))
|
14
|
+
- Fix type validator message [\#501](https://github.com/Apipie/apipie-rails/pull/501) ([cindygu-itglue](https://github.com/cindygu-itglue))
|
15
|
+
- Add IT locale [\#496](https://github.com/Apipie/apipie-rails/pull/496) ([alepore](https://github.com/alepore))
|
16
|
+
- Fix small typo on dsl\_definition data init [\#494](https://github.com/Apipie/apipie-rails/pull/494) ([begault](https://github.com/begault))
|
17
|
+
- Localize app info message [\#491](https://github.com/Apipie/apipie-rails/pull/491) ([belousovAV](https://github.com/belousovAV))
|
18
|
+
- Fix travis build [\#489](https://github.com/Apipie/apipie-rails/pull/489) ([mtparet](https://github.com/mtparet))
|
19
|
+
- Handle blank data when parsing a example's response [\#453](https://github.com/Apipie/apipie-rails/pull/453) ([stbenjam](https://github.com/stbenjam))
|
20
|
+
- 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))
|
21
|
+
|
5
22
|
v0.3.7
|
6
23
|
------
|
7
24
|
|
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.rails40
CHANGED
data/Gemfile.rails41
CHANGED
data/Gemfile.rails42
CHANGED
data/Gemfile.rails50
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
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.
|
19
|
+
s.add_dependency "rails", ">= 4.0"
|
20
20
|
s.add_dependency 'json'
|
21
21
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
22
22
|
s.add_development_dependency "sqlite3"
|
@@ -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
|
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
|
|
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
|
@@ -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
|
@@ -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
@@ -12,37 +12,37 @@ describe Apipie::ApipiesController do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "succeeds on version details" do
|
15
|
-
get :index, :version => "2.0"
|
15
|
+
get :index, :params => { :version => "2.0" }
|
16
16
|
|
17
17
|
assert_response :success
|
18
18
|
end
|
19
19
|
|
20
20
|
it "returns not_found on wrong version" do
|
21
|
-
get :index, :version => "wrong_version"
|
21
|
+
get :index, :params => { :version => "wrong_version" }
|
22
22
|
|
23
23
|
assert_response :not_found
|
24
24
|
end
|
25
25
|
|
26
26
|
it "succeeds on resource details" do
|
27
|
-
get :index, :version => "2.0", :resource => "architectures"
|
27
|
+
get :index, :params => { :version => "2.0", :resource => "architectures" }
|
28
28
|
|
29
29
|
assert_response :success
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns not_found on wrong resource" do
|
33
|
-
get :index, :version => "2.0", :resource => "wrong_resource"
|
33
|
+
get :index, :params => { :version => "2.0", :resource => "wrong_resource" }
|
34
34
|
|
35
35
|
assert_response :not_found
|
36
36
|
end
|
37
37
|
|
38
38
|
it "succeeds on method details" do
|
39
|
-
get :index, :version => "2.0", :resource => "architectures", :method => "index"
|
39
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index" }
|
40
40
|
|
41
41
|
assert_response :success
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns not_found on wrong method" do
|
45
|
-
get :index, :version => "2.0", :resource => "architectures", :method => "wrong_method"
|
45
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "wrong_method" }
|
46
46
|
|
47
47
|
assert_response :not_found
|
48
48
|
end
|
@@ -215,17 +215,17 @@ describe Apipie::ApipiesController do
|
|
215
215
|
it "uses the file in cache dir instead of generating the content on runtime" do
|
216
216
|
get :index
|
217
217
|
expect(response.body).to eq("apidoc.html cache v1")
|
218
|
-
get :index, :version => 'v1'
|
218
|
+
get :index, :params => { :version => 'v1' }
|
219
219
|
expect(response.body).to eq("apidoc.html cache v1")
|
220
|
-
get :index, :version => 'v2'
|
220
|
+
get :index, :params => { :version => 'v2' }
|
221
221
|
expect(response.body).to eq("apidoc.html cache v2")
|
222
|
-
get :index, :version => 'v1', :format => "html"
|
222
|
+
get :index, :params => { :version => 'v1', :format => "html" }
|
223
223
|
expect(response.body).to eq("apidoc.html cache v1")
|
224
|
-
get :index, :version => 'v1', :format => "json"
|
224
|
+
get :index, :params => { :version => 'v1', :format => "json" }
|
225
225
|
expect(response.body).to eq("apidoc.json cache")
|
226
|
-
get :index, :version => 'v1', :format => "html", :resource => "resource"
|
226
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource" }
|
227
227
|
expect(response.body).to eq("resource.html cache")
|
228
|
-
get :index, :version => 'v1', :format => "html", :resource => "resource", :method => "method"
|
228
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource", :method => "method" }
|
229
229
|
expect(response.body).to eq("method.html cache")
|
230
230
|
end
|
231
231
|
|
@@ -66,7 +66,7 @@ describe UsersController do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should reply to valid request" do
|
69
|
-
get :show, :id => '5', :session => "secret_hash"
|
69
|
+
get :show, :params => { :id => '5', :session => "secret_hash" }
|
70
70
|
assert_response :success
|
71
71
|
end
|
72
72
|
|
@@ -92,17 +92,17 @@ describe UsersController do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should reply to valid request" do
|
95
|
-
expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
|
95
|
+
expect { get :show, :params => { :id => 5, :session => "secret_hash" }}.not_to raise_error
|
96
96
|
assert_response :success
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should fail if required parameter is missing" do
|
100
|
-
expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
100
|
+
expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should pass if required parameter has wrong type" do
|
104
|
-
expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
|
105
|
-
expect { get :show, :id => "ten", :session => "secret_hash" }.not_to raise_error
|
104
|
+
expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
|
105
|
+
expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
|
106
106
|
end
|
107
107
|
|
108
108
|
end
|
@@ -115,12 +115,12 @@ describe UsersController do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should reply to valid request" do
|
118
|
-
expect { get :show, :id => 5, :session =>
|
118
|
+
expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
|
119
119
|
assert_response :success
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should fail if extra parameter is passed in" do
|
123
|
-
expect { get :show, :
|
123
|
+
expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -132,81 +132,75 @@ describe UsersController do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should reply to valid request" do
|
135
|
-
get :show, :id => '5', :session => "secret_hash"
|
135
|
+
get :show, :params => { :id => '5', :session => "secret_hash" }
|
136
136
|
assert_response :success
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should work with nil value for a required hash param" do
|
140
140
|
expect {
|
141
|
-
get :show, :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil}
|
141
|
+
get :show, :params => { :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil} }
|
142
142
|
}.to raise_error(Apipie::ParamInvalid, /dummy_hash/)
|
143
143
|
assert_response :success
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should fail if required parameter is missing" do
|
147
|
-
expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
147
|
+
expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should work with custom Type validator" do
|
151
151
|
expect {
|
152
152
|
get :show,
|
153
|
-
:id => "not a number",
|
154
|
-
:session => "secret_hash"
|
153
|
+
:params => { :id => "not a number", :session => "secret_hash" }
|
155
154
|
}.to raise_error(Apipie::ParamError, /id/) # old-style error rather than ParamInvalid
|
156
155
|
end
|
157
156
|
|
158
157
|
it "should work with Regexp validator" do
|
159
|
-
get :show,
|
160
|
-
:id => 5,
|
161
|
-
:session => "secret_hash",
|
162
|
-
:regexp_param => "24 years"
|
158
|
+
get :show, :params => { :id => 5, :session => "secret_hash", :regexp_param => "24 years" }
|
163
159
|
assert_response :success
|
164
160
|
|
165
161
|
expect {
|
166
|
-
get :show,
|
167
|
-
|
168
|
-
|
169
|
-
:regexp_param => "ten years"
|
162
|
+
get :show, :params => { :id => 5,
|
163
|
+
:session => "secret_hash",
|
164
|
+
:regexp_param => "ten years" }
|
170
165
|
}.to raise_error(Apipie::ParamInvalid, /regexp_param/)
|
171
166
|
end
|
172
167
|
|
173
168
|
it "should work with Array validator" do
|
174
|
-
get :show, :id => 5, :session => "secret_hash", :array_param => "one"
|
175
|
-
assert_response :success
|
176
|
-
get :show, :id => 5, :session => "secret_hash", :array_param => "two"
|
169
|
+
get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "one" }
|
177
170
|
assert_response :success
|
178
|
-
get :show, :id => 5, :session => "secret_hash", :array_param =>
|
171
|
+
get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "two" }
|
179
172
|
assert_response :success
|
180
|
-
get :show, :id => 5, :session => "secret_hash", :
|
173
|
+
get :show, :params => { :id => 5, :session => "secret_hash", :array_param => '1' }
|
181
174
|
assert_response :success
|
182
175
|
|
183
176
|
expect {
|
184
|
-
get :show,
|
185
|
-
|
186
|
-
|
187
|
-
:array_param => "blabla"
|
177
|
+
get :show, :params => { :id => 5,
|
178
|
+
:session => "secret_hash",
|
179
|
+
:array_param => "blabla" }
|
188
180
|
}.to raise_error(Apipie::ParamInvalid, /array_param/)
|
189
181
|
|
190
182
|
expect {
|
191
|
-
get :show,
|
192
|
-
|
193
|
-
|
194
|
-
|
183
|
+
get :show, :params => {
|
184
|
+
:id => 5,
|
185
|
+
:session => "secret_hash",
|
186
|
+
:array_param => 3 }
|
195
187
|
}.to raise_error(Apipie::ParamInvalid, /array_param/)
|
196
188
|
end
|
197
189
|
|
198
190
|
it "should work with Proc validator" do
|
199
191
|
expect {
|
200
192
|
get :show,
|
201
|
-
:
|
202
|
-
|
203
|
-
|
193
|
+
:params => {
|
194
|
+
:id => 5,
|
195
|
+
:session => "secret_hash",
|
196
|
+
:proc_param => "asdgsag" }
|
204
197
|
}.to raise_error(Apipie::ParamInvalid, /proc_param/)
|
205
198
|
|
206
199
|
get :show,
|
207
|
-
:
|
208
|
-
|
209
|
-
|
200
|
+
:params => {
|
201
|
+
:id => 5,
|
202
|
+
:session => "secret_hash",
|
203
|
+
:proc_param => "param value"}
|
210
204
|
assert_response :success
|
211
205
|
end
|
212
206
|
|
@@ -244,10 +238,11 @@ describe UsersController do
|
|
244
238
|
params = Apipie[UsersController, :create].to_json[:params]
|
245
239
|
expect(params).to include(:name => "facts",
|
246
240
|
:full_name => "facts",
|
247
|
-
:validator => "Must be Hash",
|
241
|
+
:validator => "Must be a Hash",
|
248
242
|
:description => "\n<p>Additional optional facts about the user</p>\n",
|
249
243
|
:required => false,
|
250
244
|
:allow_nil => true,
|
245
|
+
:allow_blank => false,
|
251
246
|
:metadata => nil,
|
252
247
|
:show => true,
|
253
248
|
:expected_type => "hash",
|
@@ -261,7 +256,18 @@ describe UsersController do
|
|
261
256
|
:pass => "12345",
|
262
257
|
:membership => "standard",
|
263
258
|
},
|
264
|
-
:facts =>
|
259
|
+
:facts => { :test => 'test' }
|
260
|
+
assert_response :success
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should allow blank when allow_blank is set to true" do
|
264
|
+
post :create,
|
265
|
+
:user => {
|
266
|
+
:name => "root",
|
267
|
+
:pass => "12345",
|
268
|
+
:membership => "standard"
|
269
|
+
},
|
270
|
+
:age => ""
|
265
271
|
assert_response :success
|
266
272
|
end
|
267
273
|
|
@@ -293,21 +299,21 @@ describe UsersController do
|
|
293
299
|
it "should raise an error" do
|
294
300
|
expect{
|
295
301
|
put :update,
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
},
|
302
|
-
:comments => [
|
303
|
-
{
|
304
|
-
:comment => 'comment1'
|
302
|
+
:params => {
|
303
|
+
:id => 5,
|
304
|
+
:user => {
|
305
|
+
:name => "root",
|
306
|
+
:pass => "12345"
|
305
307
|
},
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
308
|
+
:comments => [
|
309
|
+
{
|
310
|
+
:comment => {:bad_input => 4}
|
311
|
+
},
|
312
|
+
{
|
313
|
+
:comment => {:bad_input => 5}
|
314
|
+
}
|
315
|
+
]
|
316
|
+
}
|
311
317
|
}.to raise_error(Apipie::ParamInvalid)
|
312
318
|
end
|
313
319
|
end
|
@@ -525,7 +531,8 @@ describe UsersController do
|
|
525
531
|
:params => [{:full_name=>"oauth",
|
526
532
|
:required=>false,
|
527
533
|
:allow_nil => false,
|
528
|
-
:
|
534
|
+
:allow_blank => false,
|
535
|
+
:validator=>"Must be a String",
|
529
536
|
:description=>"\n<p>Authorization</p>\n",
|
530
537
|
:name=>"oauth",
|
531
538
|
:show=>true,
|
@@ -534,6 +541,7 @@ describe UsersController do
|
|
534
541
|
:description=>"\n<p>Deprecated parameter not documented</p>\n",
|
535
542
|
:expected_type=>"hash",
|
536
543
|
:allow_nil=>false,
|
544
|
+
:allow_blank => false,
|
537
545
|
:name=>"legacy_param",
|
538
546
|
:required=>false,
|
539
547
|
:full_name=>"legacy_param",
|
@@ -543,6 +551,7 @@ describe UsersController do
|
|
543
551
|
:description=>"\n<p>Param description for all methods</p>\n",
|
544
552
|
:expected_type=>"hash",
|
545
553
|
:allow_nil=>false,
|
554
|
+
:allow_blank => false,
|
546
555
|
:name=>"resource_param",
|
547
556
|
:required=>false,
|
548
557
|
:full_name=>"resource_param",
|
@@ -550,14 +559,16 @@ describe UsersController do
|
|
550
559
|
:params=>
|
551
560
|
[{:required=>true,
|
552
561
|
:allow_nil => false,
|
553
|
-
:
|
562
|
+
:allow_blank => false,
|
563
|
+
:validator=>"Must be a String",
|
554
564
|
:description=>"\n<p>Username for login</p>\n",
|
555
565
|
:name=>"ausername", :full_name=>"resource_param[ausername]",
|
556
566
|
:show=>true,
|
557
567
|
:expected_type=>"string"},
|
558
568
|
{:required=>true,
|
559
569
|
:allow_nil => false,
|
560
|
-
:
|
570
|
+
:allow_blank => false,
|
571
|
+
:validator=>"Must be a String",
|
561
572
|
:description=>"\n<p>Password for login</p>\n",
|
562
573
|
:name=>"apassword", :full_name=>"resource_param[apassword]",
|
563
574
|
:show=>true,
|
@@ -567,6 +578,7 @@ describe UsersController do
|
|
567
578
|
},
|
568
579
|
{:required=>false, :validator=>"Parameter has to be Integer.",
|
569
580
|
:allow_nil => false,
|
581
|
+
:allow_blank => false,
|
570
582
|
:description=>"\n<p>Company ID</p>\n",
|
571
583
|
:name=>"id", :full_name=>"id",
|
572
584
|
:show=>true,
|
@@ -690,13 +702,16 @@ EOS2
|
|
690
702
|
|
691
703
|
describe "Parameter processing / extraction" do
|
692
704
|
before do
|
705
|
+
Apipie.configuration.validate = true
|
693
706
|
Apipie.configuration.process_params = true
|
707
|
+
controllers_dirname = File.expand_path('../dummy/app/controllers', File.dirname(__FILE__))
|
708
|
+
Dir.glob("#{controllers_dirname}/**/*") { |file| load(file) if File.file?(file) }
|
694
709
|
end
|
695
710
|
|
696
711
|
it "process correctly the parameters" do
|
697
|
-
post :create,
|
712
|
+
post :create, :user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard' }, :facts => {:test => 'test'}
|
698
713
|
|
699
|
-
expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts =>
|
714
|
+
expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => {:test => 'test'}}.with_indifferent_access)
|
700
715
|
end
|
701
716
|
|
702
717
|
it "ignore not described parameters" do
|
@@ -221,6 +221,7 @@ class UsersController < ApplicationController
|
|
221
221
|
param :permalink, String
|
222
222
|
end
|
223
223
|
param :facts, Hash, :desc => "Additional optional facts about the user", :allow_nil => true
|
224
|
+
param :age, :number, :desc => "Age is just a number", :allow_blank => true
|
224
225
|
def create
|
225
226
|
render :text => "OK #{params.inspect}"
|
226
227
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -10,7 +10,7 @@ Dummy::Application.routes.draw do
|
|
10
10
|
end
|
11
11
|
resources :concerns, :only => [:index, :show]
|
12
12
|
namespace :files do
|
13
|
-
get '/*file_path',
|
13
|
+
get '/*file_path', format: false, :action => 'download'
|
14
14
|
end
|
15
15
|
resources :twitter_example do
|
16
16
|
collection do
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,34 @@ require 'rspec/rails'
|
|
9
9
|
|
10
10
|
require 'apipie-rails'
|
11
11
|
|
12
|
+
module Rails4Compatibility
|
13
|
+
module Testing
|
14
|
+
def process_with_rails4_compat(*args)
|
15
|
+
compatible_request(*args) { |*new_args| process_without_rails4_compat(*new_args) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.alias_method_chain :process, :rails4_compat
|
20
|
+
end
|
21
|
+
|
22
|
+
def compatible_request(method, action, hash = {})
|
23
|
+
if hash.is_a?(Hash)
|
24
|
+
if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
|
25
|
+
hash = hash.dup
|
26
|
+
hash.merge!(hash.delete(:params) || {})
|
27
|
+
elsif hash.key?(:params)
|
28
|
+
hash = { :params => hash }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if hash.empty?
|
32
|
+
yield method, action
|
33
|
+
else
|
34
|
+
yield method, action, hash
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
12
40
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
13
41
|
# in spec/support/ and its subdirectories.
|
14
42
|
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
|
@@ -41,3 +69,7 @@ RSpec.configure do |config|
|
|
41
69
|
# end
|
42
70
|
config.infer_spec_type_from_file_location!
|
43
71
|
end
|
72
|
+
|
73
|
+
require 'action_controller/test_case.rb'
|
74
|
+
# TODO: replace with prepend once we deprecate ruby 2.0.0
|
75
|
+
ActionController::TestCase::Behavior.send(:include, Rails4Compatibility::Testing)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apipie-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pokorny
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
type: :
|
20
|
+
version: '4.0'
|
21
|
+
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '4.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: json
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,10 +151,10 @@ files:
|
|
151
151
|
- APACHE-LICENSE-2.0
|
152
152
|
- CHANGELOG.md
|
153
153
|
- Gemfile
|
154
|
-
- Gemfile.rails32
|
155
154
|
- Gemfile.rails40
|
156
155
|
- Gemfile.rails41
|
157
156
|
- Gemfile.rails42
|
157
|
+
- Gemfile.rails50
|
158
158
|
- MIT-LICENSE
|
159
159
|
- NOTICE
|
160
160
|
- README.rst
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- config/locales/de.yml
|
192
192
|
- config/locales/en.yml
|
193
193
|
- config/locales/es.yml
|
194
|
+
- config/locales/it.yml
|
194
195
|
- config/locales/pl.yml
|
195
196
|
- config/locales/pt-BR.yml
|
196
197
|
- config/locales/ru.yml
|