I am writing an API with Grape for may Rails 6 application.
I have a model with custom columns (depending on specification). I generate a patch request parameters list, and I would like to generate desc and type with a function. But I do not know if it is possible, and if yes, where to put the function (all I tried do not work).
This is a part of my Api class.
class MyObject < Grape::API
# ...
desc 'Update a MyObject.'
params do
requires :id, type: Integer, desc: 'MyObject ID.', documentation: {param_type: 'body'}
optional :title, type: String, desc: 'MyObject Title.', documentation: {param_type: 'body'}
optional :custom_field_attributes, type: Hash, documentation: {param_type: 'body'} do
CustomField.column_names.each do |cf|
next unless cf.include? 'custom_'
optional cf.intern,
type: custom_field_type(cf), # Here I would like to call a function
desc: custom_field_desc(cf) # Here too
end
end
end
patch do
# ...
end
end
Is it possible to do this ?