jsonapi-swagger-blocks-generator 0.1.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.
@@ -0,0 +1,352 @@
1
+ class <%= model.camelcase %>
2
+ include Swagger::Blocks
3
+ <%- model_name = "#{model}".split("::").last || model -%>
4
+ <%- attributes = "#{namespace}::#{model_name.camelcase}Resource".constantize._attributes -%>
5
+ <%- relationships = "#{namespace}::#{model_name.camelcase}Resource".constantize._relationships -%>
6
+
7
+ swagger_schema :<%= model_name.singularize.underscore %>_index_response do
8
+ property :data do
9
+ key :type, :array
10
+ items do
11
+ property :id do
12
+ key :type, :integer
13
+ end
14
+ property :type do
15
+ key :type, :string
16
+ end
17
+ <%- if attributes -%>
18
+ property :attributes do
19
+ items do
20
+ <%- attributes.keys.each do |attribute| -%>
21
+ property :<%= attribute %> do
22
+ key :type, :string
23
+ end
24
+ <%- end -%>
25
+ end
26
+ end
27
+ <%- end -%>
28
+ <%- if relationships -%>
29
+ property :relationships do
30
+ <%- relationships.keys.each do |relationship| -%>
31
+ property :<%= relationship %> do
32
+ property :links do
33
+ property :self do
34
+ key :type, :string
35
+ end
36
+ property :related do
37
+ key :type, :string
38
+ end
39
+ end
40
+ end
41
+ <%- end -%>
42
+ end
43
+ <%- end -%>
44
+ end
45
+ end
46
+ end
47
+
48
+ swagger_schema :<%= model_name.singularize.underscore %>_show_response do
49
+ property :data do
50
+ property :id do
51
+ key :type, :integer
52
+ end
53
+ property :type do
54
+ key :type, :string
55
+ end
56
+ property :links do
57
+ property :self do
58
+ key :type, :string
59
+ end
60
+ end
61
+ <%- if attributes -%>
62
+ property :attributes do
63
+ items do
64
+ <%- attributes.keys.each do |attribute| -%>
65
+ property :<%= attribute %> do
66
+ key :type, :string
67
+ end
68
+ <%- end -%>
69
+ end
70
+ end
71
+ <%- end -%>
72
+ <%- if relationships -%>
73
+ property :relationships do
74
+ <%- relationships.keys.each do |relationship| -%>
75
+ property :<%= relationship %> do
76
+ property :links do
77
+ property :self do
78
+ key :type, :string
79
+ end
80
+ property :related do
81
+ key :type, :string
82
+ end
83
+ end
84
+ end
85
+ <%- end -%>
86
+ end
87
+ <%- end -%>
88
+ end
89
+ end
90
+
91
+ swagger_schema :<%= model_name.singularize.underscore %>_create_response do
92
+ property :data do
93
+ property :id do
94
+ key :type, :integer
95
+ end
96
+ property :type do
97
+ key :type, :string
98
+ end
99
+ property :links do
100
+ property :self do
101
+ key :type, :string
102
+ end
103
+ end
104
+ <%- if attributes -%>
105
+ property :attributes do
106
+ items do
107
+ <%- attributes.keys.each do |attribute| -%>
108
+ property :<%= attribute %> do
109
+ key :type, :string
110
+ end
111
+ <%- end -%>
112
+ end
113
+ end
114
+ <%- end -%>
115
+ <%- if relationships -%>
116
+ property :relationships do
117
+ <%- relationships.keys.each do |relationship| -%>
118
+ property :<%= relationship %> do
119
+ property :links do
120
+ property :self do
121
+ key :type, :string
122
+ end
123
+ property :related do
124
+ key :type, :string
125
+ end
126
+ end
127
+ end
128
+ <%- end -%>
129
+ end
130
+ <%- end -%>
131
+ end
132
+ end
133
+
134
+ swagger_schema :<%= model_name.singularize.underscore %>_update_response do
135
+ property :data do
136
+ property :id do
137
+ key :type, :integer
138
+ end
139
+ property :type do
140
+ key :type, :string
141
+ end
142
+ property :links do
143
+ property :self do
144
+ key :type, :string
145
+ end
146
+ end
147
+ <%- if attributes -%>
148
+ property :attributes do
149
+ items do
150
+ <%- attributes.keys.each do |attribute| -%>
151
+ property :<%= attribute %> do
152
+ key :type, :string
153
+ end
154
+ <%- end -%>
155
+ end
156
+ end
157
+ <%- end -%>
158
+ <%- if relationships -%>
159
+ property :relationships do
160
+ <%- relationships.keys.each do |relationship| -%>
161
+ property :<%= relationship %> do
162
+ property :links do
163
+ property :self do
164
+ key :type, :string
165
+ end
166
+ property :related do
167
+ key :type, :string
168
+ end
169
+ end
170
+ end
171
+ <%- end -%>
172
+ end
173
+ <%- end -%>
174
+ end
175
+ end
176
+
177
+ swagger_schema :create_<%= model_name.singularize.underscore %> do
178
+ property :data do
179
+ property :type do
180
+ key :type, :string
181
+ end
182
+ <%- if attributes -%>
183
+ property :attributes do
184
+ items do
185
+ <%- attributes.keys.each do |attribute| -%>
186
+ property :<%= attribute %> do
187
+ key :type, :string
188
+ end
189
+ <%- end -%>
190
+ end
191
+ end
192
+ <%- end -%>
193
+ <%- if relationships -%>
194
+ property :relationships do
195
+ <%- relationships.each do |relationship| -%>
196
+ property :<%= relationship[0] %> do
197
+ property :data do
198
+ <%- if relationship[1].class.to_s == "JSONAPI::Relationship::ToOne" -%>
199
+ property :type do
200
+ key :type, :string
201
+ end
202
+ property :id do
203
+ key :type, :string
204
+ end
205
+ <%- elsif relationship[1].class.to_s == "JSONAPI::Relationship::ToMany" -%>
206
+ items do
207
+ property :type do
208
+ key :type, :string
209
+ end
210
+ property :id do
211
+ key :type, :string
212
+ end
213
+ end
214
+ <%- end -%>
215
+ end
216
+ end
217
+ <%- end -%>
218
+ end
219
+ <%- end -%>
220
+ end
221
+ end
222
+
223
+ swagger_schema :update_<%= model_name.singularize.underscore %> do
224
+ property :data do
225
+ property :type do
226
+ key :type, :string
227
+ end
228
+ <%- if attributes -%>
229
+ property :attributes do
230
+ items do
231
+ <%- attributes.keys.each do |attribute| -%>
232
+ property :<%= attribute %> do
233
+ key :type, :string
234
+ end
235
+ <%- end -%>
236
+ end
237
+ end
238
+ <%- end -%>
239
+ end
240
+ end
241
+ <%- relationships = "#{namespace}::#{model_name.camelcase}Resource".constantize._relationships -%>
242
+ <%- if relationships -%>
243
+ <% relationships.keys.each do |relationship| %>
244
+ swagger_schema :show_<%= relationship %>_from_<%= model_name.singularize.underscore %>_response do
245
+ <%- relation_relationships = "#{namespace}::#{relationship.to_s.camelcase.singularize}Resource".constantize._relationships -%>
246
+ <%- relation_attributes = "#{namespace}::#{relationship.to_s.camelcase.singularize}Resource".constantize._attributes -%>
247
+ property :data do
248
+ key :type, :array
249
+ items do
250
+ property :id do
251
+ key :type, :integer
252
+ end
253
+ property :type do
254
+ key :type, :string
255
+ end
256
+ <%- if relation_attributes -%>
257
+ property :attributes do
258
+ items do
259
+ <%- relation_attributes.keys.each do |attribute| -%>
260
+ property :<%= attribute %> do
261
+ key :type, :string
262
+ end
263
+ <%- end -%>
264
+ end
265
+ end
266
+ <%- end -%>
267
+ <%- if relation_relationships -%>
268
+ property :relationships do
269
+ <%- relation_relationships.keys.each do |relation_relationship| -%>
270
+ property :<%= relation_relationship %> do
271
+ property :links do
272
+ property :self do
273
+ key :type, :string
274
+ end
275
+ property :related do
276
+ key :type, :string
277
+ end
278
+ end
279
+ end
280
+ <%- end -%>
281
+ end
282
+ <%- end -%>
283
+ end
284
+ end
285
+ end
286
+
287
+ swagger_schema :show_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do
288
+ property :links do
289
+ property :self do
290
+ key :type, :string
291
+ end
292
+ property :related do
293
+ key :type, :string
294
+ end
295
+ end
296
+ property :data do
297
+ key :type, :array
298
+ items do
299
+ property :id do
300
+ key :type, :integer
301
+ end
302
+ property :type do
303
+ key :type, :string
304
+ end
305
+ end
306
+ end
307
+ end
308
+
309
+ swagger_schema :put_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do
310
+ property :data do
311
+ key :type, :array
312
+ items do
313
+ property :id do
314
+ key :type, :integer
315
+ end
316
+ property :type do
317
+ key :type, :string
318
+ end
319
+ end
320
+ end
321
+ end
322
+
323
+ swagger_schema :update_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do
324
+ property :data do
325
+ key :type, :array
326
+ items do
327
+ property :id do
328
+ key :type, :integer
329
+ end
330
+ property :type do
331
+ key :type, :string
332
+ end
333
+ end
334
+ end
335
+ end
336
+
337
+ swagger_schema :delete_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do
338
+ property :data do
339
+ key :type, :array
340
+ items do
341
+ property :id do
342
+ key :type, :integer
343
+ end
344
+ property :type do
345
+ key :type, :string
346
+ end
347
+ end
348
+ end
349
+ end
350
+ <%- end -%>
351
+ <%- end -%>
352
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsonapi
4
+ module Swagger
5
+ module Blocks
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsonapi
4
+ module Swagger
5
+ module Blocks
6
+ module Generator
7
+ VERSION = "0.1.1".freeze
8
+ end
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsonapi-swagger-blocks-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gleydson Tavares
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: The swagger-bloks files are created based on the JSONAPI::Resources files.
56
+ To use this gem, you need to have jsonapi-resources gem installed.
57
+ email:
58
+ - tavares.gleydson@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".simplecov"
67
+ - ".travis.yml"
68
+ - CODE_OF_CONDUCT.md
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - jsonapi-swagger-blocks-generator.gemspec
77
+ - lib/generators/jsonapi/USAGE
78
+ - lib/generators/jsonapi/swagger_blocks_generator.rb
79
+ - lib/generators/jsonapi/templates/controller_template.template
80
+ - lib/generators/jsonapi/templates/model_template.template
81
+ - lib/jsonapi/swagger/blocks/generator.rb
82
+ - lib/jsonapi/swagger/blocks/generator/version.rb
83
+ homepage: https://github.com/g13ydson/jsonapi-swagger-blocks-generator
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.14
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: creates swagger blocks files based on the JSONAPI::Resource
107
+ test_files: []