Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Inconsistent XML element names when returning an array versus an object

Đang mở
#235 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
api

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug? question

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?

Ngôn ngữ chính
Ruby
Star
730
Fork
154
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby-grape/grape-entity

Tất cả issue của ruby-grape/grape-entity

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.