rubygarage / api_struct

API wrapper builder with response serialization
MIT License
234 stars 21 forks source link

Issue with serializing related entites #11

Open TheFifthFreedom opened 4 years ago

TheFifthFreedom commented 4 years ago

@kirillshevch I'm using version 1.0.5, and there seems to be an issue with serializing related entities - here's a quick and dirty example with the Stripe API:

module StripeApi
  module Entities
    class Person < ApiStruct::Entity
      client_service StripeApi::Clients::Persons

      attr_entity :id,
                  :first_name,
                  :last_name

      has_entity :verification, as: StripeApi::Entities::Verification
    end
  end
end
module StripeApi
  module Entities
    class Verification < ApiStruct::Entity
      client_service StripeApi::Clients::Persons

      attr_entity :status,
                  :details,
                  :details_code
    end
  end
end

With those two serializers in place, when I call StripeApi::Entities::Person.show <params>, here's what I get:

#<Hashie::Mash first_name="John" id="person_<HIDDEN>" last_name="Doe" verification=#<Hashie::Mash additional_document=#<Hashie::Mash back=nil details=nil details_code=nil front=nil> details=nil details_code=nil document=#<Hashie::Mash back=nil details=nil details_code=nil front=nil> status="unverified">>

Essentially the verification field on the Person entity gets deserialized as if it was a attr_entity :verification - the Verification entity fails to exclude all params except status, details and details_code. What do you think?