introspective_grape 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83d87bcd4a1b094140084f652e87311d763b4259
4
- data.tar.gz: ad9cc7c59b4675a4b105e656c3bc82e7a6db2b45
3
+ metadata.gz: f52e3f6200f277c190a76450e09f65c582a9e56d
4
+ data.tar.gz: f2779c6afdfa697bc4d051d3ab461d9afcb91e6f
5
5
  SHA512:
6
- metadata.gz: d1e241e2e6b14512efe1b3da193f3a382def1c7a953dc9790d4b6680f68b1168b2397d45be5a09e2641eb7b5e5a392f31e42a37148aec9e394e40a176c25b8cf
7
- data.tar.gz: aa769217ebffabc67b73732108c7e56c77482e6bd48a6ff8b929f35bfd3491f99ea3881b08f2c02e8534957add7941687a47b7bf81db5b5a4963df7e86d588da
6
+ metadata.gz: fc38af247ee9f040212122583701537567fc3a6551339c35034f88a0edef5acea6ed79b020fb7d5f3d16dddcc299bd12b882870d1a90826220bf00b6d8bfbb51
7
+ data.tar.gz: 08b47cd609c1501a9eeeb4293d5dc3dee9a97028c814aef22a9930f543ba529439358258f2b75a0f7af0d00597d5b73fb6d58ed57738683b6f7c397f384296e9
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ 0.2.5 10/28/2016
3
+ ==============
4
+
5
+ ### Bug Fix
6
+
7
+ Include the nested model IDs in the swagger doc.
8
+
2
9
  0.2.4 10/26/2016
3
10
  ==============
4
11
 
@@ -204,7 +204,7 @@ module IntrospectiveGrape
204
204
  detail klass.create_documentation || "creates a new #{name} record"
205
205
  end
206
206
  dsl.params do
207
- klass.generate_params(self, klass, :create, model, api_params)
207
+ klass.generate_params(self, :create, model, api_params, true)
208
208
  end
209
209
  dsl.post do
210
210
  if @model
@@ -225,7 +225,7 @@ module IntrospectiveGrape
225
225
  detail klass.update_documentation || "updates the details of a #{name}"
226
226
  end
227
227
  dsl.params do
228
- klass.generate_params(self, klass, :update, model, api_params)
228
+ klass.generate_params(self, :update, model, api_params, true)
229
229
  end
230
230
  dsl.put ":#{routes.last.swaggerKey}" do
231
231
  authorize @model, :update?
@@ -316,35 +316,36 @@ module IntrospectiveGrape
316
316
 
317
317
 
318
318
 
319
- def generate_params(dsl, klass, action, model, fields)
319
+ def generate_params(dsl, action, model, fields, is_root_endpoint=false)
320
320
  # We'll be doing a recursive walk (to handle nested attributes) down the
321
321
  # whitelisted params, generating the Grape param definitions by introspecting
322
322
  # on the model and its associations.
323
323
  raise "Invalid action: #{action}" unless [:update, :create].include?(action)
324
324
  # dsl : The Grape::Validations::ParamsScope object
325
- # klass : A reference back to the original descendant of IntrospectiveGrape::API.
326
- # You have to pass this around to remember who you were before the DSL
327
- # scope hijacked your identity.
328
325
  # action: create or update
329
326
  # model : The ActiveRecord model class
330
327
  # fields: The whitelisted data structure for Rails' strong params, from which we
331
328
  # infer Grape's parameters
329
+
330
+ # skip the ID param at the root level endpoint, so we don't duplicate the URL parameter (api/v#/model/modelId)
331
+ fields -= [:id] if is_root_endpoint
332
332
 
333
- (fields-[:id]).each do |field|
333
+ fields.each do |field|
334
334
  if field.kind_of?(Hash)
335
- generate_nested_params(dsl,klass,action,model,field)
336
- elsif (action==:create && klass.param_required?(model,field) )
335
+ generate_nested_params(dsl,action,model,field)
336
+ elsif (action==:create && param_required?(model,field) )
337
337
  # All params are optional on an update, only require them during creation.
338
338
  # Updating a record with new child models will have to rely on ActiveRecord
339
339
  # validations:
340
- dsl.requires field, type: klass.param_type(model,field)
340
+ dsl.requires field, type: param_type(model,field)
341
341
  else
342
- dsl.optional field, type: klass.param_type(model,field)
342
+ dsl.optional field, type: param_type(model,field)
343
343
  end
344
344
  end
345
345
  end
346
346
 
347
- def generate_nested_params(dsl,klass,action,model,fields)
347
+ def generate_nested_params(dsl,action,model,fields)
348
+ klass = self
348
349
  fields.each do |r,v|
349
350
  # Look at model.reflections to find the association's class name:
350
351
  reflection = r.to_s.sub(/_attributes$/,'') # the reflection name
@@ -360,7 +361,7 @@ module IntrospectiveGrape
360
361
  # In case you need a refresher on how these work:
361
362
  # http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
362
363
  dsl.optional r, type: Array do |dl|
363
- klass.generate_params(dl,klass,action,relation,v)
364
+ klass.generate_params(dl,action,relation,v)
364
365
  klass.add_destroy_param(dl,model,reflection) unless action==:create
365
366
  end
366
367
  else
@@ -369,7 +370,7 @@ module IntrospectiveGrape
369
370
  # ThroughReflection, HasOneReflection,
370
371
  # HasAndBelongsToManyReflection, BelongsToReflection
371
372
  dsl.optional r, type: Hash do |dl|
372
- klass.generate_params(dl,klass,action,relation,v)
373
+ klass.generate_params(dl,action,relation,v)
373
374
  klass.add_destroy_param(dl,model,reflection) unless action==:create
374
375
  end
375
376
  end
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveGrape
2
- VERSION = "0.2.4".freeze
2
+ VERSION = "0.2.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: introspective_grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-27 00:00:00.000000000 Z
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails