lib/grape-swagger/entity/parser.rb in grape-swagger-entity-0.2.5 vs lib/grape-swagger/entity/parser.rb in grape-swagger-entity-0.3.0

- old
+ new

@@ -20,21 +20,22 @@ def extract_params(exposure) exposure.root_exposures.each_with_object({}) do |value, memo| if value.for_merge && (value.respond_to?(:entity_class) || value.respond_to?(:using_class_name)) entity_class = value.respond_to?(:entity_class) ? value.entity_class : value.using_class_name - memo.merge!(extract_params(entity_class)) + extracted_params = extract_params(entity_class) + memo.merge!(extracted_params) else memo[value.attribute] = value.send(:options) end end end def parse_grape_entity_params(params, parent_model = nil) return unless params - params.each_with_object({}) do |(entity_name, entity_options), memo| + parsed = params.each_with_object({}) do |(entity_name, entity_options), memo| next if entity_options.fetch(:documentation, {}).fetch(:in, nil).to_s == 'header' final_entity_name = entity_options.fetch(:as, entity_name) documentation = entity_options[:documentation] @@ -46,10 +47,12 @@ next unless documentation memo[final_entity_name][:readOnly] = documentation[:read_only].to_s == 'true' if documentation[:read_only] memo[final_entity_name][:description] = documentation[:desc] if documentation[:desc] end + + [parsed, required_params(params)] end def parse_nested(entity_name, entity_options, parent_model = nil) nested_entity = if parent_model.nil? model.root_exposures.find_by(entity_name) @@ -59,12 +62,10 @@ params = nested_entity.nested_exposures.each_with_object({}) do |value, memo| memo[value.attribute] = value.send(:options) end - required = required_params(params) - - properties = parse_grape_entity_params(params, nested_entity) + properties, required = parse_grape_entity_params(params, nested_entity) is_a_collection = entity_options[:documentation].is_a?(Hash) && entity_options[:documentation][:type].to_s.casecmp('array').zero? if is_a_collection {