lib/grape-swagger/entity/parser.rb in grape-swagger-entity-0.3.2 vs lib/grape-swagger/entity/parser.rb in grape-swagger-entity-0.3.3

- old
+ new

@@ -15,19 +15,28 @@ parse_grape_entity_params(extract_params(model)) end private + class Alias + attr_reader :original, :renamed + def initialize(original, renamed) + @original = original + @renamed = renamed + end + end + 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 extracted_params = extract_params(entity_class) memo.merge!(extracted_params) else - memo[value.attribute] = value.send(:options) + opts = value.send(:options) + opts[:as] ? memo[Alias.new(value.attribute, opts[:as])] = opts : memo[value.attribute] = opts end end end def parse_grape_entity_params(params, parent_model = nil) @@ -37,9 +46,10 @@ documentation_options = entity_options.fetch(:documentation, {}) in_option = documentation_options.fetch(:in, nil).to_s hidden_option = documentation_options.fetch(:hidden, nil) next if in_option == 'header' || hidden_option == true + entity_name = entity_name.original if entity_name.is_a?(Alias) final_entity_name = entity_options.fetch(:as, entity_name) documentation = entity_options[:documentation] memo[final_entity_name] = if entity_options[:nesting] parse_nested(entity_name, entity_options, parent_model)