File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -522,6 +522,37 @@ module API
522522end
523523```
524524
525+ ### Caveats
526+
527+ Entities with duplicate exposure names and conditions will silently overwrite one another.
528+ In the following example, when object#check equals "foo", only afield will be exposed.
529+ However, when object#check equals "bar" both bfield and foo will be exposed.
530+
531+ ``` ruby
532+ module API
533+ module Entities
534+ class User < Grape ::Entity
535+ expose :afield , :foo , :if => lambda {|object ,options | object.check== " foo" }
536+ expose :bfield , :foo , :if => lambda {|object ,options | object.check== " bar" }
537+ end
538+ end
539+ end
540+ ```
541+
542+ This can be problematic, when you have mixed collections. Using #respond_to? is safer.
543+
544+ ``` ruby
545+ module API
546+ module Entities
547+ class User < Grape ::Entity
548+ expose :afield , :if => lambda {|object ,options | object.check== " foo" }
549+ expose :bfield , :if => lambda {|object ,options | object.check== " bar" }
550+ expose :foo , :if => lambda {object,options| object.respond_to?(:foo )}
551+ end
552+ end
553+ end
554+ ```
555+
525556## Describing and Inspecting an API
526557
527558Grape lets you add a description to an API along with any other optional
You can’t perform that action at this time.
0 commit comments