fix "undefined method array or #<ActiveRecord::ConnectionAdapters::MySQL::Column"

This commit is contained in:
Junichiro Kasuya 2020-11-11 11:49:23 +09:00
parent 9eae4f0b0b
commit a0f7422793

View File

@ -132,14 +132,15 @@ module Jsonapi
end end
model_klass.columns.each do |col| model_klass.columns.each do |col|
col_name = transform_method ? col.name.send(transform_method) : col.name col_name = transform_method ? col.name.send(transform_method) : col.name
clos[col_name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: col.array, nullable: col.null, comment: col.comment } is_array = col.respond_to?(:array) ? col.array : false
clos[col_name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: is_array, nullable: col.null, comment: col.comment }
clos[col_name.to_sym][:comment] = safe_encode(col.comment) if need_encoding clos[col_name.to_sym][:comment] = safe_encode(col.comment) if need_encoding
end end
end end
end end
def swagger_type(column) def swagger_type(column)
return 'array' if column.array return 'array' if column.respond_to?(:array) && column.array
case column.type case column.type
when :bigint, :integer then 'integer' when :bigint, :integer then 'integer'
@ -168,4 +169,4 @@ module Jsonapi
content&.force_encoding('ASCII-8BIT') content&.force_encoding('ASCII-8BIT')
end end
end end
end end