rest-api-generator 0.1.5 → 0.1.7
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 +4 -4
- data/Gemfile.lock +15 -7
- data/README.md +47 -10
- data/{lib → app/controllers}/rest_api_generator/application_controller.rb +1 -0
- data/{lib → app/controllers}/rest_api_generator/child_resource_controller.rb +9 -1
- data/{lib → app/controllers}/rest_api_generator/resource_controller.rb +9 -1
- data/lib/rest_api_generator/config.rb +6 -1
- data/lib/rest_api_generator/rails.rb +6 -0
- data/lib/rest_api_generator/version.rb +1 -1
- data/lib/rest_api_generator.rb +5 -13
- data/rest-api-generator.gemspec +9 -3
- metadata +33 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7576268dec99ae0feafe5da3a552dae8d0609ccd244f5e62a99007e2f54090b
|
4
|
+
data.tar.gz: 0f8a227490885ada7b83f1373c854857889e710b1d24285a81b45490308419a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19bbdd850d24d6168fda588274287ad8645b255165487261dd6413420ab395fdc150675d97ed57ac6e2d395f2bf7cc5d48632f3b43bfe2a11f06964aae71b1d7
|
7
|
+
data.tar.gz: 4653ea0a74f2377c9052eba66bb16230096598f5f3e5d52f42ff5ad5141b763b4054359c7bf360083d7e08b517249bf44b17a9a6e64765f51861961075068c65
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest-api-generator (0.1.
|
4
|
+
rest-api-generator (0.1.7)
|
5
|
+
anyway_config (>= 2.0.0)
|
6
|
+
pagy
|
5
7
|
rails (>= 5.0)
|
6
8
|
|
7
9
|
GEM
|
@@ -78,7 +80,7 @@ GEM
|
|
78
80
|
activesupport (>= 3.0)
|
79
81
|
railties (>= 3.0)
|
80
82
|
rspec-rails (>= 2.2)
|
81
|
-
anyway_config (2.
|
83
|
+
anyway_config (2.4.0)
|
82
84
|
ruby-next-core (>= 0.14.0)
|
83
85
|
ast (2.4.2)
|
84
86
|
builder (3.2.4)
|
@@ -93,7 +95,7 @@ GEM
|
|
93
95
|
date (3.3.3)
|
94
96
|
diff-lcs (1.5.0)
|
95
97
|
erubi (1.12.0)
|
96
|
-
globalid (1.
|
98
|
+
globalid (1.1.0)
|
97
99
|
activesupport (>= 5.0)
|
98
100
|
i18n (1.12.0)
|
99
101
|
concurrent-ruby (~> 1.0)
|
@@ -103,7 +105,7 @@ GEM
|
|
103
105
|
loofah (2.19.1)
|
104
106
|
crass (~> 1.0.2)
|
105
107
|
nokogiri (>= 1.5.9)
|
106
|
-
mail (2.8.
|
108
|
+
mail (2.8.1)
|
107
109
|
mini_mime (>= 0.1.1)
|
108
110
|
net-imap
|
109
111
|
net-pop
|
@@ -111,6 +113,7 @@ GEM
|
|
111
113
|
marcel (1.0.2)
|
112
114
|
method_source (1.0.0)
|
113
115
|
mini_mime (1.1.2)
|
116
|
+
mini_portile2 (2.8.1)
|
114
117
|
minitest (5.16.3)
|
115
118
|
net-imap (0.3.4)
|
116
119
|
date
|
@@ -121,9 +124,13 @@ GEM
|
|
121
124
|
timeout
|
122
125
|
net-smtp (0.3.3)
|
123
126
|
net-protocol
|
124
|
-
nio4r (2.5.
|
127
|
+
nio4r (2.5.9)
|
128
|
+
nokogiri (1.13.10)
|
129
|
+
mini_portile2 (~> 2.8.0)
|
130
|
+
racc (~> 1.4)
|
125
131
|
nokogiri (1.13.10-x86_64-linux)
|
126
132
|
racc (~> 1.4)
|
133
|
+
pagy (6.0.3)
|
127
134
|
parallel (1.22.1)
|
128
135
|
parser (3.1.3.0)
|
129
136
|
ast (~> 2.4.1)
|
@@ -222,6 +229,8 @@ GEM
|
|
222
229
|
rubocop (~> 1.35)
|
223
230
|
ruby-next-core (0.15.3)
|
224
231
|
ruby-progressbar (1.11.0)
|
232
|
+
sqlite3 (1.5.4)
|
233
|
+
mini_portile2 (~> 2.8.0)
|
225
234
|
sqlite3 (1.5.4-x86_64-linux)
|
226
235
|
switchcop (0.1.2)
|
227
236
|
rubocop (~> 1.40.0)
|
@@ -230,7 +239,7 @@ GEM
|
|
230
239
|
rubocop-rspec (~> 2.16.0)
|
231
240
|
rubocop-shopify (~> 2.10.1)
|
232
241
|
thor (1.2.1)
|
233
|
-
timeout (0.3.
|
242
|
+
timeout (0.3.2)
|
234
243
|
tzinfo (2.0.5)
|
235
244
|
concurrent-ruby (~> 1.0)
|
236
245
|
unicode-display_width (2.3.0)
|
@@ -245,7 +254,6 @@ PLATFORMS
|
|
245
254
|
|
246
255
|
DEPENDENCIES
|
247
256
|
ammeter (~> 1.1.5)
|
248
|
-
anyway_config (>= 2.0.0)
|
249
257
|
database_cleaner
|
250
258
|
rake (~> 13.0)
|
251
259
|
rest-api-generator!
|
data/README.md
CHANGED
@@ -24,6 +24,8 @@ Following [Switch Dreams's](https://www.switchdreams.com.br/]) coding practices,
|
|
24
24
|
- :memo: [Automated documentation](#specsdocs)
|
25
25
|
- [Resource ordering](#ordering)
|
26
26
|
- [Resource filter](#filtering)
|
27
|
+
- [Resource pagination](#pagination)
|
28
|
+
- [Configurable](#configuration)
|
27
29
|
|
28
30
|
## Next Features
|
29
31
|
|
@@ -243,19 +245,11 @@ This spec options work as generators too, so you can call them individually:
|
|
243
245
|
rails g rest_api_generator:spec:rswag Car name:string color:string
|
244
246
|
```
|
245
247
|
|
246
|
-
|
248
|
+
#### Configuration for specs
|
247
249
|
|
248
250
|
By default, the plain rspec and rswag specs are going to be generated in the _spec/requests_ and _spec/docs_
|
249
|
-
directories, respectively. You can override
|
251
|
+
directories, respectively. You can override using the (config options)[#configuration]]. :
|
250
252
|
|
251
|
-
```rb
|
252
|
-
# config/initializers/rest_api_generator.rb
|
253
|
-
|
254
|
-
RestApiGenerator.configure do |config|
|
255
|
-
config.test_path = "custom_test_dir/requests"
|
256
|
-
config.docs_path = "custom_docs_dir/rswag"
|
257
|
-
end
|
258
|
-
```
|
259
253
|
|
260
254
|
### Resource Features
|
261
255
|
|
@@ -301,6 +295,49 @@ And It's done, you can filter your index end-point:
|
|
301
295
|
|
302
296
|
- `GET /cars?color=blue or GET /cars?color=red&name=Ferrari`
|
303
297
|
|
298
|
+
### Pagination
|
299
|
+
|
300
|
+
For pagination, you need to create pagy initialializer file (pagy.rb) in the config directory of your project. Follow [pagy's example](https://ddnexus.github.io/pagy/quick-start/) for more information.
|
301
|
+
|
302
|
+
Next, you should add some lines on top of the previously created pagy file:
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
# config/initializers/pagy.rb
|
306
|
+
require "pagy"
|
307
|
+
require "pagy/extras/headers"
|
308
|
+
```
|
309
|
+
|
310
|
+
At last, change the pagination variable on RestApiGenerator initializer to true;
|
311
|
+
|
312
|
+
```rb
|
313
|
+
# config/initializers/rest_api_generator.rb
|
314
|
+
config.pagination = true # default: false
|
315
|
+
```
|
316
|
+
|
317
|
+
Note, if the parent controller is changed, it is necessary to include Pagy::Backend in the new parent.
|
318
|
+
|
319
|
+
```rb
|
320
|
+
# new_parent_controller.rb
|
321
|
+
class NewParentController < ActionController::Base
|
322
|
+
include Pagy::Backend
|
323
|
+
end
|
324
|
+
```
|
325
|
+
|
326
|
+
## Configuration
|
327
|
+
|
328
|
+
You can override this gem configuration using the initializer or any other method from [anyway_config](https://github.com/palkan/anyway_config):
|
329
|
+
|
330
|
+
```rb
|
331
|
+
# config/initializers/rest_api_generator.rb
|
332
|
+
|
333
|
+
RestApiGenerator.configure do |config|
|
334
|
+
config.test_path = "custom_test_dir/requests" # default: spec/requests
|
335
|
+
config.docs_path = "custom_docs_dir/rswag" # default: spec/docs
|
336
|
+
config.parent_class = "ApplicationController" # default: RestApiGenerator::ResourceController
|
337
|
+
config.pagination = true # default: false
|
338
|
+
end
|
339
|
+
```
|
340
|
+
|
304
341
|
## Development
|
305
342
|
|
306
343
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RestApiGenerator
|
4
|
-
class ChildResourceController < RestApiGenerator.parent_controller.constantize
|
4
|
+
class ChildResourceController < RestApiGenerator.configuration.parent_controller.constantize
|
5
5
|
include Orderable
|
6
6
|
|
7
7
|
before_action :set_parent_resource
|
@@ -11,6 +11,10 @@ module RestApiGenerator
|
|
11
11
|
@resources = resources
|
12
12
|
@resources = @resources.filter_resource(params_for_filter) if resource_class.include?(Filterable)
|
13
13
|
@resources = @resources.order(ordering_params(params[:sort])) if params[:sort]
|
14
|
+
if pagination
|
15
|
+
@pagy, @resources = pagy(@resources)
|
16
|
+
pagy_headers_merge(@pagy)
|
17
|
+
end
|
14
18
|
render json: @resources, status: :ok
|
15
19
|
end
|
16
20
|
|
@@ -93,5 +97,9 @@ module RestApiGenerator
|
|
93
97
|
def record_id
|
94
98
|
params.permit(:id)[:id]
|
95
99
|
end
|
100
|
+
|
101
|
+
def pagination
|
102
|
+
RestApiGenerator.configuration.pagination
|
103
|
+
end
|
96
104
|
end
|
97
105
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RestApiGenerator
|
4
|
-
class ResourceController < RestApiGenerator.parent_controller.constantize
|
4
|
+
class ResourceController < RestApiGenerator.configuration.parent_controller.constantize
|
5
5
|
include Orderable
|
6
6
|
|
7
7
|
before_action :set_resource, only: [:show, :update, :destroy]
|
@@ -10,6 +10,10 @@ module RestApiGenerator
|
|
10
10
|
@resources = resource_class.all
|
11
11
|
@resources = @resources.filter_resource(params_for_filter) if resource_class.include?(Filterable)
|
12
12
|
@resources = @resources.order(ordering_params(params[:sort])) if params[:sort]
|
13
|
+
if pagination
|
14
|
+
@pagy, @resources = pagy(@resources)
|
15
|
+
pagy_headers_merge(@pagy)
|
16
|
+
end
|
13
17
|
render json: @resources, status: :ok
|
14
18
|
end
|
15
19
|
|
@@ -69,5 +73,9 @@ module RestApiGenerator
|
|
69
73
|
def record_id
|
70
74
|
params.permit(:id)[:id]
|
71
75
|
end
|
76
|
+
|
77
|
+
def pagination
|
78
|
+
RestApiGenerator.configuration.pagination
|
79
|
+
end
|
72
80
|
end
|
73
81
|
end
|
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
require "anyway_config"
|
4
4
|
|
5
|
+
Anyway::Settings.default_config_path = ->(_name) { Rails.root ? Rails.root.join("config/rest_api_generator.yml") : "" }
|
6
|
+
|
5
7
|
module RestApiGenerator
|
6
8
|
class Config < Anyway::Config
|
7
9
|
config_name :rest_api_generator
|
8
10
|
|
9
|
-
attr_config test_path: "spec/requests",
|
11
|
+
attr_config test_path: "spec/requests",
|
12
|
+
docs_path: "spec/docs",
|
13
|
+
parent_controller: "RestApiGenerator::ApplicationController",
|
14
|
+
pagination: false
|
10
15
|
end
|
11
16
|
end
|
data/lib/rest_api_generator.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "rails"
|
4
4
|
require_relative "rest_api_generator/version"
|
5
|
-
require_relative "rest_api_generator/application_controller"
|
6
5
|
require_relative "rest_api_generator/error_handler"
|
7
6
|
require_relative "rest_api_generator/config"
|
8
7
|
require_relative "rest_api_generator/custom_error"
|
@@ -13,20 +12,13 @@ require_relative "rest_api_generator/orderable"
|
|
13
12
|
module RestApiGenerator
|
14
13
|
class Error < StandardError; end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
@configuration ||= Config.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def configure
|
22
|
-
yield(configuration)
|
23
|
-
end
|
15
|
+
def self.configuration
|
16
|
+
@config ||= Config.new
|
24
17
|
end
|
25
18
|
|
26
|
-
def self.
|
27
|
-
|
19
|
+
def self.configure
|
20
|
+
yield(configuration) if block_given?
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
|
32
|
-
require_relative "rest_api_generator/child_resource_controller"
|
24
|
+
require "rest_api_generator/rails" if defined?(Rails)
|
data/rest-api-generator.gemspec
CHANGED
@@ -22,8 +22,13 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.metadata["source_code_uri"] = "https://github.com/SwitchDreams/rest-api-generator"
|
23
23
|
spec.metadata["changelog_uri"] = "https://github.com/SwitchDreams/rest-api-generator"
|
24
24
|
|
25
|
-
spec.files = Dir["{bin,sig,lib,public}/**/*",
|
26
|
-
"
|
25
|
+
spec.files = Dir["{bin,sig,lib,public,app}/**/*",
|
26
|
+
"MIT-LICENSE",
|
27
|
+
"Rakefile",
|
28
|
+
"README.md",
|
29
|
+
"rest-api-generator.gemspec",
|
30
|
+
"Gemfile",
|
31
|
+
"Gemfile.lock"]
|
27
32
|
spec.bindir = "exe"
|
28
33
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
34
|
spec.require_paths = ["lib"]
|
@@ -32,10 +37,11 @@ Gem::Specification.new do |spec|
|
|
32
37
|
# guide at: https://bundler.io/guides/creating_gem.html
|
33
38
|
spec.metadata["rubygems_mfa_required"] = "true"
|
34
39
|
|
40
|
+
spec.add_dependency "anyway_config", ">= 2.0.0"
|
41
|
+
spec.add_dependency "pagy"
|
35
42
|
spec.add_dependency "rails", ">= 5.0"
|
36
43
|
|
37
44
|
spec.add_development_dependency "ammeter", "~> 1.1.5"
|
38
|
-
spec.add_development_dependency "anyway_config", ">= 2.0.0"
|
39
45
|
spec.add_development_dependency "database_cleaner"
|
40
46
|
spec.add_development_dependency "rspec-rails", "~> 6.0.0"
|
41
47
|
spec.add_development_dependency "rswag"
|
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-api-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PedroAugustoRamalhoDuarte
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: anyway_config
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pagy
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ammeter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.5
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.5
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: database_cleaner
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +134,9 @@ files:
|
|
120
134
|
- Gemfile.lock
|
121
135
|
- README.md
|
122
136
|
- Rakefile
|
137
|
+
- app/controllers/rest_api_generator/application_controller.rb
|
138
|
+
- app/controllers/rest_api_generator/child_resource_controller.rb
|
139
|
+
- app/controllers/rest_api_generator/resource_controller.rb
|
123
140
|
- bin/console
|
124
141
|
- bin/setup
|
125
142
|
- lib/generators/rest_api_generator/USAGE
|
@@ -137,15 +154,13 @@ files:
|
|
137
154
|
- lib/generators/rest_api_generator/templates/rest_api_controller.rb.tt
|
138
155
|
- lib/rest-api-generator.rb
|
139
156
|
- lib/rest_api_generator.rb
|
140
|
-
- lib/rest_api_generator/application_controller.rb
|
141
|
-
- lib/rest_api_generator/child_resource_controller.rb
|
142
157
|
- lib/rest_api_generator/config.rb
|
143
158
|
- lib/rest_api_generator/custom_error.rb
|
144
159
|
- lib/rest_api_generator/error_handler.rb
|
145
160
|
- lib/rest_api_generator/filterable.rb
|
146
161
|
- lib/rest_api_generator/helpers/render.rb
|
147
162
|
- lib/rest_api_generator/orderable.rb
|
148
|
-
- lib/rest_api_generator/
|
163
|
+
- lib/rest_api_generator/rails.rb
|
149
164
|
- lib/rest_api_generator/version.rb
|
150
165
|
- rest-api-generator.gemspec
|
151
166
|
- sig/rest_api_generator.rbs
|