apipie-rails 0.1.2 → 0.1.3
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/CHANGELOG.md +6 -0
- data/lib/apipie/param_description.rb +12 -25
- data/lib/apipie/validator.rb +12 -4
- data/lib/apipie/version.rb +1 -1
- data/spec/controllers/concerns_controller_spec.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +1 -1
- data/spec/lib/param_description_spec.rb +53 -1
- data/spec/lib/param_group_spec.rb +6 -6
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -100,32 +100,19 @@ module Apipie
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def to_json
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
:params => validator.hash_params_ordered.map(&:to_json)
|
115
|
-
}
|
116
|
-
else
|
117
|
-
{
|
118
|
-
:name => name.to_s,
|
119
|
-
:full_name => full_name,
|
120
|
-
:description => desc,
|
121
|
-
:required => required,
|
122
|
-
:allow_nil => allow_nil,
|
123
|
-
:validator => validator.to_s,
|
124
|
-
:metadata => metadata,
|
125
|
-
:show => show,
|
126
|
-
:expected_type => validator.expected_type
|
127
|
-
}
|
103
|
+
hash = { :name => name.to_s,
|
104
|
+
:full_name => full_name,
|
105
|
+
:description => desc,
|
106
|
+
:required => required,
|
107
|
+
:allow_nil => allow_nil,
|
108
|
+
:validator => validator.to_s,
|
109
|
+
:expected_type => validator.expected_type,
|
110
|
+
:metadata => metadata,
|
111
|
+
:show => show }
|
112
|
+
if sub_params = validator.params_ordered
|
113
|
+
hash[:params] = sub_params.map(&:to_json)
|
128
114
|
end
|
115
|
+
hash
|
129
116
|
end
|
130
117
|
|
131
118
|
def merge_with(other_param_desc)
|
data/lib/apipie/validator.rb
CHANGED
@@ -70,6 +70,10 @@ module Apipie
|
|
70
70
|
raise NotImplementedError, "Dont know how to merge #{self.inspect} with #{other_validator.inspect}"
|
71
71
|
end
|
72
72
|
|
73
|
+
def params_ordered
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
73
77
|
end
|
74
78
|
|
75
79
|
# validate arguments type
|
@@ -218,8 +222,8 @@ module Apipie
|
|
218
222
|
prepare_hash_params
|
219
223
|
end
|
220
224
|
|
221
|
-
def
|
222
|
-
@
|
225
|
+
def params_ordered
|
226
|
+
@params_ordered ||= _apipie_dsl_data[:params].map do |args|
|
223
227
|
options = args.find { |arg| arg.is_a? Hash }
|
224
228
|
options[:parent] = self.param_description
|
225
229
|
Apipie::ParamDescription.from_dsl_data(param_description.method_description, args)
|
@@ -267,7 +271,7 @@ module Apipie
|
|
267
271
|
|
268
272
|
def merge_with(other_validator)
|
269
273
|
if other_validator.is_a? HashValidator
|
270
|
-
@
|
274
|
+
@params_ordered = ParamDescription.unify(self.params_ordered + other_validator.params_ordered)
|
271
275
|
prepare_hash_params
|
272
276
|
else
|
273
277
|
super
|
@@ -275,7 +279,7 @@ module Apipie
|
|
275
279
|
end
|
276
280
|
|
277
281
|
def prepare_hash_params
|
278
|
-
@hash_params =
|
282
|
+
@hash_params = params_ordered.reduce({}) do |h, param|
|
279
283
|
h.update(param.name.to_sym => param)
|
280
284
|
end
|
281
285
|
end
|
@@ -373,6 +377,10 @@ module Apipie
|
|
373
377
|
def description
|
374
378
|
"Must be an Array of nested elements"
|
375
379
|
end
|
380
|
+
|
381
|
+
def params_ordered
|
382
|
+
@validator.params_ordered
|
383
|
+
end
|
376
384
|
end
|
377
385
|
|
378
386
|
end
|
data/lib/apipie/version.rb
CHANGED
@@ -34,7 +34,7 @@ describe ConcernsController do
|
|
34
34
|
|
35
35
|
it "replaces placeholders in param names and descriptions" do
|
36
36
|
create_desc = Apipie["concern_resources#create"].params[:user]
|
37
|
-
name_param, concern_type_param = create_desc.validator.
|
37
|
+
name_param, concern_type_param = create_desc.validator.params_ordered
|
38
38
|
name_param.desc.should include "Name of a user"
|
39
39
|
concern_type_param.name.should == :user_type
|
40
40
|
end
|
@@ -192,7 +192,7 @@ describe UsersController do
|
|
192
192
|
param = a.params_ordered.select {|p| p.name == :user }
|
193
193
|
param.count.should == 1
|
194
194
|
param.first.validator.class.should eq(Apipie::Validator::HashValidator)
|
195
|
-
hash_params = param.first.validator.
|
195
|
+
hash_params = param.first.validator.params_ordered
|
196
196
|
hash_params.count.should == 4
|
197
197
|
hash_params[0].name == :name
|
198
198
|
hash_params[1].name == :pass
|
@@ -174,7 +174,7 @@ describe Apipie::ParamDescription do
|
|
174
174
|
|
175
175
|
describe "required params in action aware validator" do
|
176
176
|
|
177
|
-
subject { method_description.params[:user].validator.
|
177
|
+
subject { method_description.params[:user].validator.params_ordered }
|
178
178
|
|
179
179
|
let(:required) do
|
180
180
|
subject.find_all(&:required).map(&:name)
|
@@ -240,6 +240,58 @@ describe Apipie::ParamDescription do
|
|
240
240
|
end
|
241
241
|
|
242
242
|
|
243
|
+
describe 'sub params' do
|
244
|
+
|
245
|
+
context 'with HashValidator' do
|
246
|
+
|
247
|
+
subject do
|
248
|
+
Apipie::ParamDescription.new(method_desc, :param, Hash) do
|
249
|
+
param :answer, Fixnum
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should include the nested params in the json" do
|
254
|
+
sub_params = subject.to_json[:params]
|
255
|
+
sub_params.size.should == 1
|
256
|
+
sub_param = sub_params.first
|
257
|
+
sub_param[:name].should == "answer"
|
258
|
+
sub_param[:full_name].should == "param[answer]"
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
context 'with NestedValidator' do
|
264
|
+
|
265
|
+
subject do
|
266
|
+
Apipie::ParamDescription.new(method_desc, :param, Array) do
|
267
|
+
param :answer, Fixnum
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should include the nested params in the json" do
|
272
|
+
sub_params = subject.to_json[:params]
|
273
|
+
sub_params.size.should == 1
|
274
|
+
sub_param = sub_params.first
|
275
|
+
sub_param[:name].should == "answer"
|
276
|
+
sub_param[:full_name].should == "param[answer]"
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'with flat validator' do
|
282
|
+
|
283
|
+
subject do
|
284
|
+
Apipie::ParamDescription.new(method_desc, :param, String)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should include the nested params in the json" do
|
288
|
+
subject.to_json[:params].should be_nil
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
243
295
|
describe "Array with classes" do
|
244
296
|
it "should be valid for objects included in class array" do
|
245
297
|
param = Apipie::ParamDescription.new(method_desc, :param, [Fixnum, String])
|
@@ -4,10 +4,10 @@ describe "param groups" do
|
|
4
4
|
|
5
5
|
it "lets reuse the params description in more actions" do
|
6
6
|
user_create_desc = Apipie["users#create"].params[:user]
|
7
|
-
user_create_params = user_create_desc.validator.
|
7
|
+
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
8
8
|
|
9
9
|
user_update_desc = Apipie["users#update"].params[:user]
|
10
|
-
user_update_params = user_update_desc.validator.
|
10
|
+
user_update_params = user_update_desc.validator.params_ordered.map(&:name)
|
11
11
|
|
12
12
|
common = user_update_params & user_create_params
|
13
13
|
common.sort_by(&:to_s).should == user_update_params.sort_by(&:to_s)
|
@@ -15,13 +15,13 @@ describe "param groups" do
|
|
15
15
|
|
16
16
|
it "allows using groups is nested param descriptions" do
|
17
17
|
user_create_desc = Apipie["users#update"].params[:user]
|
18
|
-
user_create_params = user_create_desc.validator.
|
18
|
+
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
19
19
|
user_create_params.map(&:to_s).sort.should == %w[membership name pass]
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should allow adding additional params to group" do
|
23
23
|
user_create_desc = Apipie["users#create"].params[:user]
|
24
|
-
user_create_params = user_create_desc.validator.
|
24
|
+
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
25
25
|
user_create_params.map(&:to_s).sort.should == %w[membership name pass permalink]
|
26
26
|
end
|
27
27
|
|
@@ -34,10 +34,10 @@ describe "param groups" do
|
|
34
34
|
|
35
35
|
it "lets you reuse a group definition from different controller" do
|
36
36
|
arch_v1_desc = Apipie["1.0#architectures#create"].params[:architecture]
|
37
|
-
arch_v1_params = arch_v1_desc.validator.
|
37
|
+
arch_v1_params = arch_v1_desc.validator.params_ordered.map(&:name)
|
38
38
|
|
39
39
|
arch_v2_desc = Apipie["2.0#architectures#create"].params[:architecture]
|
40
|
-
arch_v2_params = arch_v2_desc.validator.
|
40
|
+
arch_v2_params = arch_v2_desc.validator.params_ordered.map(&:name)
|
41
41
|
|
42
42
|
arch_v1_params.sort_by(&:to_s).should == arch_v2_params.sort_by(&:to_s)
|
43
43
|
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.1.
|
4
|
+
version: 0.1.3
|
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: 2014-
|
13
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|