apicasso 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3546484905f1ef3c02adbfbdbf03e00ba32986b3424226ea92f749af82f863b0
4
- data.tar.gz: b0522514a3ce287bc71bbe2543cfc327a286346df29f52768d07853ae1d357da
3
+ metadata.gz: c446e231756b175405116dd7cd0af8b78a6eb201301827edb61e28aed7adefae
4
+ data.tar.gz: bb126b0779311dade78e676b3cd7658bdf88c489050802e8bb34d30db8b7f402
5
5
  SHA512:
6
- metadata.gz: 3bdae43c1597ed688f7d41794ee06b98a8b71bbdb4fcaa55bb8cdbb42dabe938501ca107ca34ce3a10c10b30104a2ae8e4e38f0f219d3eff4d51e7ff0998be5e
7
- data.tar.gz: 59e569b3589a918ded54f5ceb4759b8b55a86f7a3287666163c22ab40c53d1644758d5d516c325be200c0e52b2280ed48734f7c12dd82c5ae9ab52556ce3870d
6
+ metadata.gz: f8ecac9a9e8e6ff5f4aa1617614d6e8a7cccb90fb83ea049882af83f1cc4e575585dc2de94f8ea15e6c05df0aea2319070d367dee976f1edd72f10fd5a4d81bb
7
+ data.tar.gz: ae9da807a82ff8307b7c6114dd97b6967e146dfad2c5ac16acc69873c8c17b4c8a216cc1baecaca18319fa72fcb83706c98839dd192267c16830f19fbb5e5b4c
@@ -9,7 +9,16 @@ module Apicasso
9
9
  include Swagger::Blocks
10
10
 
11
11
  swagger_root do
12
- MODELS_EXCLUDED = [::ApplicationRecord, ActiveRecord::SchemaMigration, Apicasso::ApplicationRecord, Apicasso::Key, Apicasso::Request, Apicasso::ApidocsController, ActiveStorage::Attachment, ActiveStorage::Blob].freeze
12
+ MODELS_EXCLUDED = [
13
+ 'ApplicationRecord',
14
+ 'ActiveRecord::SchemaMigration',
15
+ 'Apicasso::ApplicationRecord',
16
+ 'Apicasso::Key',
17
+ 'Apicasso::Request',
18
+ 'Apicasso::ApidocsController',
19
+ 'ActiveStorage::Attachment',
20
+ 'ActiveStorage::Blob'
21
+ ].freeze
13
22
  key :swagger, '2.0'
14
23
  info do
15
24
  key :title, ENV.fetch('APP_NAME', I18n.t('application.name'))
@@ -24,11 +33,11 @@ module Apicasso
24
33
  end
25
34
  end
26
35
  ActiveRecord::Base.descendants.each do |model|
27
- unless MODELS_EXCLUDED.include?(model)
28
- tag do
29
- key :name, I18n.t("activerecord.models.#{model.name.underscore}", default: model.name.underscore)
30
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.description", default: model.name)
31
- end
36
+ next if MODELS_EXCLUDED.include?(model.name) || model.abstract_class
37
+
38
+ tag do
39
+ key :name, I18n.t("activerecord.models.#{model.name.underscore}", default: model.name.underscore)
40
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.description", default: model.name)
32
41
  end
33
42
  end
34
43
  key :host, I18n.t('application.apicasso_host', default: ENV.fetch('ROOT', 'localhost:3000'))
@@ -51,6 +60,10 @@ module Apicasso
51
60
  *ActiveRecord::Base.descendants,
52
61
  self
53
62
  ].freeze
63
+ ASSOCIATION_EXCLUDED = [
64
+ 'ActiveStorage::Attachment',
65
+ 'ActiveStorage::Blob'
66
+ ].freeze
54
67
  swagger_schema :ErrorModel do
55
68
  key :required, [:code, :message]
56
69
  property :code do
@@ -63,41 +76,41 @@ module Apicasso
63
76
  end
64
77
 
65
78
  SWAGGERED_CLASSES.each do |klass|
66
- unless MODELS_EXCLUDED.include?(klass)
67
- swagger_schema klass.name.to_sym do
68
- key :required, klass.presence_validators if klass.presence_validators?
69
- klass.columns_hash.each do |name, type|
70
- property name.to_sym do
71
- key :type, type.type
72
- end
79
+ next if MODELS_EXCLUDED.include?(klass.name) || klass.abstract_class
80
+
81
+ swagger_schema klass.name.to_sym do
82
+ key :required, klass.presence_validators if klass.presence_validators?
83
+ klass.columns_hash.each do |name, type|
84
+ property name.to_sym do
85
+ key :type, type.type
73
86
  end
74
87
  end
75
- swagger_schema "#{klass.name}Input".to_sym do
76
- allOf do
77
- schema do
78
- key :'$ref', "#{klass.name}Input".to_sym
79
- end
80
- schema do
81
- key :required, %i[*presence_validators] if klass.presence_validators?
82
- klass.columns_hash.each do |name, type|
83
- property name.to_sym do
84
- key :type, type.type
85
- end
88
+ end
89
+ swagger_schema "#{klass.name}Input".to_sym do
90
+ allOf do
91
+ schema do
92
+ key :'$ref', "#{klass.name}Input".to_sym
93
+ end
94
+ schema do
95
+ key :required, %i[*presence_validators] if klass.presence_validators?
96
+ klass.columns_hash.each do |name, type|
97
+ property name.to_sym do
98
+ key :type, type.type
86
99
  end
87
100
  end
88
101
  end
89
102
  end
90
- swagger_schema "#{klass.name}Metadata".to_sym do
91
- allOf do
92
- schema do
93
- key :'$ref', "#{klass.name}Metadata".to_sym
94
- end
95
- schema do
96
- klass.columns_hash.each do |name, type|
97
- property name.to_sym do
98
- key :description, type.type
99
- key :type, :string
100
- end
103
+ end
104
+ swagger_schema "#{klass.name}Metadata".to_sym do
105
+ allOf do
106
+ schema do
107
+ key :'$ref', "#{klass.name}Metadata".to_sym
108
+ end
109
+ schema do
110
+ klass.columns_hash.each do |name, type|
111
+ property name.to_sym do
112
+ key :description, type.type
113
+ key :type, :string
101
114
  end
102
115
  end
103
116
  end
@@ -106,367 +119,366 @@ module Apicasso
106
119
  end
107
120
 
108
121
  ActiveRecord::Base.descendants.each do |model|
109
- unless MODELS_EXCLUDED.include?(model)
110
- swagger_path "/#{model.name.underscore}" do
111
- operation :get do
112
- key :summary, I18n.t("activerecord.models.#{model.name.underscore}.index.summary", default: model.name)
113
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.index.description", default: model.name)
114
- key :operationId, "find#{model.name.pluralize}"
115
- key :produces, ['application/json']
116
- key :tags, [model.name.underscore]
117
- parameter do
118
- key :name, :sort
119
- key :in, :query
120
- key :description, I18n.t('apicasso.sort.description',
121
- default: 'Parameters sorting splitted by `,` preffixed by `+` or `-` which translates into ascending or descending order')
122
+ next if MODELS_EXCLUDED.include?(model.name) || model.abstract_class
123
+
124
+ swagger_path "/#{model.name.underscore}" do
125
+ operation :get do
126
+ key :summary, I18n.t("activerecord.models.#{model.name.underscore}.index.summary", default: model.name)
127
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.index.description", default: model.name)
128
+ key :operationId, "find#{model.name.pluralize}"
129
+ key :produces, ['application/json']
130
+ key :tags, [model.name.underscore]
131
+ parameter do
132
+ key :name, :sort
133
+ key :in, :query
134
+ key :description, I18n.t('apicasso.sort.description',
135
+ default: 'Parameters sorting splitted by `,` preffixed by `+` or `-` which translates into ascending or descending order')
136
+ key :required, false
137
+ key :type, :string
138
+ key :collectionFormat, :json
139
+ end
140
+ parameter do
141
+ key :name, :q
142
+ key :in, :query
143
+ key :description, I18n.t('apicasso.q.description',
144
+ default: 'Records filtering by attribute and search query as affix. Usage: `?q[{attribute}{search_affix}]={matcher}`. All available search affixes are listed on: https://github.com/activerecord-hackery/ransack#search-matchers')
145
+ key :required, false
146
+ key :type, :json
147
+ end
148
+ parameter do
149
+ key :name, :page
150
+ key :in, :query
151
+ key :description, I18n.t('apicasso.page.description',
152
+ default: 'Records pagination paging, which offsets collection based on `params[:per_page]`')
153
+ key :required, false
154
+ key :type, :integer
155
+ end
156
+ parameter do
157
+ key :name, :per_page
158
+ key :in, :query
159
+ key :description, I18n.t('apicasso.per_page.description',
160
+ default: 'Records pagination size, which sets how many records will be rendered per request')
161
+ key :required, false
162
+ key :type, :integer
163
+ end
164
+ response 200 do
165
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.index.response",
166
+ default: "#{model.name} response, which include records matching current query and pagination metadata")
167
+ schema do
168
+ key :name, :total
169
+ key :description, I18n.t('apicasso.total.description',
170
+ default: 'Total records contained in current collection, as if there was no pagination.')
171
+ key :required, true
172
+ key :type, :integer
173
+ end
174
+ schema do
175
+ key :name, :total_pages
176
+ key :description, I18n.t('apicasso.total_pages.description',
177
+ default: 'How many pages of data the current collection has.')
178
+ key :required, true
179
+ key :type, :integer
180
+ end
181
+ schema do
182
+ key :name, :last_page
183
+ key :description, I18n.t('apicasso.last_page.description',
184
+ default: 'An indication if current request is the last to paginate in the current collection')
185
+ key :required, true
186
+ key :type, :boolean
187
+ end
188
+ schema do
189
+ key :name, :previous_page
190
+ key :description, I18n.t('apicasso.previous_page.description',
191
+ default: "The link of the previous page for the current collection. It can be null if there isn't any")
122
192
  key :required, false
123
193
  key :type, :string
124
- key :collectionFormat, :json
125
194
  end
126
- parameter do
127
- key :name, :q
128
- key :in, :query
129
- key :description, I18n.t('apicasso.q.description',
130
- default: 'Records filtering by attribute and search query as affix. Usage: `?q[{attribute}{search_affix}]={matcher}`. All available search affixes are listed on: https://github.com/activerecord-hackery/ransack#search-matchers')
195
+ schema do
196
+ key :name, :next_page
197
+ key :description, I18n.t('apicasso.next_page.description',
198
+ default: "The link of the next page for the current collection. It can be null if there isn't any")
131
199
  key :required, false
132
- key :type, :json
200
+ key :type, :string
133
201
  end
134
- parameter do
135
- key :name, :page
136
- key :in, :query
137
- key :description, I18n.t('apicasso.page.description',
138
- default: 'Records pagination paging, which offsets collection based on `params[:per_page]`')
139
- key :required, false
140
- key :type, :integer
202
+ schema do
203
+ key :name, :out_of_bounds
204
+ key :description, I18n.t('apicasso.out_of_bounds.description',
205
+ default: 'An indication if current request is out of pagination bounds for the current collection')
206
+ key :required, true
207
+ key :type, :boolean
141
208
  end
142
- parameter do
143
- key :name, :per_page
144
- key :in, :query
145
- key :description, I18n.t('apicasso.per_page.description',
146
- default: 'Records pagination size, which sets how many records will be rendered per request')
147
- key :required, false
209
+ schema do
210
+ key :name, :offset
211
+ key :description, I18n.t('apicasso.offset.description',
212
+ default: 'How many records were offsetted from the collection to render the current page')
213
+ key :required, true
148
214
  key :type, :integer
149
215
  end
150
- response 200 do
151
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.index.response",
152
- default: "#{model.name} response, which include records matching current query and pagination metadata")
153
- schema do
154
- key :name, :total
155
- key :description, I18n.t('apicasso.total.description',
156
- default: 'Total records contained in current collection, as if there was no pagination.')
157
- key :required, true
158
- key :type, :integer
159
- end
160
- schema do
161
- key :name, :total_pages
162
- key :description, I18n.t('apicasso.total_pages.description',
163
- default: 'How many pages of data the current collection has.')
164
- key :required, true
165
- key :type, :integer
166
- end
167
- schema do
168
- key :name, :last_page
169
- key :description, I18n.t('apicasso.last_page.description',
170
- default: 'An indication if current request is the last to paginate in the current collection')
171
- key :required, true
172
- key :type, :boolean
173
- end
174
- schema do
175
- key :name, :previous_page
176
- key :description, I18n.t('apicasso.previous_page.description',
177
- default: "The link of the previous page for the current collection. It can be null if there isn't any")
178
- key :required, false
179
- key :type, :string
180
- end
181
- schema do
182
- key :name, :next_page
183
- key :description, I18n.t('apicasso.next_page.description',
184
- default: "The link of the next page for the current collection. It can be null if there isn't any")
185
- key :required, false
186
- key :type, :string
187
- end
188
- schema do
189
- key :name, :out_of_bounds
190
- key :description, I18n.t('apicasso.out_of_bounds.description',
191
- default: 'An indication if current request is out of pagination bounds for the current collection')
192
- key :required, true
193
- key :type, :boolean
194
- end
195
- schema do
196
- key :name, :offset
197
- key :description, I18n.t('apicasso.offset.description',
198
- default: 'How many records were offsetted from the collection to render the current page')
199
- key :required, true
200
- key :type, :integer
201
- end
202
- schema do
203
- key :name, :entries
204
- key :description, I18n.t('apicasso.entries.description',
205
- default: 'The records collection in the current pagination scope.')
206
- key :required, true
207
- key :type, :array
208
- items do
209
- key :'$ref', model.name.to_sym
210
- end
216
+ schema do
217
+ key :name, :entries
218
+ key :description, I18n.t('apicasso.entries.description',
219
+ default: 'The records collection in the current pagination scope.')
220
+ key :required, true
221
+ key :type, :array
222
+ items do
223
+ key :'$ref', model.name.to_sym
211
224
  end
212
225
  end
213
226
  end
214
- operation :options do
215
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.schema.description",
216
- default: "#{model.name} metadata information.")
217
- key :operationId, "schema#{model.name.pluralize}"
218
- key :produces, ['application/json']
219
- key :tags, [model.name.underscore]
220
- response 200 do
221
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.schema.response",
222
- default: "#{model.name} metadata as a json with field names as keys and field types as values.")
223
- schema do
224
- key :'$ref', "#{model.name}".to_sym
225
- end
227
+ end
228
+ operation :options do
229
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.schema.description",
230
+ default: "#{model.name} metadata information.")
231
+ key :operationId, "schema#{model.name.pluralize}"
232
+ key :produces, ['application/json']
233
+ key :tags, [model.name.underscore]
234
+ response 200 do
235
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.schema.response",
236
+ default: "#{model.name} metadata as a json with field names as keys and field types as values.")
237
+ schema do
238
+ key :'$ref', "#{model.name}".to_sym
226
239
  end
227
240
  end
228
- operation :post do
229
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.create.response",
230
- default: "Creates a #{model.name}")
231
- key :operationId, "add#{model.name}"
232
- key :produces, ['application/json']
233
- key :tags, [model.name.underscore]
234
- parameter do
235
- key :name, model.name.underscore.to_sym
236
- key :in, :body
237
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.create.description",
238
- default: "#{model.name} to add into application")
239
- key :required, true
240
- schema do
241
- key :'$ref', "#{model.name}".to_sym
242
- end
241
+ end
242
+ operation :post do
243
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.create.response",
244
+ default: "Creates a #{model.name}")
245
+ key :operationId, "add#{model.name}"
246
+ key :produces, ['application/json']
247
+ key :tags, [model.name.underscore]
248
+ parameter do
249
+ key :name, model.name.underscore.to_sym
250
+ key :in, :body
251
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.create.description",
252
+ default: "#{model.name} to add into application")
253
+ key :required, true
254
+ schema do
255
+ key :'$ref', "#{model.name}".to_sym
243
256
  end
244
- response 201 do
245
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.description",
246
- default: "#{model.name} response")
247
- schema do
248
- key :'$ref', model.name.to_sym
249
- end
257
+ end
258
+ response 201 do
259
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.description",
260
+ default: "#{model.name} response")
261
+ schema do
262
+ key :'$ref', model.name.to_sym
250
263
  end
251
264
  end
252
265
  end
253
- swagger_path "/#{model.name.underscore}/{id}" do
254
- operation :patch do
255
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.update.response",
256
- default: "Updates a #{model.name}")
257
- key :operationId, "edit#{model.name}"
258
- key :produces, ['application/json']
259
- key :tags, [model.name.underscore]
260
- parameter do
261
- key :name, :id
262
- key :in, :path
263
- key :description, I18n.t("activerecord.models.attributes.#{model.name.underscore}.id",
264
- default: "ID of #{model.name} to update on the application")
265
- key :required, true
266
- schema do
267
- key :'$ref', "#{model.name}".to_sym
268
- end
269
- end
270
- parameter do
271
- key :name, model.name.underscore.to_sym
272
- key :in, :body
273
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.update.description",
274
- default: "Existing #{model.name} to update on the application")
275
- key :required, true
276
- schema do
277
- key :'$ref', "#{model.name}".to_sym
278
- end
266
+ end
267
+ swagger_path "/#{model.name.underscore}/{id}" do
268
+ operation :patch do
269
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.update.response",
270
+ default: "Updates a #{model.name}")
271
+ key :operationId, "edit#{model.name}"
272
+ key :produces, ['application/json']
273
+ key :tags, [model.name.underscore]
274
+ parameter do
275
+ key :name, :id
276
+ key :in, :path
277
+ key :description, I18n.t("activerecord.models.attributes.#{model.name.underscore}.id",
278
+ default: "ID of #{model.name} to update on the application")
279
+ key :required, true
280
+ schema do
281
+ key :'$ref', "#{model.name}".to_sym
279
282
  end
280
- response 200 do
281
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.description",
282
- default: "#{model.name} response")
283
- schema do
284
- key :'$ref', model.name.to_sym
285
- end
283
+ end
284
+ parameter do
285
+ key :name, model.name.underscore.to_sym
286
+ key :in, :body
287
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.update.description",
288
+ default: "Existing #{model.name} to update on the application")
289
+ key :required, true
290
+ schema do
291
+ key :'$ref', "#{model.name}".to_sym
286
292
  end
287
293
  end
288
- operation :get do
289
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.response",
290
- default: "Creates a #{model.name}")
291
- key :operationId, "show#{model.name}"
292
- key :produces, ['application/json']
293
- key :tags, [model.name.underscore]
294
- parameter do
295
- key :name, :id
296
- key :in, :path
297
- key :description, I18n.t("activerecord.models.attributes.#{model.name.underscore}.id",
298
- default: "ID of #{model.name} to fetch on the application")
299
- key :required, true
300
- schema do
301
- key :'$ref', "#{model.name}".to_sym
302
- end
294
+ response 200 do
295
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.description",
296
+ default: "#{model.name} response")
297
+ schema do
298
+ key :'$ref', model.name.to_sym
303
299
  end
304
- response 200 do
305
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.description",
306
- default: "#{model.name} response")
307
- schema do
308
- key :'$ref', model.name.to_sym
309
- end
300
+ end
301
+ end
302
+ operation :get do
303
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.response",
304
+ default: "Creates a #{model.name}")
305
+ key :operationId, "show#{model.name}"
306
+ key :produces, ['application/json']
307
+ key :tags, [model.name.underscore]
308
+ parameter do
309
+ key :name, :id
310
+ key :in, :path
311
+ key :description, I18n.t("activerecord.models.attributes.#{model.name.underscore}.id",
312
+ default: "ID of #{model.name} to fetch on the application")
313
+ key :required, true
314
+ schema do
315
+ key :'$ref', "#{model.name}".to_sym
310
316
  end
311
317
  end
312
- operation :delete do
313
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.destroy.response",
314
- default: "Deletes a #{model.name}")
315
- key :operationId, "destroy#{model.name}"
316
- key :produces, ['application/json']
317
- key :tags, [model.name.underscore]
318
- parameter do
319
- key :name, :id
320
- key :in, :path
321
- key :description, I18n.t("activerecord.models.attributes.#{model.name.underscore}.id",
322
- default: "ID of #{model.name} to delete on the application")
323
- key :required, true
324
- schema do
325
- key :'$ref', "#{model.name}".to_sym
326
- end
318
+ response 200 do
319
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.description",
320
+ default: "#{model.name} response")
321
+ schema do
322
+ key :'$ref', model.name.to_sym
327
323
  end
328
- response 200 do
329
- key :description, I18n.t("activerecord.models.#{model.name.underscore}.destroy.description",
330
- default: "#{model.name} response")
324
+ end
325
+ end
326
+ operation :delete do
327
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.destroy.response",
328
+ default: "Deletes a #{model.name}")
329
+ key :operationId, "destroy#{model.name}"
330
+ key :produces, ['application/json']
331
+ key :tags, [model.name.underscore]
332
+ parameter do
333
+ key :name, :id
334
+ key :in, :path
335
+ key :description, I18n.t("activerecord.models.attributes.#{model.name.underscore}.id",
336
+ default: "ID of #{model.name} to delete on the application")
337
+ key :required, true
338
+ schema do
339
+ key :'$ref', "#{model.name}".to_sym
331
340
  end
332
341
  end
342
+ response 200 do
343
+ key :description, I18n.t("activerecord.models.#{model.name.underscore}.destroy.description",
344
+ default: "#{model.name} response")
345
+ end
333
346
  end
347
+ end
334
348
 
335
- model.reflect_on_all_associations.map(&:name).each do |association|
336
- inner_name = model.reflect_on_all_associations.select{ |ass| ass.name == association }.first.class_name
337
- ASSOCIATION_EXCLUDED = ['ActiveStorage::Attachment', 'ActiveStorage::Blob'].freeze
338
- unless ASSOCIATION_EXCLUDED.include?(inner_name)
339
- inner_klass = begin inner_name.constantize rescue NameError; false end
340
- swagger_path "/#{model.name.underscore}/{id}/#{association}" do
341
- operation :get do
342
- key :summary, I18n.t("activerecord.models.#{inner_name.underscore}.index.summary", default: inner_name)
343
- key :description, I18n.t("activerecord.models.#{inner_name.underscore}.index.description", default: inner_name)
344
- key :operationId, "find#{inner_name.pluralize}"
345
- key :produces, ['application/json']
346
- key :tags, [inner_name.underscore]
347
- parameter do
348
- key :name, :sort
349
- key :in, :query
350
- key :description, I18n.t('apicasso.sort.description',
351
- default: 'Parameters sorting splitted by `,` preffixed by `+` or `-` which translates into ascending or descending order')
349
+ model.reflect_on_all_associations.map(&:name).each do |association|
350
+ inner_name = association.to_s.classify
351
+ unless ASSOCIATION_EXCLUDED.include?(inner_name)
352
+ inner_klass = begin inner_name.constantize rescue NameError; false end
353
+ swagger_path "/#{model.name.underscore}/{id}/#{association}" do
354
+ operation :get do
355
+ key :summary, I18n.t("activerecord.models.#{inner_name.underscore}.index.summary", default: inner_name)
356
+ key :description, I18n.t("activerecord.models.#{inner_name.underscore}.index.description", default: inner_name)
357
+ key :operationId, "find#{inner_name.pluralize}"
358
+ key :produces, ['application/json']
359
+ key :tags, [inner_name.underscore]
360
+ parameter do
361
+ key :name, :sort
362
+ key :in, :query
363
+ key :description, I18n.t('apicasso.sort.description',
364
+ default: 'Parameters sorting splitted by `,` preffixed by `+` or `-` which translates into ascending or descending order')
365
+ key :required, false
366
+ key :type, :string
367
+ key :collectionFormat, :json
368
+ end
369
+ parameter do
370
+ key :name, :q
371
+ key :in, :query
372
+ key :description, I18n.t('apicasso.q.description',
373
+ default: 'Records filtering by attribute and search query as affix. Usage: `?q[{attribute}{search_affix}]={matcher}`. All available search affixes are listed on: https://github.com/activerecord-hackery/ransack#search-matchers')
374
+ key :required, false
375
+ key :type, :json
376
+ end
377
+ parameter do
378
+ key :name, :page
379
+ key :in, :query
380
+ key :description, I18n.t('apicasso.page.description',
381
+ default: 'Records pagination paging, which offsets collection based on `params[:per_page]`')
382
+ key :required, false
383
+ key :type, :integer
384
+ end
385
+ parameter do
386
+ key :name, :per_page
387
+ key :in, :query
388
+ key :description, I18n.t('apicasso.per_page.description',
389
+ default: 'Records pagination size, which sets how many records will be rendered per request')
390
+ key :required, false
391
+ key :type, :integer
392
+ end
393
+ response 200 do
394
+ key :description, I18n.t("activerecord.models.#{inner_name.underscore}.index.response",
395
+ default: "#{inner_name} response, which include records matching current query and pagination metadata")
396
+ schema do
397
+ key :name, :total
398
+ key :description, I18n.t('apicasso.total.description',
399
+ default: 'Total records contained in current collection, as if there was no pagination.')
400
+ key :required, true
401
+ key :type, :integer
402
+ end
403
+ schema do
404
+ key :name, :total_pages
405
+ key :description, I18n.t('apicasso.total_pages.description',
406
+ default: 'How many pages of data the current collection has.')
407
+ key :required, true
408
+ key :type, :integer
409
+ end
410
+ schema do
411
+ key :name, :last_page
412
+ key :description, I18n.t('apicasso.last_page.description',
413
+ default: 'An indication if current request is the last to paginate in the current collection')
414
+ key :required, true
415
+ key :type, :boolean
416
+ end
417
+ schema do
418
+ key :name, :previous_page
419
+ key :description, I18n.t('apicasso.previous_page.description',
420
+ default: "The link of the previous page for the current collection. It can be null if there isn't any")
352
421
  key :required, false
353
422
  key :type, :string
354
- key :collectionFormat, :json
355
423
  end
356
- parameter do
357
- key :name, :q
358
- key :in, :query
359
- key :description, I18n.t('apicasso.q.description',
360
- default: 'Records filtering by attribute and search query as affix. Usage: `?q[{attribute}{search_affix}]={matcher}`. All available search affixes are listed on: https://github.com/activerecord-hackery/ransack#search-matchers')
424
+ schema do
425
+ key :name, :next_page
426
+ key :description, I18n.t('apicasso.next_page.description',
427
+ default: "The link of the next page for the current collection. It can be null if there isn't any")
361
428
  key :required, false
362
- key :type, :json
429
+ key :type, :string
363
430
  end
364
- parameter do
365
- key :name, :page
366
- key :in, :query
367
- key :description, I18n.t('apicasso.page.description',
368
- default: 'Records pagination paging, which offsets collection based on `params[:per_page]`')
369
- key :required, false
370
- key :type, :integer
431
+ schema do
432
+ key :name, :out_of_bounds
433
+ key :description, I18n.t('apicasso.out_of_bounds.description',
434
+ default: 'An indication if current request is out of pagination bounds for the current collection')
435
+ key :required, true
436
+ key :type, :boolean
371
437
  end
372
- parameter do
373
- key :name, :per_page
374
- key :in, :query
375
- key :description, I18n.t('apicasso.per_page.description',
376
- default: 'Records pagination size, which sets how many records will be rendered per request')
377
- key :required, false
438
+ schema do
439
+ key :name, :offset
440
+ key :description, I18n.t('apicasso.offset.description',
441
+ default: 'How many records were offsetted from the collection to render the current page')
442
+ key :required, true
378
443
  key :type, :integer
379
444
  end
380
- response 200 do
381
- key :description, I18n.t("activerecord.models.#{inner_name.underscore}.index.response",
382
- default: "#{inner_name} response, which include records matching current query and pagination metadata")
383
- schema do
384
- key :name, :total
385
- key :description, I18n.t('apicasso.total.description',
386
- default: 'Total records contained in current collection, as if there was no pagination.')
387
- key :required, true
388
- key :type, :integer
389
- end
390
- schema do
391
- key :name, :total_pages
392
- key :description, I18n.t('apicasso.total_pages.description',
393
- default: 'How many pages of data the current collection has.')
394
- key :required, true
395
- key :type, :integer
396
- end
397
- schema do
398
- key :name, :last_page
399
- key :description, I18n.t('apicasso.last_page.description',
400
- default: 'An indication if current request is the last to paginate in the current collection')
401
- key :required, true
402
- key :type, :boolean
403
- end
404
- schema do
405
- key :name, :previous_page
406
- key :description, I18n.t('apicasso.previous_page.description',
407
- default: "The link of the previous page for the current collection. It can be null if there isn't any")
408
- key :required, false
409
- key :type, :string
410
- end
411
- schema do
412
- key :name, :next_page
413
- key :description, I18n.t('apicasso.next_page.description',
414
- default: "The link of the next page for the current collection. It can be null if there isn't any")
415
- key :required, false
416
- key :type, :string
417
- end
418
- schema do
419
- key :name, :out_of_bounds
420
- key :description, I18n.t('apicasso.out_of_bounds.description',
421
- default: 'An indication if current request is out of pagination bounds for the current collection')
422
- key :required, true
423
- key :type, :boolean
424
- end
425
- schema do
426
- key :name, :offset
427
- key :description, I18n.t('apicasso.offset.description',
428
- default: 'How many records were offsetted from the collection to render the current page')
429
- key :required, true
430
- key :type, :integer
431
- end
432
- schema do
433
- key :name, :entries
434
- key :description, I18n.t('apicasso.entries.description',
435
- default: 'The records collection in the current pagination scope.')
436
- key :required, true
437
- key :type, :array
438
- items do
439
- key :'$ref', "#{inner_name}".to_sym
440
- end
445
+ schema do
446
+ key :name, :entries
447
+ key :description, I18n.t('apicasso.entries.description',
448
+ default: 'The records collection in the current pagination scope.')
449
+ key :required, true
450
+ key :type, :array
451
+ items do
452
+ key :'$ref', "#{inner_name}".to_sym
441
453
  end
442
454
  end
443
- response :default do
444
- key :description, I18n.t("activerecord.errors.models.#{inner_name.underscore}",
445
- default: "Unexpected error in #{inner_name}")
446
- schema do
447
- key :'$ref', :ErrorModel
448
- end
455
+ end
456
+ response :default do
457
+ key :description, I18n.t("activerecord.errors.models.#{inner_name.underscore}",
458
+ default: "Unexpected error in #{inner_name}")
459
+ schema do
460
+ key :'$ref', :ErrorModel
449
461
  end
450
462
  end
451
- operation :options do
452
- key :description, I18n.t("activerecord.models.#{inner_name.underscore}.schema.description",
453
- default: "#{inner_name} metadata information.")
454
- key :operationId, "schema#{inner_name.pluralize}"
455
- key :produces, ['application/json']
456
- key :tags, [inner_name.underscore]
457
- response 200 do
458
- key :description, I18n.t("activerecord.models.#{inner_name.underscore}.schema.response",
459
- default: "#{inner_name} metadata as a json with field names as keys and field types as values.")
460
- schema do
461
- key :'$ref', "#{inner_name}".to_sym
462
- end
463
+ end
464
+ operation :options do
465
+ key :description, I18n.t("activerecord.models.#{inner_name.underscore}.schema.description",
466
+ default: "#{inner_name} metadata information.")
467
+ key :operationId, "schema#{inner_name.pluralize}"
468
+ key :produces, ['application/json']
469
+ key :tags, [inner_name.underscore]
470
+ response 200 do
471
+ key :description, I18n.t("activerecord.models.#{inner_name.underscore}.schema.response",
472
+ default: "#{inner_name} metadata as a json with field names as keys and field types as values.")
473
+ schema do
474
+ key :'$ref', "#{inner_name}".to_sym
463
475
  end
464
- response :default do
465
- key :description, I18n.t("activerecord.errors.models.#{inner_name.underscore}",
466
- default: "Unexpected error in #{inner_name}")
467
- schema do
468
- key :'$ref', :ErrorModel
469
- end
476
+ end
477
+ response :default do
478
+ key :description, I18n.t("activerecord.errors.models.#{inner_name.underscore}",
479
+ default: "Unexpected error in #{inner_name}")
480
+ schema do
481
+ key :'$ref', :ErrorModel
470
482
  end
471
483
  end
472
484
  end
@@ -163,11 +163,7 @@ module Apicasso
163
163
 
164
164
  # A method to allow origin customizing through method overriding
165
165
  def allow_origin
166
- if request.headers['Referer'].present?
167
- request.protocol + URI(request.headers['Referer']).host
168
- else
169
- request.headers['Origin'] || '*'
170
- end
166
+ request.headers['Referer'] || request.headers['Origin'] || '*'
171
167
  end
172
168
 
173
169
  # Checks if current request is a CORS preflight check
@@ -1,3 +1,3 @@
1
1
  module Apicasso
2
- VERSION = '0.4.9'.freeze
2
+ VERSION = '0.4.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apicasso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Bellincanta