Skip to content

@documentation memoization is slightly incorrect #153

Closed
@marshall-lee

Description

@marshall-lee
def self.documentation
  @documentation ||= exposures.each_with_object({}) do |(attribute, exposure_options), memo|
    if exposure_options[:documentation].present?
      memo[key_for(attribute)] = exposure_options[:documentation]
    end
  end
end

It works incorrect in this corner case:

entity_class = Class.new(Grape::Entity)
entity_class.expose :x, documentation: { desc: 'just x' }
doc1 = entity_class.documentation
entity_class.expose :y, documentation: { desc: 'just y' }
doc2 = entity_class.documentation
doc1 # => {:x=>{:desc=>"just x"}} 
doc1 == doc2 # => true

It could be fixed simply by assigning nil to @documentation in expose and unexpose.
Will be fixed in #151

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions