-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly deserialize source on BT during expand #1165
Conversation
@ob-stripe Can you have a quick look and confirm this is the right direction? Some questions
|
851a0cc
to
adb8321
Compare
This looks mostly on the right track to me. Thanks for taking a stab at this @remi-stripe!
Ugh. I'd rather avoid adding complex tests that use the real API. The test suite already takes forever to run, and these tests will either be painful to port to stripe-mock or will be scraped entirely. Since it's unlikely stripe-mock will support returning different @brandur-stripe Any thoughts here?
Honestly, I'd rather throw an exception with a message saying to contact support so we can update the library with missing types. Just returning the raw JSON does not sound like a great developer experience. I understand that updating stripe-dotnet can be painful because of the pinned API version and semi-frequent major version bumps, but I don't think we're going to add new types often enough that we should have an escape hatch specifically for this case. (Worst case, the JSON of the entire response is always accessible via the
Not a C# expert™, but that seems fine to me. C unions are not really compatible with classes anyway (even in C++, you cannot have any kind of virtual functions in a union). |
We can not do that. If we did this it'd mean that as soon as we add a new type, anyone could end up with an exception or a crash in their production application right? New types are not a breaking change and could be introduced. |
Ah, good point. Sigh, who decided that an expandable polymorphic attribute was a good idea anyway :shakes_fist: So yeah, |
this is interesting: Do you think StructLayout has promise here? |
@jaymedavis Yeah I looked into it but it seems a bit hacky/complex for the sake of saving a little bit of memory |
Thought that might be the case. To my knowledge, .net developers rarely ever use the struct keyword anyway. |
adb8321
to
74848d9
Compare
@ob-stripe I took another stab at this PR now that I better understand the test suite based on stripe-mock. Can you have a look as I think it's ready to merge. It's a breaking change, but also it never worked so not sure what we want to do here? |
74848d9
to
49ce8af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor comment, but looks great otherwise.
// works as expectes. | ||
var json = GetResourceAsString("api_fixtures.balance_transaction_with_expansion.json"); | ||
var balanceTransactions = Mapper<StripeList<StripeBalanceTransaction>>.MapFromJson(json); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just add a couple of asserts here:
Assert.NotNull(balanceTransactions.Data)
Assert.IsTrue(balanceTransactions.Data.Count >= 9)
just to avoid exceptions when trying to access something that doesn't exist if the deserialization goes wrong (or if something is wrong with the fixture itself).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ob-stripe done! PTAL
I think it's fine to release this as a minor version. Technically, the API changed, but as you pointed out no integration could use the previous API anyway, so in practice it's more like a new feature. |
49ce8af
to
8eb8d8e
Compare
Released as 17.4.0. |
This PR adds support for deserializing
source
on a Balance Transaction properly. It used to map to aSource
class which is a "parent class" for payment methods and has nothing to do with balance transaction.There's a new custom deserializer and type for this that looks at the balance transaction's source
object
property and deserializes the right type based on this.This PR also adds support for local JSON files as fixtures for the new test suite to properly test deserializing all source types.
Fixes #1162
cc @stripe/api-libraries