lib/open_api/dsl/helpers.rb in zero-rails_openapi-1.3.2 vs lib/open_api/dsl/helpers.rb in zero-rails_openapi-1.3.3

- old
+ new

@@ -9,13 +9,13 @@ # About `show_attrs`, see: # (1) BuilderSupport module: https://github.com/zhandao/zero-rails/blob/master/app/models/concerns/builder_support.rb # (2) config in model: https://github.com/zhandao/zero-rails/tree/master/app/models/good.rb # (3) jbuilder file: https://github.com/zhandao/zero-rails/blob/mster/app/views/api/v1/goods/index.json.jbuilder # in a word, BuilderSupport let you control the `output fields and nested association infos` very easily. - if model&.respond_to? :show_attrs + if model.respond_to? :show_attrs columns = model.columns.map(&:name).map(&:to_sym) - model&.show_attrs&.map do |attr| + model.show_attrs.map do |attr| if columns.include? attr index = columns.index attr type = model.columns[index].sql_type_metadata.type.to_s.camelize type = 'DateTime' if type == 'Datetime' { attr => Object.const_get(type) } @@ -24,16 +24,16 @@ assoc_model = Object.const_get(attr.to_s.split('_').first.singularize.camelize) { attr => load_schema(assoc_model) } end rescue next end else - model&.columns&.map do |column| + model.columns.map do |column| name = column.name.to_sym type = column.sql_type_metadata.type.to_s.camelize type = 'DateTime' if type == 'Datetime' { name => Object.const_get(type) } end - end&.compact&.reduce({ }, :merge) + end.compact.reduce({ }, :merge) rescue '' end # Arrow Writing: # response :RespComponent => [ '200', 'success', :json ] # It is equivalent to: