-
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
Revamp interfaces on Stripe model classes #1317
Revamp interfaces on Stripe model classes #1317
Conversation
Also, to clarify the motivation behind this: having both
|
b09bd74
to
04415cc
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.
Some minor comments in the code.
Should we do something similar for Deleted
and Metadata
to not have to put it on every resource that needs it?
Would be neat but then StripeEntityWithIdAndObjectAndDeletedAndMetdata
is not really cool. Maybe metadata should be the default for StripeEntityWithId and you'd have to explicitly use StripeEntityWithIdAndNoMetadata
for the ones that explicitly don't support it? But it's easy to miss if so.
@@ -5,11 +5,8 @@ namespace Stripe | |||
using Newtonsoft.Json; | |||
using Stripe.Infrastructure; | |||
|
|||
public class Dispute : StripeEntityWithId, ISupportMetadata | |||
public class Dispute : StripeEntityWithIdAndObject |
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 don't think Discount has an id, at least it's not in the docs.
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.
👍 Fixed.
@@ -3,7 +3,7 @@ namespace Stripe | |||
using System.Collections.Generic; | |||
using Newtonsoft.Json; | |||
|
|||
public class RecipientActiveAccount : StripeEntityWithId, ISupportMetadata | |||
public class RecipientActiveAccount : StripeEntityWithId |
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.
Why not StripeEntityWithIdAndObject
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.
👍 Fixed.
@@ -1,12 +0,0 @@ | |||
namespace Stripe |
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.
Wasn't this used to ensure we added Metadata
to the Resource too?
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'm not sure why resource classes used this interface at all, but I don't think this is a good reason: the interface would only force you add the Metadata
property if you remembered to add the interface...
@@ -22,7 +22,7 @@ public static void Map(object value, Action<string> updateId, Action<T> updateOb | |||
else if (value is string) | |||
{ | |||
updateId((string)value); | |||
updateObject(null); | |||
updateObject(default(T)); |
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.
Can you put a real comment on this line?
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.
👍
8f016e4
to
467b140
Compare
Yeah, tbh I'm already not thrilled about all the I'd also rather avoid adding more interfaces / classes for other common fields (like |
Should we do |
To be clear, I was suggesting going one step further and get rid of
Right now we have no need for the latter two. Having an |
I do like the distinction between |
I'd argue that if the goal is to make it clear what resources should have an ID, then using the |
But |
When it comes to model classes, I think explicitness is more valuable than DRY. Having each model class directly define all of its properties makes it easier to compare the model to a reference (e.g. the API ref or the OpenAPI spec). I also think it's cleaner to have both ptal @remi-stripe |
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.
not sure we use IHasId
properly
@@ -2,8 +2,11 @@ namespace Stripe | |||
{ | |||
using Newtonsoft.Json; | |||
|
|||
public class EventRequest : StripeEntityWithId | |||
public class EventRequest : StripeEntity, IHasId |
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 don't think IHasId
makes sense here. It's not a Stripe resource, it has the field id because it's the name of the field for the request. I don't think it makes sense to use IHasId in that case
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.
👍 Agreed.
@@ -2,8 +2,11 @@ namespace Stripe | |||
{ | |||
using Newtonsoft.Json; | |||
|
|||
public class EphemeralKeyAssociatedObject : StripeEntityWithId | |||
public class EphemeralKeyAssociatedObject : StripeEntity, IHasId |
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 don't think IHasId
makes sense here. It's not a Stripe resource, it has the field id because it's the name of the field for the associated object. I don't think it makes sense to use IHasId in that case
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.
👍 Agreed.
{ | ||
[JsonProperty("id")] | ||
public string Id { get; set; } |
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.
OOC does this really have an Id field? It's a fake union right? Is it because of the expansion logic where we set the field Id
?
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'm planning on removing all these union classes in #1313, so this is kind of moot.
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.
no you're moot
{ | ||
[JsonProperty("id")] | ||
public string Id { get; set; } | ||
|
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.
Same as PaymentSource
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.
Same, this will go away in #1313.
{ | ||
[JsonProperty("id")] | ||
public string Id { get; set; } |
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.
Same as the other ones
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.
👍 Agreed.
ccdf2f2
to
3762630
Compare
ptal @remi-stripe |
317bb20
to
6a5df72
Compare
r? @remi-stripe
cc @stripe/api-libraries
IStripeEntity
interface implemented byStripeEntity
IHasId
andIHasObject
interfacesStripeEntityWithId
StripeEntity
, and addIHasId
andIHasObject
interfaces where neededISupportMetadata
(ISupportMetadata
was only useful to properly encodemetadata
with the old plugin system, it's useless now)AdditionalOwners
toAdditionalOwner
(the model represents a single additional owner)request
attribute on event objects (cf. https://stripe.com/docs/upgrades#2017-05-25)