Inconsistent XML element names when returning an array versus an object
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with item.rb and compare the XML serialization entry points for an array of Items and a single Item. Review issues #38 and #23, including the formatter and root approaches mentioned there. Done means establishing consistent element names without making the JSON keys inconsistent.
Written by the indexing model from the issue text.
Description
I have an entity that I am using both for presenting an array of Item objects as well as singular Item objects. I was surprised to see that when returning XML the element names are different in these two very similar situations.
item.rb
module Legacy
module V1
module Entities
# Defines the combined item entity
class Item < Grape::Entity
expose :object, as: 'itemmast', using: Entities::Itemmast
expose :object, as: 'loclvl', using: Entities::Loclvl
end
end
end
end
Response Body: Array of Items
<legacy_v1_entities_items type="array">
<legacy_v1_entities_item>
<itemmast>
<ALPHAPC>00001</ALPHAPC>
<PC type="integer">1</PC>
</itemmast>
<loclvl>
<UPC type="integer">1</UPC>
</loclvl>
</legacy_v1_entities_item>
<legacy_v1_entities_item>
<itemmast>
<ALPHAPC>00002</ALPHAPC>
<PC type="integer">2</PC>
</itemmast>
<loclvl>
<UPC type="integer">2</UPC>
</loclvl>
</legacy_v1_entities_item>
</legacy_v1_entities_items>
Response Body: Single Item Object
<hash>
<itemmast>
<ALPHAPC>00001</ALPHAPC>
<PC type="integer">1</PC>
</itemmast>
<loclvl>
<UPC type="integer">1</UPC>
</loclvl>
</hash>
I've looked at issues #38 and #23, and while I can add a formatter as suggested this can lead to issues with entities which don't follow the same pattern. Additionally, if I change the root in this particular entity, the keys in the resulting JSON response are then inconsistent. Can anyone point me in the right direction of how to approach solving this inconsistency?
- Dominant language
- Ruby
- Stars
- 730
- Forks
- 155
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby-grape/grape-entity
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ruby-grape/grape-entity#386 · 7 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#382 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#380 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
ruby-grape/grape-entity#373 · 2 comments ·
-
Truncate FormatterOpen
Difficulty 1/5 1-3 hours Newbie friendliness 45/100
ruby-grape/grape-entity#372 ·
All issues in ruby-grape/grape-entity
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rubys/roundhouse#444 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
sclorg/s2i-ruby-container#656 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
endoflife-date/endoflife.date#11277 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
yegor256/rubocop-elegant#92 ·