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.
@@ -2,6 +2,12 @@
2
2
  Changelog
3
3
  ===========
4
4
 
5
+ v0.1.3
6
+ ------
7
+
8
+ * nested attributes showing in the documentation
9
+ [#230](https://github.com/Apipie/apipie-rails/pull/230) [@iNecas][]
10
+
5
11
  v0.1.2
6
12
  ------
7
13
 
@@ -100,32 +100,19 @@ module Apipie
100
100
  end
101
101
 
102
102
  def to_json
103
- if validator.is_a? Apipie::Validator::HashValidator
104
- {
105
- :name => name.to_s,
106
- :full_name => full_name,
107
- :description => desc,
108
- :required => required,
109
- :allow_nil => allow_nil,
110
- :validator => validator.to_s,
111
- :expected_type => validator.expected_type,
112
- :metadata => metadata,
113
- :show => show,
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)
@@ -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 hash_params_ordered
222
- @hash_params_ordered ||= _apipie_dsl_data[:params].map do |args|
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
- @hash_params_ordered = ParamDescription.unify(self.hash_params_ordered + other_validator.hash_params_ordered)
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 = hash_params_ordered.reduce({}) do |h, param|
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
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -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.hash_params_ordered
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.hash_params_ordered
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.hash_params_ordered }
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.hash_params_ordered.map(&:name)
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.hash_params_ordered.map(&:name)
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.hash_params_ordered.map(&:name)
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.hash_params_ordered.map(&:name)
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.hash_params_ordered.map(&:name)
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.hash_params_ordered.map(&:name)
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.2
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-03-20 00:00:00.000000000 Z
13
+ date: 2014-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails