apipie-rails 0.0.22 → 0.0.23
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.
- data/.travis.yml +0 -2
- data/CHANGELOG +8 -0
- data/README.rst +9 -1
- data/app/controllers/apipie/apipies_controller.rb +7 -0
- data/lib/apipie/application.rb +1 -1
- data/lib/apipie/configuration.rb +1 -1
- data/lib/apipie/param_description.rb +12 -14
- data/lib/apipie/static_dispatcher.rb +1 -1
- data/lib/apipie/validator.rb +2 -0
- data/lib/apipie/version.rb +1 -1
- data/spec/controllers/apipies_controller_spec.rb +11 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/lib/application_spec.rb +11 -0
- data/spec/lib/param_description_spec.rb +57 -0
- data/spec/lib/validator_spec.rb +46 -0
- metadata +4 -2
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
Changelog
|
3
3
|
===========
|
4
4
|
|
5
|
+
v0.0.23
|
6
|
+
-------
|
7
|
+
|
8
|
+
* fix exceptions on unknown validator
|
9
|
+
* fix concerns substitution in parameters
|
10
|
+
* possibility to authenticate the API doc
|
11
|
+
* support for array in api_controllers_matcher
|
12
|
+
|
5
13
|
v0.0.22
|
6
14
|
-------
|
7
15
|
|
data/README.rst
CHANGED
@@ -492,7 +492,7 @@ reload_controllers
|
|
492
492
|
Set to enable/disable reloading controllers (and the documentation with it), by default enabled in development.
|
493
493
|
|
494
494
|
api_controllers_matcher
|
495
|
-
For reloading to work properly you need to specify where your API controllers are.
|
495
|
+
For reloading to work properly you need to specify where your API controllers are. Can be an array if multiple paths are needed
|
496
496
|
|
497
497
|
markup
|
498
498
|
You can choose markup language for descriptions of your application,
|
@@ -517,6 +517,9 @@ namespaced_resources
|
|
517
517
|
Use controller paths instead of controller names as resource id.
|
518
518
|
This prevents same named controllers overwriting each other.
|
519
519
|
|
520
|
+
authenticate
|
521
|
+
Pass a proc in order to authenticate user. Pass nil for
|
522
|
+
no authentication (by default).
|
520
523
|
|
521
524
|
Example:
|
522
525
|
|
@@ -535,6 +538,11 @@ Example:
|
|
535
538
|
This is where you can inform user about your application and API
|
536
539
|
in general.
|
537
540
|
", '1.0'
|
541
|
+
config.authenticate = Proc.new do
|
542
|
+
authenticate_or_request_with_http_basic do |username, password|
|
543
|
+
username == "test" && password == "supersecretpassword"
|
544
|
+
end
|
545
|
+
end
|
538
546
|
end
|
539
547
|
|
540
548
|
|
@@ -3,6 +3,13 @@ module Apipie
|
|
3
3
|
layout Apipie.configuration.layout
|
4
4
|
|
5
5
|
around_filter :set_script_name
|
6
|
+
before_filter :authenticate
|
7
|
+
|
8
|
+
def authenticate
|
9
|
+
if Apipie.configuration.authenticate
|
10
|
+
instance_eval(&Apipie.configuration.authenticate)
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
14
|
def index
|
8
15
|
|
data/lib/apipie/application.rb
CHANGED
data/lib/apipie/configuration.rb
CHANGED
@@ -4,7 +4,7 @@ module Apipie
|
|
4
4
|
attr_accessor :app_name, :app_info, :copyright, :markup, :disqus_shortname,
|
5
5
|
:api_base_url, :doc_base_url, :required_by_default, :layout,
|
6
6
|
:default_version, :debug, :version_in_url, :namespaced_resources,
|
7
|
-
:validate, :validate_value, :validate_presence
|
7
|
+
:validate, :validate_value, :validate_presence, :authenticate
|
8
8
|
|
9
9
|
|
10
10
|
alias_method :validate?, :validate
|
@@ -51,11 +51,9 @@ module Apipie
|
|
51
51
|
|
52
52
|
action_awareness
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
@validator
|
57
|
-
Validator::BaseValidator.find(self, validator, @options, block)
|
58
|
-
raise "Validator not found." unless validator
|
54
|
+
if validator
|
55
|
+
@validator = Validator::BaseValidator.find(self, validator, @options, block)
|
56
|
+
raise "Validator for #{validator} not found." unless @validator
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
@@ -180,16 +178,16 @@ module Apipie
|
|
180
178
|
end
|
181
179
|
|
182
180
|
def concern_subst(string)
|
183
|
-
return if string.nil?
|
181
|
+
return string if string.nil? or !method_description.from_concern?
|
182
|
+
|
184
183
|
original = string
|
185
|
-
if
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
end
|
184
|
+
string = ":#{original}" if original.is_a? Symbol
|
185
|
+
|
186
|
+
replaced = method_description.resource.controller._apipie_perform_concern_subst(string)
|
187
|
+
|
188
|
+
return original if replaced == string
|
189
|
+
return replaced.to_sym if original.is_a? Symbol
|
190
|
+
return replaced
|
193
191
|
end
|
194
192
|
|
195
193
|
end
|
@@ -34,7 +34,7 @@ module Apipie
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class StaticDispatcher
|
37
|
-
# Dispatches the
|
37
|
+
# Dispatches the static files. Similar to ActionDispatch::Static, but
|
38
38
|
# it supports different baseurl configurations
|
39
39
|
def initialize(app, path, baseurl)
|
40
40
|
@app = app
|
data/lib/apipie/validator.rb
CHANGED
data/lib/apipie/version.rb
CHANGED
@@ -95,6 +95,17 @@ describe Apipie::ApipiesController do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
describe "authenticate user" do
|
99
|
+
it "authenticate user if an authentication method is setted" do
|
100
|
+
test = false
|
101
|
+
Apipie.configuration.authenticate = Proc.new do
|
102
|
+
test = true
|
103
|
+
end
|
104
|
+
get :index
|
105
|
+
test.should == true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
98
109
|
describe "documentation cache" do
|
99
110
|
|
100
111
|
let(:cache_dir) { File.join(Rails.root, "tmp", "apipie-cache") }
|
@@ -2,7 +2,7 @@ class ConcernsController < ApplicationController
|
|
2
2
|
|
3
3
|
resource_description { resource_id 'concern_resources' }
|
4
4
|
|
5
|
-
apipie_concern_subst(:concern => 'user', :custom_subst => 'custom')
|
5
|
+
apipie_concern_subst(:concern => 'user', :custom_subst => 'custom', 'string_subst' => 'string')
|
6
6
|
include ::Concerns::SampleController
|
7
7
|
|
8
8
|
end
|
@@ -2,6 +2,17 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Apipie::Application do
|
4
4
|
|
5
|
+
describe "api_controllers_paths" do
|
6
|
+
before { Apipie.configuration.api_controllers_matcher = [File.join(Rails.root, "app", "controllers", "**","*.rb"), File.join(Rails.root, "lib", "**","*.rb")] }
|
7
|
+
|
8
|
+
it "should support receiving array as parameter" do
|
9
|
+
expect { Apipie.api_controllers_paths}.
|
10
|
+
not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
15
|
+
|
5
16
|
describe "get_resource_name" do
|
6
17
|
subject {Apipie.get_resource_name(Api::V2::Nested::ArchitecturesController)}
|
7
18
|
|
@@ -12,6 +12,63 @@ describe Apipie::ParamDescription do
|
|
12
12
|
Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "validator selection" do
|
16
|
+
|
17
|
+
it "should allow nil validator" do
|
18
|
+
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil)
|
19
|
+
param.validator.should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should throw exception on unknown validator" do
|
23
|
+
proc { Apipie::ParamDescription.new(method_desc, :param, :unknown) }.should raise_error(RuntimeError, /Validator.*not found/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should pick type validator" do
|
27
|
+
Apipie::Validator::BaseValidator.should receive(:find).and_return(:validator_instance)
|
28
|
+
param = Apipie::ParamDescription.new(method_desc, :param, String)
|
29
|
+
param.validator.should == :validator_instance
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "concern substitution" do
|
35
|
+
|
36
|
+
let(:concern_dsl_data) { dsl_data.merge(:from_concern => true) }
|
37
|
+
|
38
|
+
let(:concern_resource_desc) do
|
39
|
+
Apipie::ResourceDescription.new(ConcernsController, "concerns")
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:concern_method_desc) do
|
43
|
+
Apipie::MethodDescription.new(:show, concern_resource_desc, concern_dsl_data)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should replace string parameter name with colon prefix" do
|
47
|
+
param = Apipie::ParamDescription.new(concern_method_desc, ":string_subst", String)
|
48
|
+
param.name.should == "string"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should replace symbol parameter name" do
|
52
|
+
param = Apipie::ParamDescription.new(concern_method_desc, :concern, String)
|
53
|
+
param.name.should == :user
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should keep original value for strings without colon prefixes" do
|
57
|
+
param = Apipie::ParamDescription.new(concern_method_desc, "string_subst", String)
|
58
|
+
param.name.should == "string_subst"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should keep the original value when a string can't be replaced" do
|
62
|
+
param = Apipie::ParamDescription.new(concern_method_desc, ":param", String)
|
63
|
+
param.name.should == ":param"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should keep the original value when a symbol can't be replaced" do
|
67
|
+
param = Apipie::ParamDescription.new(concern_method_desc, :param, String)
|
68
|
+
param.name.should == :param
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
15
72
|
|
16
73
|
describe "required_by_default config option" do
|
17
74
|
context "parameters required by default" do
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::Validator do
|
4
|
+
|
5
|
+
let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
|
6
|
+
|
7
|
+
let(:resource_desc) do
|
8
|
+
Apipie::ResourceDescription.new(UsersController, "users")
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:method_desc) do
|
12
|
+
Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:params_desc) do
|
16
|
+
Apipie::ParamDescription.new(method_desc, :param, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'TypeValidator' do
|
20
|
+
|
21
|
+
context "expected type" do
|
22
|
+
|
23
|
+
it "should return hash for type Hash" do
|
24
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Hash)
|
25
|
+
validator.expected_type.should == 'hash'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return array for type Array" do
|
29
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Array)
|
30
|
+
validator.expected_type.should == 'array'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return numeric for type Numeric" do
|
34
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Numeric)
|
35
|
+
validator.expected_type.should == 'numeric'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return string by default" do
|
39
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Symbol)
|
40
|
+
validator.expected_type.should == 'string'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
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.0.
|
4
|
+
version: 0.0.23
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- spec/lib/param_description_spec.rb
|
250
250
|
- spec/lib/param_group_spec.rb
|
251
251
|
- spec/lib/resource_description_spec.rb
|
252
|
+
- spec/lib/validator_spec.rb
|
252
253
|
- spec/spec_helper.rb
|
253
254
|
homepage: http://github.com/Pajk/apipie-rails
|
254
255
|
licenses: []
|
@@ -330,4 +331,5 @@ test_files:
|
|
330
331
|
- spec/lib/param_description_spec.rb
|
331
332
|
- spec/lib/param_group_spec.rb
|
332
333
|
- spec/lib/resource_description_spec.rb
|
334
|
+
- spec/lib/validator_spec.rb
|
333
335
|
- spec/spec_helper.rb
|