introspective_grape 0.3.5 → 0.4.1
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 +40 -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 +13 -12
- data/lib/introspective_grape.rb +3 -1
- data/lib/introspective_grape/api.rb +36 -31
- data/lib/introspective_grape/camel_snake.rb +30 -31
- data/lib/introspective_grape/configuration.rb +15 -0
- data/lib/introspective_grape/create_helpers.rb +2 -2
- 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/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 -36
- metadata +49 -51
- 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: 3034e0ca4ea70e3b33f6971169aa59faae640f4d43272fa1152293abf693651b
|
4
|
+
data.tar.gz: ea99ca40acf330e9a5136ef0789ab59737333b88fdaeec54027b4812aa9669f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 946339968ec6dc500c349751582d2b7c0b280522c2942ed152d8a5f8828b576ed1ddb9b118d849a2e00bbcebb352512ac5fb7465b047552f6269a4e40be2794c
|
7
|
+
data.tar.gz: 1f14f292c04fb776c12665adb84e46b81d75b26a7ba90cc0187f7b2f9b59a35f0265ead685ba612f5e5b1763a3ff992ddd372ef456db2447a678f0ae5afe1238
|
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,3 +1,43 @@
|
|
1
|
+
0.4.1 10/20/2020
|
2
|
+
================
|
3
|
+
|
4
|
+
We can't expect to ever release a 1.0 if the configuration object doesn't actually persist from the initializer.
|
5
|
+
|
6
|
+
0.4.0 10/20/2020
|
7
|
+
================
|
8
|
+
|
9
|
+
Add an `IntrospectiveGrape.config.skip_object_reload = true` option.
|
10
|
+
|
11
|
+
0.3.9 04/01/2019
|
12
|
+
================
|
13
|
+
|
14
|
+
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.
|
15
|
+
|
16
|
+
gem 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
17
|
+
|
18
|
+
Probably we'll just fork it if nobody else can be bothered.
|
19
|
+
|
20
|
+
0.3.8 03/27/2019
|
21
|
+
================
|
22
|
+
|
23
|
+
Support the latest Grape.
|
24
|
+
|
25
|
+
0.3.7 03/26/2019
|
26
|
+
================
|
27
|
+
|
28
|
+
Updated to support Grape ~> 1.2.0. Ruby 2.2 no longer supported.
|
29
|
+
|
30
|
+
|
31
|
+
0.3.7 03/25/2019
|
32
|
+
================
|
33
|
+
|
34
|
+
Updated to support Grape <~ 1.1.0.
|
35
|
+
|
36
|
+
0.3.6 03/23/2019
|
37
|
+
================
|
38
|
+
|
39
|
+
Updated to support Rails 5+.
|
40
|
+
|
1
41
|
|
2
42
|
0.3.5 09/14/2018
|
3
43
|
================
|
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,25 +18,26 @@ 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 = '
|
21
|
+
s.required_ruby_version = '>= 2.3'
|
22
22
|
|
23
|
-
|
24
|
-
s.add_dependency "
|
23
|
+
s.add_dependency "rails", '> 5.0.0'
|
24
|
+
s.add_dependency "rack", '< 2.0.9'
|
25
25
|
|
26
|
-
|
27
|
-
s.add_dependency 'grape
|
28
|
-
s.add_dependency 'grape-
|
29
|
-
s.add_dependency '
|
30
|
-
s.add_dependency '
|
26
|
+
# grape 1.0.0 breaks the pagination solution
|
27
|
+
s.add_dependency 'grape', ['~> 1.2.0', '< 1.2.5']
|
28
|
+
s.add_dependency 'grape-entity'
|
29
|
+
s.add_dependency 'grape-swagger'
|
30
|
+
s.add_dependency 'kaminari' #, '< 1.0' # version 1.0.0 breaks
|
31
|
+
#s.add_dependency 'grape-kaminari', :github => 'alexey-klimuk/grape-kaminari'
|
31
32
|
# Pundit 2.0 mysteriously made authorize a protected method...
|
32
|
-
s.add_dependency 'pundit'
|
33
|
+
s.add_dependency 'pundit' #, '<2.0'
|
33
34
|
s.add_dependency 'camel_snake_keys', '>0.0.4'
|
34
35
|
|
35
36
|
if RUBY_PLATFORM == 'java'
|
36
37
|
#s.add_development_dependency "jdbc-sqlite3"
|
37
38
|
s.add_development_dependency "activerecord-jdbcsqlite3-adapter"
|
38
39
|
else
|
39
|
-
s.add_development_dependency "sqlite3"
|
40
|
+
s.add_development_dependency "sqlite3", '<1.4.0' #'< 1.3.14'
|
40
41
|
end
|
41
42
|
|
42
43
|
#s.add_development_dependency "byebug"
|
@@ -44,8 +45,8 @@ Gem::Specification.new do |s|
|
|
44
45
|
s.add_development_dependency "rspec-rails", '>= 3.0'
|
45
46
|
s.add_development_dependency 'devise'
|
46
47
|
#s.add_development_dependency 'devise-async'
|
47
|
-
s.add_development_dependency 'paperclip', '< 5.0'
|
48
|
-
s.add_development_dependency '
|
48
|
+
s.add_development_dependency 'paperclip', ">= 5.2.0" #'< 5.0'
|
49
|
+
s.add_development_dependency 'machinist_redux'
|
49
50
|
s.add_development_dependency 'simplecov'
|
50
51
|
s.add_development_dependency 'rufus-mnemo'
|
51
52
|
|
data/lib/introspective_grape.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'introspective_grape/configuration'
|
1
2
|
module IntrospectiveGrape
|
2
3
|
autoload :API, 'introspective_grape/api'
|
3
4
|
autoload :CamelSnake, 'introspective_grape/camel_snake'
|
5
|
+
autoload :Configure, 'introspective_grape/configuration'
|
4
6
|
autoload :CreateHelpers, 'introspective_grape/create_helpers'
|
5
7
|
autoload :Doc, 'introspective_grape/doc'
|
6
8
|
autoload :Filters, 'introspective_grape/filters'
|
@@ -13,6 +15,6 @@ module IntrospectiveGrape
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.config
|
16
|
-
@config
|
18
|
+
@config ||= Configuration.new
|
17
19
|
end
|
18
20
|
end
|
@@ -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
|
@@ -228,7 +250,12 @@ module IntrospectiveGrape
|
|
228
250
|
|
229
251
|
default_includes = routes.first.klass.default_includes(routes.first.model)
|
230
252
|
|
231
|
-
|
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
|
232
259
|
end
|
233
260
|
end
|
234
261
|
|
@@ -244,28 +271,6 @@ module IntrospectiveGrape
|
|
244
271
|
end
|
245
272
|
end
|
246
273
|
|
247
|
-
def convert_nested_params_hash(dsl, routes)
|
248
|
-
root = routes.first
|
249
|
-
klass = root.klass
|
250
|
-
dsl.after_validation do
|
251
|
-
# After Grape validates its parameters:
|
252
|
-
# 1) Find the root model instance for the API if its passed (implicitly either
|
253
|
-
# an update/destroy on the root node or it's a nested route
|
254
|
-
# 2) For nested endpoints convert the params hash into Rails-compliant nested
|
255
|
-
# attributes, to be passed to the root instance for update. This keeps
|
256
|
-
# behavior consistent between bulk and single record updates.
|
257
|
-
|
258
|
-
if params[root.key]
|
259
|
-
@model = root.model.includes( klass.default_includes(root.model) ).find(params[root.key])
|
260
|
-
end
|
261
|
-
|
262
|
-
if routes.size > 1
|
263
|
-
nested_attributes = klass.build_nested_attributes(routes[1..-1], params.except(root.key,:api_key) )
|
264
|
-
@params.merge!( nested_attributes ) if nested_attributes.kind_of?(Hash)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
274
|
|
270
275
|
def build_routes(routes, model, reflection_name=nil)
|
271
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
|