rest-api-generator 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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +22 -1
- data/README.md +21 -3
- data/lib/generators/rest_api_generator/helpers.rb +42 -0
- data/lib/generators/rest_api_generator/resource_generator.rb +2 -45
- data/lib/generators/rest_api_generator/spec/rspec_generator.rb +36 -0
- data/lib/generators/rest_api_generator/spec/rswag_generator.rb +54 -0
- data/lib/generators/rest_api_generator/{templates/child_api_spec.rb.tt → spec/templates/rspec/nested_resource_controller_spec.rb.tt} +0 -0
- data/lib/generators/rest_api_generator/{templates/rest_api_spec.rb.tt → spec/templates/rspec/resource_controller_spec.rb.tt} +0 -0
- data/lib/generators/rest_api_generator/spec/templates/rswag/nested_resource_controller_spec.rb.tt +116 -0
- data/lib/generators/rest_api_generator/spec/templates/rswag/resource_controller_spec.rb.tt +111 -0
- data/lib/rest_api_generator/version.rb +1 -1
- data/rest-api-generator.gemspec +8 -7
- metadata +24 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c84db27490fa76b76096f10ba351092bfb42479890a2a279d725f579c4edb7
|
4
|
+
data.tar.gz: 25e537cd496a09eb3b5755fadf4d04bbcaad38c941bf54af60e230ed7a1ccd13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f07b832a6373ed5197f114a0bdc54c6a6c2088d712e3641b8d55d717a5d5b019bba3427907b73495ac6a97de2bfbdd68ee48de267651808cf3d6adbe9f2547
|
7
|
+
data.tar.gz: 565c3cc7797794a6c59008990e58727173c5fa472ef8a8a188cb2a2ba60789cf03994ba8feaff7d8d5dfcf3443333412ece5dbb926f5a44156fa71ad240531b0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest-api-generator (0.1.
|
4
|
+
rest-api-generator (0.1.3)
|
5
5
|
rails (>= 5.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -72,6 +72,8 @@ GEM
|
|
72
72
|
i18n (>= 1.6, < 2)
|
73
73
|
minitest (>= 5.1)
|
74
74
|
tzinfo (~> 2.0)
|
75
|
+
addressable (2.8.1)
|
76
|
+
public_suffix (>= 2.0.2, < 6.0)
|
75
77
|
ammeter (1.1.5)
|
76
78
|
activesupport (>= 3.0)
|
77
79
|
railties (>= 3.0)
|
@@ -94,6 +96,8 @@ GEM
|
|
94
96
|
i18n (1.12.0)
|
95
97
|
concurrent-ruby (~> 1.0)
|
96
98
|
json (2.6.3)
|
99
|
+
json-schema (3.0.0)
|
100
|
+
addressable (>= 2.8)
|
97
101
|
loofah (2.19.1)
|
98
102
|
crass (~> 1.0.2)
|
99
103
|
nokogiri (>= 1.5.9)
|
@@ -121,6 +125,7 @@ GEM
|
|
121
125
|
parallel (1.22.1)
|
122
126
|
parser (3.1.3.0)
|
123
127
|
ast (~> 2.4.1)
|
128
|
+
public_suffix (5.0.1)
|
124
129
|
racc (1.6.2)
|
125
130
|
rack (2.2.4)
|
126
131
|
rack-test (2.0.2)
|
@@ -176,6 +181,20 @@ GEM
|
|
176
181
|
rspec-mocks (~> 3.11)
|
177
182
|
rspec-support (~> 3.11)
|
178
183
|
rspec-support (3.12.0)
|
184
|
+
rswag (2.8.0)
|
185
|
+
rswag-api (= 2.8.0)
|
186
|
+
rswag-specs (= 2.8.0)
|
187
|
+
rswag-ui (= 2.8.0)
|
188
|
+
rswag-api (2.8.0)
|
189
|
+
railties (>= 3.1, < 7.1)
|
190
|
+
rswag-specs (2.8.0)
|
191
|
+
activesupport (>= 3.1, < 7.1)
|
192
|
+
json-schema (>= 2.2, < 4.0)
|
193
|
+
railties (>= 3.1, < 7.1)
|
194
|
+
rspec-core (>= 2.14)
|
195
|
+
rswag-ui (2.8.0)
|
196
|
+
actionpack (>= 3.1, < 7.1)
|
197
|
+
railties (>= 3.1, < 7.1)
|
179
198
|
rubocop (1.40.0)
|
180
199
|
json (~> 2.3)
|
181
200
|
parallel (~> 1.10)
|
@@ -227,6 +246,8 @@ DEPENDENCIES
|
|
227
246
|
rest-api-generator!
|
228
247
|
rspec (~> 3.0)
|
229
248
|
rspec-rails (~> 6.0.0)
|
249
|
+
rswag
|
250
|
+
rswag-specs
|
230
251
|
sqlite3
|
231
252
|
switchcop
|
232
253
|
|
data/README.md
CHANGED
@@ -20,14 +20,13 @@ Following [Switch Dreams's](https://www.switchdreams.com.br/]) coding practices,
|
|
20
20
|
|
21
21
|
- [Automatic rest api crud generation](#example)
|
22
22
|
- [Nested Resource](#nested-resource)
|
23
|
-
- [Modular error handler](#modular-error-handler)
|
23
|
+
- :goal_net: [Modular error handler](#modular-error-handler)
|
24
|
+
- :memo: [Automated documentation](#specsdocs)
|
24
25
|
- [Resource ordering](#ordering)
|
25
26
|
- [Resource filter](#filtering)
|
26
27
|
|
27
28
|
## Next Features
|
28
29
|
|
29
|
-
- Generate nested resource end-points 🚧
|
30
|
-
- Automated documentation 🚧 https://github.com/SwitchDreams/rest-api-generator/issues/12
|
31
30
|
- Serialization https://github.com/SwitchDreams/rest-api-generator/issues/14
|
32
31
|
https://github.com/SwitchDreams/rest-api-generator/issues/11
|
33
32
|
- Pagination https://github.com/SwitchDreams/rest-api-generator/issues/15
|
@@ -116,6 +115,7 @@ For a better experience you can override some methods from the
|
|
116
115
|
| father | Generate nested resource | nil | --father Users |
|
117
116
|
| scope | Scope the resource for other route or namespace organization | nil | --scope Api::V1 |
|
118
117
|
| eject | Eject the controller to high customization | false | true |
|
118
|
+
| spec | Choose the spec format. Current options: "rspec" or "rswag" | rspec | --spec rswag |
|
119
119
|
|
120
120
|
#### Scope
|
121
121
|
|
@@ -225,6 +225,24 @@ class CarsController < ApplicationController
|
|
225
225
|
end
|
226
226
|
```
|
227
227
|
|
228
|
+
#### Specs/Docs
|
229
|
+
|
230
|
+
The default generated spec for this gem is using plain rspec, but you can choose rswag, for scaffold you specs and docs
|
231
|
+
at the same time:
|
232
|
+
|
233
|
+
For this you need to setup https://github.com/rswag/rswag and you the following flag when generating resources.
|
234
|
+
|
235
|
+
```shell
|
236
|
+
rails g rest_api_generator:resource Car name:string color:string --spec rswag
|
237
|
+
```
|
238
|
+
|
239
|
+
This spec options work as generators too, so you can call them individually:
|
240
|
+
|
241
|
+
```shell
|
242
|
+
# rest_api_generator:spec:rswag or rest_api_generator:spec:rspec
|
243
|
+
rails g rest_api_generator:spec:rswag Car name:string color:string
|
244
|
+
```
|
245
|
+
|
228
246
|
### Resource Features
|
229
247
|
|
230
248
|
#### Modular Error Handler
|
@@ -4,8 +4,12 @@ module RestApiGenerator
|
|
4
4
|
module Helpers
|
5
5
|
attr_accessor :options, :attributes
|
6
6
|
|
7
|
+
API_CONTROLLER_DIR_PATH = "app/controllers"
|
8
|
+
API_TEST_DIR_PATH = "spec/requests"
|
9
|
+
|
7
10
|
private
|
8
11
|
|
12
|
+
# Columns handlers
|
9
13
|
def model_columns_for_attributes
|
10
14
|
class_name.singularize.constantize.columns.reject do |column|
|
11
15
|
column.name.to_s =~ /^(id|user_id|created_at|updated_at)$/
|
@@ -18,6 +22,42 @@ module RestApiGenerator
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
25
|
+
# Namespace scope
|
26
|
+
|
27
|
+
def scope_namespacing(&block)
|
28
|
+
content = capture(&block)
|
29
|
+
content = wrap_with_scope(content) if options["scope"].present? || options["father"].present?
|
30
|
+
concat(content)
|
31
|
+
end
|
32
|
+
|
33
|
+
def module_namespace
|
34
|
+
if options["scope"].present? && options["father"].present?
|
35
|
+
options["scope"] + "::" + options["father"]
|
36
|
+
else
|
37
|
+
options["scope"] + options["father"]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def wrap_with_scope(content)
|
42
|
+
content = indent(content).chomp
|
43
|
+
"module #{module_namespace}\n#{content}\nend\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
# Paths handlers
|
47
|
+
def controller_path
|
48
|
+
"#{API_CONTROLLER_DIR_PATH}#{scope_path}/#{file_name.pluralize}_controller.rb"
|
49
|
+
end
|
50
|
+
|
51
|
+
def scope_path
|
52
|
+
return "" if options["scope"].blank? && options["father"].blank?
|
53
|
+
|
54
|
+
if options["scope"].present? && options["father"].present?
|
55
|
+
"/" + option_to_path(options["scope"]) + "/" + option_to_path(options["father"])
|
56
|
+
else
|
57
|
+
"/" + option_to_path(options["scope"]) + option_to_path(options["father"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
21
61
|
def option_to_path(option)
|
22
62
|
option.downcase.split("::").join("/")
|
23
63
|
end
|
@@ -35,6 +75,8 @@ module RestApiGenerator
|
|
35
75
|
end
|
36
76
|
|
37
77
|
def initial_route
|
78
|
+
return "/#{plural_name}" if options["father"].blank? && options["scope"].blank?
|
79
|
+
|
38
80
|
scope_route_path + "/" + nested_routes
|
39
81
|
end
|
40
82
|
|
@@ -13,20 +13,14 @@ module RestApiGenerator
|
|
13
13
|
class_option :eject, type: :boolean, default: false
|
14
14
|
class_option :scope, type: :string, default: ""
|
15
15
|
class_option :father, type: :string, default: ""
|
16
|
-
|
17
|
-
API_CONTROLLER_DIR_PATH = "app/controllers"
|
18
|
-
API_TEST_DIR_PATH = "spec/requests"
|
16
|
+
hook_for :spec, in: "rest_api_generator:spec", default: "rspec"
|
19
17
|
|
20
18
|
def create_service_file
|
21
19
|
create_model_files
|
22
20
|
|
23
|
-
# Create controller and specs
|
24
|
-
controller_path = "#{API_CONTROLLER_DIR_PATH}#{scope_path}/#{file_name.pluralize}_controller.rb"
|
25
|
-
controller_test_path = "#{API_TEST_DIR_PATH}#{scope_path}/#{file_name.pluralize}_controller_spec.rb"
|
26
|
-
|
27
21
|
template controller_template, controller_path
|
28
|
-
template spec_controller_template, controller_test_path
|
29
22
|
|
23
|
+
# Routes
|
30
24
|
if options["scope"].blank? && options["father"].blank?
|
31
25
|
route "resources :#{file_name.pluralize}"
|
32
26
|
else
|
@@ -36,35 +30,6 @@ module RestApiGenerator
|
|
36
30
|
|
37
31
|
private
|
38
32
|
|
39
|
-
def scope_path
|
40
|
-
return "" if options["scope"].blank? && options["father"].blank?
|
41
|
-
|
42
|
-
if options["scope"].present? && options["father"].present?
|
43
|
-
"/" + option_to_path(options["scope"]) + "/" + option_to_path(options["father"])
|
44
|
-
else
|
45
|
-
"/" + option_to_path(options["scope"]) + option_to_path(options["father"])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def scope_namespacing(&block)
|
50
|
-
content = capture(&block)
|
51
|
-
content = wrap_with_scope(content) if options["scope"].present? || options["father"].present?
|
52
|
-
concat(content)
|
53
|
-
end
|
54
|
-
|
55
|
-
def module_namespace
|
56
|
-
if options["scope"].present? && options["father"].present?
|
57
|
-
options["scope"] + "::" + options["father"]
|
58
|
-
else
|
59
|
-
options["scope"] + options["father"]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def wrap_with_scope(content)
|
64
|
-
content = indent(content).chomp
|
65
|
-
"module #{module_namespace}\n#{content}\nend\n"
|
66
|
-
end
|
67
|
-
|
68
33
|
def controller_template
|
69
34
|
if options["eject"]
|
70
35
|
if options["father"].present?
|
@@ -79,14 +44,6 @@ module RestApiGenerator
|
|
79
44
|
end
|
80
45
|
end
|
81
46
|
|
82
|
-
def spec_controller_template
|
83
|
-
if options["father"].present?
|
84
|
-
"child_api_spec.rb"
|
85
|
-
else
|
86
|
-
"rest_api_spec.rb"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
47
|
def create_model_files
|
91
48
|
g = Rails::Generators::ModelGenerator.new([file_name, build_model_attributes])
|
92
49
|
g.destination_root = destination_root
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require "generators/rest_api_generator/helpers"
|
5
|
+
|
6
|
+
module RestApiGenerator
|
7
|
+
module Spec
|
8
|
+
class RspecGenerator < Rails::Generators::NamedBase
|
9
|
+
include Helpers
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
|
13
|
+
class_option :eject, type: :boolean, default: false
|
14
|
+
class_option :scope, type: :string, default: ""
|
15
|
+
class_option :father, type: :string, default: ""
|
16
|
+
|
17
|
+
def create_service_file
|
18
|
+
template spec_controller_template, controller_test_path
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def controller_test_path
|
24
|
+
"#{API_TEST_DIR_PATH}#{scope_path}/#{file_name.pluralize}_controller_spec.rb"
|
25
|
+
end
|
26
|
+
|
27
|
+
def spec_controller_template
|
28
|
+
if options["father"].present?
|
29
|
+
"rspec/resource_controller_spec.rb"
|
30
|
+
else
|
31
|
+
"rspec/nested_resource_controller_spec.rb"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require "generators/rest_api_generator/helpers"
|
5
|
+
|
6
|
+
module RestApiGenerator
|
7
|
+
module Spec
|
8
|
+
class RswagGenerator < Rails::Generators::NamedBase
|
9
|
+
include Helpers
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
|
13
|
+
class_option :eject, type: :boolean, default: false
|
14
|
+
class_option :scope, type: :string, default: ""
|
15
|
+
class_option :father, type: :string, default: ""
|
16
|
+
|
17
|
+
def create_service_file
|
18
|
+
template spec_controller_template, controller_test_path
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Changes nested routes for rswag format
|
24
|
+
# Example: /cars/{car.id}/drivers/{id}
|
25
|
+
def nested_routes
|
26
|
+
return "" if options["father"].blank?
|
27
|
+
|
28
|
+
"#{options["father"].downcase.pluralize}/{#{options["father"].singularize.downcase}_id}/#{plural_name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def spec_routes
|
32
|
+
{
|
33
|
+
index: initial_route,
|
34
|
+
show: initial_route + "/{id}",
|
35
|
+
create: initial_route,
|
36
|
+
update: initial_route + "/{id}",
|
37
|
+
delete: initial_route + "/{id}",
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def controller_test_path
|
42
|
+
"#{API_TEST_DIR_PATH}#{scope_path}/#{file_name.pluralize}_spec.rb"
|
43
|
+
end
|
44
|
+
|
45
|
+
def spec_controller_template
|
46
|
+
if options["father"].present?
|
47
|
+
"rswag/nested_resource_controller_spec.rb"
|
48
|
+
else
|
49
|
+
"rswag/resource_controller_spec.rb"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
File without changes
|
File without changes
|
data/lib/generators/rest_api_generator/spec/templates/rswag/nested_resource_controller_spec.rb.tt
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe "<%= spec_routes[:index] %>", type: :request do
|
4
|
+
let(:resource) { create(:<%= singular_table_name %>, <%= options['father'].downcase.singularize %>: parent_resource) }
|
5
|
+
let(:parent_resource ) { create(:<%= options['father'].downcase.singularize %>) }
|
6
|
+
|
7
|
+
path "<%= spec_routes[:index] %>" do
|
8
|
+
parameter name: "<%= options['father'].downcase.singularize %>_id", in: :path, type: :string, description: "<%= options['father'].downcase.singularize %> id"
|
9
|
+
let(:<%= options['father'].downcase.singularize %>_id) { parent_resource.id }
|
10
|
+
|
11
|
+
get("list <%= plural_name %>") do
|
12
|
+
consumes "application/json"
|
13
|
+
|
14
|
+
response(200, "successful") do
|
15
|
+
after do |example|
|
16
|
+
example.metadata[:response][:content] = {
|
17
|
+
"application/json" => {
|
18
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
run_test!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
post("create <%= singular_table_name %>") do
|
28
|
+
consumes "application/json"
|
29
|
+
|
30
|
+
# You'll want to customize the parameter types...
|
31
|
+
parameter name: :<%= singular_table_name %>, in: :body, schema: {
|
32
|
+
type: :object,
|
33
|
+
properties: {
|
34
|
+
<% attributes.each do |attribute| -%>
|
35
|
+
<%= attribute.name %>: { type: :string },
|
36
|
+
<% end -%>
|
37
|
+
}
|
38
|
+
}
|
39
|
+
response(201, "successful") do
|
40
|
+
let(:<%= singular_table_name %>) { attributes_for(:<%= singular_table_name %>) }
|
41
|
+
|
42
|
+
after do |example|
|
43
|
+
example.metadata[:response][:content] = {
|
44
|
+
"application/json" => {
|
45
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
run_test!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
path "<%= spec_routes[:show] %>" do
|
56
|
+
parameter name: "id", in: :path, type: :string, description: "id"
|
57
|
+
parameter name: "<%= options['father'].downcase.singularize %>_id", in: :path, type: :string, description: "<%= options['father'].downcase.singularize %> id"
|
58
|
+
|
59
|
+
let(:id) { resource.id }
|
60
|
+
let(:<%= options['father'].downcase.singularize %>_id) { parent_resource.id }
|
61
|
+
|
62
|
+
get("show <%= singular_table_name %>") do
|
63
|
+
consumes "application/json"
|
64
|
+
|
65
|
+
response(200, "successful") do
|
66
|
+
|
67
|
+
after do |example|
|
68
|
+
example.metadata[:response][:content] = {
|
69
|
+
"application/json" => {
|
70
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
71
|
+
}
|
72
|
+
}
|
73
|
+
end
|
74
|
+
run_test!
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
patch("update <%= singular_table_name %>") do
|
80
|
+
consumes "application/json"
|
81
|
+
|
82
|
+
# You'll want to customize the parameter types...
|
83
|
+
parameter name: :<%= singular_table_name %>, in: :body, schema: {
|
84
|
+
type: :object,
|
85
|
+
properties: {
|
86
|
+
<% attributes.each do |attribute| -%>
|
87
|
+
<%= attribute.name %>: { type: :string },
|
88
|
+
<% end -%>
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
response(200, "successful") do
|
93
|
+
let(:<%= singular_table_name %>) { attributes_for(:<%= singular_table_name %>) }
|
94
|
+
|
95
|
+
after do |example|
|
96
|
+
example.metadata[:response][:content] = {
|
97
|
+
"application/json" => {
|
98
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
99
|
+
}
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
run_test!
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
delete("delete plan") do
|
108
|
+
consumes "application/json"
|
109
|
+
|
110
|
+
response(204, "successful") do
|
111
|
+
|
112
|
+
run_test!
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe "<%= spec_routes[:index] %>", type: :request do
|
4
|
+
let(:resource) { create(:<%= singular_table_name %>) }
|
5
|
+
|
6
|
+
path "<%= spec_routes[:index] %>" do
|
7
|
+
get("list <%= plural_name %>") do
|
8
|
+
consumes "application/json"
|
9
|
+
|
10
|
+
response(200, "successful") do
|
11
|
+
after do |example|
|
12
|
+
example.metadata[:response][:content] = {
|
13
|
+
"application/json" => {
|
14
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
run_test!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
post("create <%= singular_table_name %>") do
|
24
|
+
consumes "application/json"
|
25
|
+
|
26
|
+
# You'll want to customize the parameter types...
|
27
|
+
parameter name: :<%= singular_table_name %>, in: :body, schema: {
|
28
|
+
type: :object,
|
29
|
+
properties: {
|
30
|
+
<% attributes.each do |attribute| -%>
|
31
|
+
<%= attribute.name %>: { type: :string },
|
32
|
+
<% end -%>
|
33
|
+
}
|
34
|
+
}
|
35
|
+
response(201, "successful") do
|
36
|
+
let(:<%= singular_table_name %>) { attributes_for(:<%= singular_table_name %>) }
|
37
|
+
|
38
|
+
after do |example|
|
39
|
+
example.metadata[:response][:content] = {
|
40
|
+
"application/json" => {
|
41
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
run_test!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
path "<%= spec_routes[:show] %>" do
|
52
|
+
parameter name: "id", in: :path, type: :string, description: "id"
|
53
|
+
|
54
|
+
get("show <%= singular_table_name %>") do
|
55
|
+
consumes "application/json"
|
56
|
+
|
57
|
+
response(200, "successful") do
|
58
|
+
let(:id) { resource.id }
|
59
|
+
|
60
|
+
after do |example|
|
61
|
+
example.metadata[:response][:content] = {
|
62
|
+
"application/json" => {
|
63
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
run_test!
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
patch("update <%= singular_table_name %>") do
|
73
|
+
consumes "application/json"
|
74
|
+
|
75
|
+
# You'll want to customize the parameter types...
|
76
|
+
parameter name: :<%= singular_table_name %>, in: :body, schema: {
|
77
|
+
type: :object,
|
78
|
+
properties: {
|
79
|
+
<% attributes.each do |attribute| -%>
|
80
|
+
<%= attribute.name %>: { type: :string },
|
81
|
+
<% end -%>
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
response(200, "successful") do
|
86
|
+
let(:id) { resource.id }
|
87
|
+
let(:<%= singular_table_name %>) { attributes_for(:<%= singular_table_name %>) }
|
88
|
+
|
89
|
+
after do |example|
|
90
|
+
example.metadata[:response][:content] = {
|
91
|
+
"application/json" => {
|
92
|
+
example: JSON.parse(response.body, symbolize_names: true)
|
93
|
+
}
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
run_test!
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
delete("delete plan") do
|
102
|
+
consumes "application/json"
|
103
|
+
|
104
|
+
response(204, "successful") do
|
105
|
+
let(:id) { resource.id }
|
106
|
+
|
107
|
+
run_test!
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/rest-api-generator.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
3
4
|
|
4
5
|
require_relative "lib/rest_api_generator/version"
|
5
6
|
|
@@ -22,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
22
23
|
spec.metadata["changelog_uri"] = "https://github.com/SwitchDreams/rest-api-generator"
|
23
24
|
|
24
25
|
spec.files = Dir["{bin,sig,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "rest-api-generator.gemspec",
|
25
|
-
|
26
|
+
"Gemfile", "Gemfile.lock"]
|
26
27
|
spec.bindir = "exe"
|
27
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
29
|
spec.require_paths = ["lib"]
|
@@ -33,9 +34,9 @@ Gem::Specification.new do |spec|
|
|
33
34
|
|
34
35
|
spec.add_dependency "rails", ">= 5.0"
|
35
36
|
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
|
37
|
+
spec.add_development_dependency "ammeter", "~> 1.1.5"
|
38
|
+
spec.add_development_dependency "database_cleaner"
|
39
|
+
spec.add_development_dependency "rspec-rails", "~> 6.0.0"
|
40
|
+
spec.add_development_dependency "rswag"
|
41
|
+
spec.add_development_dependency "rswag-specs"
|
41
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PedroAugustoRamalhoDuarte
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.1.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: database_cleaner
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec-rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 6.0.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rswag
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rswag-specs
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -97,12 +111,16 @@ files:
|
|
97
111
|
- lib/generators/rest_api_generator/USAGE
|
98
112
|
- lib/generators/rest_api_generator/helpers.rb
|
99
113
|
- lib/generators/rest_api_generator/resource_generator.rb
|
114
|
+
- lib/generators/rest_api_generator/spec/rspec_generator.rb
|
115
|
+
- lib/generators/rest_api_generator/spec/rswag_generator.rb
|
116
|
+
- lib/generators/rest_api_generator/spec/templates/rspec/nested_resource_controller_spec.rb.tt
|
117
|
+
- lib/generators/rest_api_generator/spec/templates/rspec/resource_controller_spec.rb.tt
|
118
|
+
- lib/generators/rest_api_generator/spec/templates/rswag/nested_resource_controller_spec.rb.tt
|
119
|
+
- lib/generators/rest_api_generator/spec/templates/rswag/resource_controller_spec.rb.tt
|
100
120
|
- lib/generators/rest_api_generator/templates/child_api_controller.rb.tt
|
101
|
-
- lib/generators/rest_api_generator/templates/child_api_spec.rb.tt
|
102
121
|
- lib/generators/rest_api_generator/templates/implicit_child_resource_controller.rb.tt
|
103
122
|
- lib/generators/rest_api_generator/templates/implicit_resource_controller.rb.tt
|
104
123
|
- lib/generators/rest_api_generator/templates/rest_api_controller.rb.tt
|
105
|
-
- lib/generators/rest_api_generator/templates/rest_api_spec.rb.tt
|
106
124
|
- lib/rest-api-generator.rb
|
107
125
|
- lib/rest_api_generator.rb
|
108
126
|
- lib/rest_api_generator/application_controller.rb
|