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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c446e231756b175405116dd7cd0af8b78a6eb201301827edb61e28aed7adefae
|
4
|
+
data.tar.gz: bb126b0779311dade78e676b3cd7658bdf88c489050802e8bb34d30db8b7f402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 = [
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
127
|
-
key :name, :
|
128
|
-
key :
|
129
|
-
|
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, :
|
200
|
+
key :type, :string
|
133
201
|
end
|
134
|
-
|
135
|
-
key :name, :
|
136
|
-
key :
|
137
|
-
|
138
|
-
|
139
|
-
key :
|
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
|
-
|
143
|
-
key :name, :
|
144
|
-
key :
|
145
|
-
|
146
|
-
|
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
|
-
|
151
|
-
key :
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
key :
|
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
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
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
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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
|
-
|
289
|
-
key :description, I18n.t("activerecord.models.#{model.name.underscore}.show.
|
290
|
-
default: "
|
291
|
-
|
292
|
-
|
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
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
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
|
-
|
313
|
-
key :description, I18n.t("activerecord.models.#{model.name.underscore}.
|
314
|
-
default: "
|
315
|
-
|
316
|
-
|
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
|
-
|
329
|
-
|
330
|
-
|
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
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
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
|
-
|
357
|
-
key :name, :
|
358
|
-
key :
|
359
|
-
|
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, :
|
429
|
+
key :type, :string
|
363
430
|
end
|
364
|
-
|
365
|
-
key :name, :
|
366
|
-
key :
|
367
|
-
|
368
|
-
|
369
|
-
key :
|
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
|
-
|
373
|
-
key :name, :
|
374
|
-
key :
|
375
|
-
|
376
|
-
|
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
|
-
|
381
|
-
key :
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
key :
|
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
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
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
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
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
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
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
|
-
|
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
|
data/lib/apicasso/version.rb
CHANGED