introspective_grape 0.3.3 → 0.4.0
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 +5 -5
- data/.travis.yml +5 -52
- data/CHANGELOG.md +46 -0
- data/Gemfile +2 -0
- data/README.md +15 -0
- data/gemfiles/{Gemfile.rails.4.2.7.1 → Gemfile.rails.5.0.0} +5 -4
- data/gemfiles/Gemfile.rails.5.0.1 +1 -0
- data/gemfiles/{Gemfile.rails.4.2.7.1.new.swagger → Gemfile.rails.5.1.0} +5 -3
- data/gemfiles/{Gemfile.rails.3.2.22 → Gemfile.rails.5.2.0} +5 -4
- data/gemfiles/Gemfile.rails.master +1 -0
- data/introspective_grape.gemspec +15 -13
- data/lib/introspective_grape.rb +1 -1
- data/lib/introspective_grape/api.rb +38 -31
- data/lib/introspective_grape/camel_snake.rb +30 -31
- data/lib/introspective_grape/create_helpers.rb +8 -3
- data/lib/introspective_grape/version.rb +1 -1
- data/spec/dummy/Gemfile +6 -3
- data/spec/dummy/app/api/api_helpers.rb +2 -0
- data/spec/dummy/app/api/dummy/company_api.rb +1 -1
- data/spec/dummy/app/models/image.rb +1 -1
- data/spec/dummy/app/models/role.rb +1 -1
- data/spec/dummy/app/models/user.rb +2 -2
- data/spec/dummy/config.ru +12 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/initializers/paperclip_adapter.rb +1 -1
- data/spec/dummy/db/migrate/20190325231304_add_test_data.rb +5 -0
- data/spec/dummy/db/schema.rb +154 -173
- data/spec/requests/chat_api_spec.rb +26 -26
- data/spec/requests/company_api_spec.rb +15 -15
- data/spec/requests/location_api_spec.rb +18 -18
- data/spec/requests/project_api_spec.rb +21 -21
- data/spec/requests/role_api_spec.rb +4 -4
- data/spec/requests/sessions_api_spec.rb +10 -10
- data/spec/requests/swagger_spec.rb +1 -1
- data/spec/requests/user_api_spec.rb +34 -34
- metadata +33 -44
- data/gemfiles/2.0.0-Gemfile +0 -22
- data/gemfiles/2.2.0-Gemfile +0 -21
- data/gemfiles/Gemfile.rails.4.1.13 +0 -13
- data/gemfiles/Gemfile.rails.4.2.8 +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d1070be152294dd627fb6f0e98038ae626412ddd716dd1ae97137de93b1b0d70
|
|
4
|
+
data.tar.gz: 12fe0f44356159f58a8482b297a4e2268b9a4da3281be1e8cd1599bd1d2f0bc0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d3086df6face4380f6596be5b9dea2dc61a72e3672c2e74a175e9236cd0a18fcac749e2eeef1a8df8724e232ac816c0ca9cdec425da7a3912c997a3f91b1037
|
|
7
|
+
data.tar.gz: eee38bbee623810f27dd48d925cc456abd3a6ccbcb8773cfb4945afea29aa5da92bc6f61cbd57601f0c5ed613b4f9c4a839621bc91f33e727282d66d96e4e9ff
|
data/.travis.yml
CHANGED
|
@@ -1,76 +1,29 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
before_install:
|
|
3
|
-
- gem install bundler
|
|
3
|
+
- gem install bundler -v 1.17.3
|
|
4
4
|
install: bundle install --jobs=1 --retry=1
|
|
5
5
|
script:
|
|
6
6
|
- bundle install
|
|
7
7
|
- bundle exec rspec
|
|
8
8
|
|
|
9
9
|
rvm:
|
|
10
|
-
- 2.
|
|
11
|
-
- 2.1.0
|
|
12
|
-
- 2.2.0
|
|
13
|
-
- 2.2.6
|
|
14
|
-
- 2.3.0
|
|
10
|
+
- 2.3.1
|
|
15
11
|
- 2.4.0
|
|
12
|
+
- 2.5.0
|
|
16
13
|
- ruby-head
|
|
17
14
|
- jruby-head
|
|
18
15
|
gemfile:
|
|
19
|
-
# - gemfiles/Gemfile.rails.3.2.22
|
|
20
|
-
# - gemfiles/Gemfile.rails.4.1.13
|
|
21
|
-
- gemfiles/Gemfile.rails.4.2.7.1
|
|
22
|
-
- gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
23
|
-
- gemfiles/Gemfile.rails.4.2.8
|
|
24
16
|
- gemfiles/Gemfile.rails.5.0.1
|
|
17
|
+
- gemfiles/Gemfile.rails.5.1.0
|
|
18
|
+
- gemfiles/Gemfile.rails.5.2.0
|
|
25
19
|
- gemfiles/Gemfile.rails.master
|
|
26
20
|
|
|
27
21
|
matrix:
|
|
28
22
|
exclude:
|
|
29
|
-
# We'll have to back up to grape-swagger 0.11 for earlier rubies.
|
|
30
|
-
- rvm: 2.0.0
|
|
31
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
32
|
-
- rvm: 2.0.0
|
|
33
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
|
34
|
-
- rvm: 2.0.0
|
|
35
|
-
gemfile: gemfiles/Gemfile.rails.5.0.1
|
|
36
|
-
- rvm: 2.0.0
|
|
37
|
-
gemfile: gemfiles/Gemfile.rails.master
|
|
38
|
-
- rvm: 2.1.0
|
|
39
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
40
|
-
- rvm: 2.1.0
|
|
41
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
|
42
|
-
- rvm: 2.1.0
|
|
43
|
-
gemfile: gemfiles/Gemfile.rails.5.0.1
|
|
44
|
-
- rvm: 2.1.0
|
|
45
|
-
gemfile: gemfiles/Gemfile.rails.master
|
|
46
|
-
- rvm: 2.2.0
|
|
47
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
48
|
-
- rvm: 2.2.0
|
|
49
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
|
50
|
-
- rvm: 2.2.0
|
|
51
|
-
gemfile: gemfiles/Gemfile.rails.5.0.1
|
|
52
|
-
- rvm: 2.2.0
|
|
53
|
-
gemfile: gemfiles/Gemfile.rails.master
|
|
54
|
-
- rvm: 2.4.0
|
|
55
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1
|
|
56
|
-
- rvm: 2.4.0
|
|
57
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
58
|
-
- rvm: jruby-9.0.4.0
|
|
59
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
60
|
-
- rvm: jruby-9.0.4.0
|
|
61
|
-
gemfile: gemfiles/Gemfile.rails.4.2.8
|
|
62
23
|
- rvm: jruby-9.0.4.0
|
|
63
24
|
gemfile: gemfiles/Gemfile.rails.5.0.1
|
|
64
25
|
- rvm: jruby-9.0.4.0
|
|
65
26
|
gemfile: gemfiles/Gemfile.rails.master
|
|
66
|
-
- rvm: ruby-head
|
|
67
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1
|
|
68
|
-
- rvm: ruby-head
|
|
69
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
70
|
-
- rvm: jruby-head
|
|
71
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1
|
|
72
|
-
- rvm: jruby-head
|
|
73
|
-
gemfile: gemfiles/Gemfile.rails.4.2.7.1.new.swagger
|
|
74
27
|
allow_failures:
|
|
75
28
|
- rvm: ruby-head
|
|
76
29
|
- rvm: jruby-head
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
|
|
2
|
+
0.4.0 10/20/2020
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
Add an `IntrospectiveGrape.config.skip_object_reload = true` option.
|
|
6
|
+
|
|
7
|
+
0.3.9 04/01/2019
|
|
8
|
+
================
|
|
9
|
+
|
|
10
|
+
Add a note to the README that pagination will have to be supported via alexey-klimuk's fork of grape-kaminari from years ago because the middleware support gems have stopped being maintained, and rubygems doesn't support targeting github branches when adding dependencies.
|
|
11
|
+
|
|
12
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
|
13
|
+
|
|
14
|
+
Probably we'll just fork it if nobody else can be bothered.
|
|
15
|
+
|
|
16
|
+
0.3.8 03/27/2019
|
|
17
|
+
================
|
|
18
|
+
|
|
19
|
+
Support the latest Grape.
|
|
20
|
+
|
|
21
|
+
0.3.7 03/26/2019
|
|
22
|
+
================
|
|
23
|
+
|
|
24
|
+
Updated to support Grape ~> 1.2.0. Ruby 2.2 no longer supported.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
0.3.7 03/25/2019
|
|
28
|
+
================
|
|
29
|
+
|
|
30
|
+
Updated to support Grape <~ 1.1.0.
|
|
31
|
+
|
|
32
|
+
0.3.6 03/23/2019
|
|
33
|
+
================
|
|
34
|
+
|
|
35
|
+
Updated to support Rails 5+.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
0.3.5 09/14/2018
|
|
39
|
+
================
|
|
40
|
+
|
|
41
|
+
Restrict IntrospectiveGrape to Rails <5.0 and Pundit <2.0. We aren't Rails 5 compat until either schema_plus is or we find an alternative. Pundit 2.0 very strangely makes 'authorize' a protected method and we haven't made time to investigate.
|
|
42
|
+
|
|
43
|
+
The big update in 0.3 is that the PUT/POST actions used to reload the model on presentation (hooks elsewhere may leave a model that's been updated out of sync with the database, so the overhead seems to be necessary) without using the default_includes for eager loading, causing some N+1 problems that could be alleviated.
|
|
44
|
+
|
|
45
|
+
The general strategy of passing the params of a nested endpoint to the root model and then reloading it and burrowing down to the leaf for presentation, while simpler to implement, was really not optimal and creates a lot of unnecessary overhead like that.
|
|
46
|
+
|
|
47
|
+
|
|
2
48
|
0.2.9 04/06/2017
|
|
3
49
|
================
|
|
4
50
|
|
data/Gemfile
CHANGED
|
@@ -5,6 +5,8 @@ source 'https://rubygems.org'
|
|
|
5
5
|
# development dependencies will be added by default to the :development group.
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
|
9
|
+
|
|
8
10
|
gem 'coveralls', require: false
|
|
9
11
|
|
|
10
12
|
# Declare any dependencies that are still in development here instead of in
|
data/README.md
CHANGED
|
@@ -40,6 +40,7 @@ can speak in their own idioms.
|
|
|
40
40
|
In your Gemfile:
|
|
41
41
|
|
|
42
42
|
```
|
|
43
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari' # some middleware has fallen into deep disrepair
|
|
43
44
|
gem 'introspective_grape'
|
|
44
45
|
```
|
|
45
46
|
|
|
@@ -48,6 +49,8 @@ And bundle install.
|
|
|
48
49
|
|
|
49
50
|
## Grape Configuration
|
|
50
51
|
|
|
52
|
+
### Camelization
|
|
53
|
+
|
|
51
54
|
IntrospectiveGrape's default behavior is to camelize all outputs and snake case all inputs. To camel case all your json output you'll need to use its formatter in your API:
|
|
52
55
|
|
|
53
56
|
```
|
|
@@ -60,6 +63,18 @@ You can disable this behavior by setting `IntrospectiveGrape.config.camelize_par
|
|
|
60
63
|
|
|
61
64
|
To include this behavior in your test coverage you need to either access the API's params hash or you can format the response body to `JSON.parse(response.body).with_snake_keys` in a helper method with the `using CamelSnakeKeys` refinement.
|
|
62
65
|
|
|
66
|
+
### Reloading an object after an update request
|
|
67
|
+
|
|
68
|
+
By default the gem reloads the object instance before presenting the updated model, a lazy but
|
|
69
|
+
effective workaround to updates that may not propagate in the working instance due to actions
|
|
70
|
+
a user may take in hooks, or some updates to has_many :through associations. We want to put up
|
|
71
|
+
APIs with haste rather than digging our way out of tricky minutae that can be handled later as
|
|
72
|
+
technical debt.
|
|
73
|
+
|
|
74
|
+
This behavior can be disabled by setting `IntrospectiveGrape.config.skip_object_reload = true`,
|
|
75
|
+
when you have time for technical debt you can toggle it and work on fixing broken tests (you
|
|
76
|
+
did take the time to write comprehensive test coverage, didn't you?).
|
|
77
|
+
|
|
63
78
|
## Authentication and authorization
|
|
64
79
|
|
|
65
80
|
Authentication and authorization are presently enforced on every endpoint. If you have named the authentication helper method in Grape something other than "authenticate!" or "authorize!" you can set it with:
|
|
@@ -2,10 +2,11 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec :path => '../'
|
|
4
4
|
|
|
5
|
-
gem 'rails', '
|
|
6
|
-
gem 'grape'
|
|
7
|
-
gem 'grape-
|
|
8
|
-
gem '
|
|
5
|
+
gem 'rails', '5.0.0'
|
|
6
|
+
gem 'grape'
|
|
7
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
|
8
|
+
gem 'grape-swagger'
|
|
9
|
+
gem 'nokogiri'
|
|
9
10
|
gem 'coveralls', require: false
|
|
10
11
|
|
|
11
12
|
group :development,:test do
|
|
@@ -2,9 +2,11 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec :path => '../'
|
|
4
4
|
|
|
5
|
-
gem 'rails', '
|
|
6
|
-
gem 'grape'
|
|
7
|
-
gem 'grape-
|
|
5
|
+
gem 'rails', '5.1.0'
|
|
6
|
+
gem 'grape'
|
|
7
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
|
8
|
+
gem 'grape-swagger'
|
|
9
|
+
gem 'nokogiri'
|
|
8
10
|
gem 'coveralls', require: false
|
|
9
11
|
|
|
10
12
|
group :development,:test do
|
|
@@ -2,10 +2,11 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec :path => '../'
|
|
4
4
|
|
|
5
|
-
gem 'rails', '
|
|
6
|
-
gem 'grape'
|
|
7
|
-
gem 'grape-
|
|
8
|
-
gem '
|
|
5
|
+
gem 'rails', '5.2.0'
|
|
6
|
+
gem 'grape'
|
|
7
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
|
8
|
+
gem 'grape-swagger'
|
|
9
|
+
gem 'nokogiri'
|
|
9
10
|
gem 'coveralls', require: false
|
|
10
11
|
|
|
11
12
|
group :development,:test do
|
data/introspective_grape.gemspec
CHANGED
|
@@ -18,23 +18,25 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.files = `git ls-files`.split("\n").sort
|
|
19
19
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
20
20
|
|
|
21
|
-
s.required_ruby_version = '
|
|
22
|
-
|
|
23
|
-
s.add_dependency "rails", '
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
s.add_dependency 'grape
|
|
27
|
-
s.add_dependency 'grape-
|
|
28
|
-
s.add_dependency '
|
|
29
|
-
s.add_dependency '
|
|
30
|
-
s.add_dependency '
|
|
21
|
+
s.required_ruby_version = '>= 2.3'
|
|
22
|
+
|
|
23
|
+
s.add_dependency "rails", '> 5.0.0'
|
|
24
|
+
|
|
25
|
+
# grape 1.0.0 breaks the pagination solution
|
|
26
|
+
s.add_dependency 'grape', ['~> 1.2.0', '< 1.2.5']
|
|
27
|
+
s.add_dependency 'grape-entity'
|
|
28
|
+
s.add_dependency 'grape-swagger'
|
|
29
|
+
s.add_dependency 'kaminari' #, '< 1.0' # version 1.0.0 breaks
|
|
30
|
+
#s.add_dependency 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
|
31
|
+
# Pundit 2.0 mysteriously made authorize a protected method...
|
|
32
|
+
s.add_dependency 'pundit' #, '<2.0'
|
|
31
33
|
s.add_dependency 'camel_snake_keys', '>0.0.4'
|
|
32
34
|
|
|
33
35
|
if RUBY_PLATFORM == 'java'
|
|
34
36
|
#s.add_development_dependency "jdbc-sqlite3"
|
|
35
37
|
s.add_development_dependency "activerecord-jdbcsqlite3-adapter"
|
|
36
38
|
else
|
|
37
|
-
s.add_development_dependency "sqlite3"
|
|
39
|
+
s.add_development_dependency "sqlite3", '<1.4.0' #'< 1.3.14'
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
#s.add_development_dependency "byebug"
|
|
@@ -42,8 +44,8 @@ Gem::Specification.new do |s|
|
|
|
42
44
|
s.add_development_dependency "rspec-rails", '>= 3.0'
|
|
43
45
|
s.add_development_dependency 'devise'
|
|
44
46
|
#s.add_development_dependency 'devise-async'
|
|
45
|
-
s.add_development_dependency 'paperclip', '< 5.0'
|
|
46
|
-
s.add_development_dependency '
|
|
47
|
+
s.add_development_dependency 'paperclip', ">= 5.2.0" #'< 5.0'
|
|
48
|
+
s.add_development_dependency 'machinist_redux'
|
|
47
49
|
s.add_development_dependency 'simplecov'
|
|
48
50
|
s.add_development_dependency 'rufus-mnemo'
|
|
49
51
|
|
data/lib/introspective_grape.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'action_controller'
|
|
2
|
+
require 'kaminari'
|
|
2
3
|
require 'grape-kaminari'
|
|
3
4
|
require 'introspective_grape/validators'
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ class IntrospectiveGrapeError < StandardError
|
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
module IntrospectiveGrape
|
|
9
|
-
class API < Grape::API
|
|
10
|
+
class API < Grape::API::Instance
|
|
10
11
|
extend IntrospectiveGrape::Helpers
|
|
11
12
|
extend IntrospectiveGrape::CreateHelpers
|
|
12
13
|
extend IntrospectiveGrape::Filters
|
|
@@ -125,6 +126,34 @@ module IntrospectiveGrape
|
|
|
125
126
|
end
|
|
126
127
|
end
|
|
127
128
|
|
|
129
|
+
def convert_nested_params_hash(dsl, routes)
|
|
130
|
+
root = routes.first
|
|
131
|
+
klass = root.klass
|
|
132
|
+
dsl.after_validation do
|
|
133
|
+
# After Grape validates its parameters:
|
|
134
|
+
# 1) Find the root model instance for the API if its passed (implicitly either
|
|
135
|
+
# an update/destroy on the root node or it's a nested route
|
|
136
|
+
# 2) For nested endpoints convert the params hash into Rails-compliant nested
|
|
137
|
+
# attributes, to be passed to the root instance for update. This keeps
|
|
138
|
+
# behavior consistent between bulk and single record updates.
|
|
139
|
+
|
|
140
|
+
if params[root.key]
|
|
141
|
+
@model = root.model.includes( klass.default_includes(root.model) ).find(params[root.key])
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
if routes.size > 1
|
|
145
|
+
nested_attributes = klass.build_nested_attributes(routes[1..-1], params.except(root.key,:api_key) )
|
|
146
|
+
@params.merge!( nested_attributes ) if nested_attributes.kind_of?(Hash)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def define_restful_api(dsl, routes, model, api_params)
|
|
152
|
+
# declare index, show, update, create, and destroy methods:
|
|
153
|
+
API_ACTIONS.each do |action|
|
|
154
|
+
send("define_#{action}", dsl, routes, model, api_params) unless exclude_actions(model).include?(action)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
128
157
|
|
|
129
158
|
def define_endpoints(routes,api_params)
|
|
130
159
|
# De-reference these as local variables from their class scope, or when we make
|
|
@@ -145,13 +174,6 @@ module IntrospectiveGrape
|
|
|
145
174
|
end
|
|
146
175
|
end
|
|
147
176
|
|
|
148
|
-
def define_restful_api(dsl, routes, model, api_params)
|
|
149
|
-
# declare index, show, update, create, and destroy methods:
|
|
150
|
-
API_ACTIONS.each do |action|
|
|
151
|
-
send("define_#{action}", dsl, routes, model, api_params) unless exclude_actions(model).include?(action)
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
177
|
def define_index(dsl, routes, model, api_params)
|
|
156
178
|
include Grape::Kaminari
|
|
157
179
|
root = routes.first
|
|
@@ -225,8 +247,15 @@ module IntrospectiveGrape
|
|
|
225
247
|
authorize @model, :update?
|
|
226
248
|
|
|
227
249
|
@model.update_attributes!( safe_params(params).permit(klass.whitelist) )
|
|
250
|
+
|
|
251
|
+
default_includes = routes.first.klass.default_includes(routes.first.model)
|
|
228
252
|
|
|
229
|
-
|
|
253
|
+
if IntrospectiveGrape.config.skip_object_reload
|
|
254
|
+
present klass.find_leaf(routes, @model, params), with: "#{klass}::#{model}Entity".constantize
|
|
255
|
+
else
|
|
256
|
+
default_includes = routes.first.klass.default_includes(routes.first.model)
|
|
257
|
+
present klass.find_leaf(routes, @model.class.includes(default_includes).find(@model.id), params), with: "#{klass}::#{model}Entity".constantize
|
|
258
|
+
end
|
|
230
259
|
end
|
|
231
260
|
end
|
|
232
261
|
|
|
@@ -242,28 +271,6 @@ module IntrospectiveGrape
|
|
|
242
271
|
end
|
|
243
272
|
end
|
|
244
273
|
|
|
245
|
-
def convert_nested_params_hash(dsl, routes)
|
|
246
|
-
root = routes.first
|
|
247
|
-
klass = root.klass
|
|
248
|
-
dsl.after_validation do
|
|
249
|
-
# After Grape validates its parameters:
|
|
250
|
-
# 1) Find the root model instance for the API if its passed (implicitly either
|
|
251
|
-
# an update/destroy on the root node or it's a nested route
|
|
252
|
-
# 2) For nested endpoints convert the params hash into Rails-compliant nested
|
|
253
|
-
# attributes, to be passed to the root instance for update. This keeps
|
|
254
|
-
# behavior consistent between bulk and single record updates.
|
|
255
|
-
if params[root.key]
|
|
256
|
-
default_includes = routes.size > 1 ? [] : klass.default_includes(root.model)
|
|
257
|
-
@model = root.model.includes( default_includes ).find(params[root.key])
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
if routes.size > 1
|
|
261
|
-
nested_attributes = klass.build_nested_attributes(routes[1..-1], params.except(root.key,:api_key) )
|
|
262
|
-
@params.merge!( nested_attributes ) if nested_attributes.kind_of?(Hash)
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
end
|
|
266
|
-
|
|
267
274
|
|
|
268
275
|
def build_routes(routes, model, reflection_name=nil)
|
|
269
276
|
routes = routes.clone
|
|
@@ -5,49 +5,48 @@ require 'active_support/inflector/methods'
|
|
|
5
5
|
if IntrospectiveGrape.config.camelize_parameters
|
|
6
6
|
# Camelize the parameters in the swagger documentation.
|
|
7
7
|
if Gem::Version.new( GrapeSwagger::VERSION ) <= Gem::Version.new('0.11.0')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.camelize(:lower)
|
|
20
|
-
.gsub(/Destroy/,'_destroy')
|
|
21
|
-
end
|
|
22
|
-
parsed_params
|
|
23
|
-
end
|
|
8
|
+
module ParseParamsWithCamelized
|
|
9
|
+
def parse_params(params, path, method, _options = {})
|
|
10
|
+
parsed_params = parse_params_without_camelized(params, path, method)
|
|
11
|
+
parsed_params.each_with_index do |param|
|
|
12
|
+
param[:name] = param[:name]
|
|
13
|
+
.camelize(:lower)
|
|
14
|
+
.gsub(/Destroy/,'_destroy')
|
|
15
|
+
end
|
|
16
|
+
super(params, path, method, _options = {})
|
|
17
|
+
end
|
|
18
|
+
end
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
module CreateCamelizedDocumentationClass
|
|
21
|
+
private
|
|
22
|
+
def create_documentation_class
|
|
23
|
+
doc = super
|
|
24
|
+
doc.class_eval do
|
|
25
|
+
doc.singleton_class.send(:prepend, ParseParamsWithCamelized)
|
|
29
26
|
end
|
|
30
|
-
|
|
27
|
+
doc
|
|
31
28
|
end
|
|
32
29
|
end
|
|
30
|
+
|
|
31
|
+
Grape::API::Instance.singleton_class.send(:prepend, CreateCamelizedDocumentationClass)
|
|
33
32
|
else
|
|
33
|
+
module CallWithCamelized
|
|
34
|
+
def call(*args)
|
|
35
|
+
param = super(*args)
|
|
36
|
+
param[:name] = param[:name].camelize(:lower).gsub(/Destroy/, '_destroy')
|
|
37
|
+
param
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
GrapeSwagger::DocMethods::ParseParams.singleton_class.send(:prepend, CallWithCamelized)
|
|
34
42
|
module GrapeSwagger
|
|
35
43
|
module DocMethods
|
|
36
44
|
def self.extended(mod)
|
|
37
45
|
# Do not camelize the grape-swagger documentation endpoints.
|
|
38
46
|
mod.formatter :json, Grape::Formatter::Json
|
|
39
47
|
end
|
|
40
|
-
class ParseParams
|
|
41
|
-
class << self
|
|
42
|
-
def call_with_camelized(*args)
|
|
43
|
-
param = call_without_camelized(*args)
|
|
44
|
-
param[:name] = param[:name].camelize(:lower).gsub(/Destroy/, '_destroy')
|
|
45
|
-
param
|
|
46
|
-
end
|
|
47
|
-
alias_method_chain :call, :camelized
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
48
|
end
|
|
51
49
|
end
|
|
52
50
|
end
|
|
51
|
+
|
|
53
52
|
end
|