-
Notifications
You must be signed in to change notification settings - Fork 547
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
RFC: Static sorbet/RBI annotations for resources and methods #1479
Comments
Hello! Former maintainer of the library here (I was @ob-stripe) and current user of both Sorbet and the library at my new gig. First off, yay! Very excited to finally have first-party types 🎉 🥳 🎈 (You're probably already aware but there are unofficial Sorbet types in Tapioca's repo: https://github.com/Shopify/rbi-central/blob/main/rbi/annotations/stripe.rbi) The signatures for resource fields look fine, but I don't love the approach for method parameters. Unless I misunderstand, using types for request params would require a code change to use the new # without types
Stripe::Account.reject(reason: "foo")
# with types
Stripe::Account.reject(Stripe::Account::RejectParams.new(reason: "foo")) This makes the code more cumbersome to read, and has a (slight) performance impact since more allocations are needed, etc. Instead, I wonder if using shapes would provide a better experience: # account.rbi
class Account
RejectParamsType = T.type_alias { { reason: String } }
sig { params(params: RejectParamsType).returns(Stripe::Account) }
def self.create(params = {}); end
end
# client code
Stripe::Account.reject(reason: "foo") But there are some problems of this approach:
|
👋 @olivier-thatch Thanks for stopping by at stripe again and giving us feedback! 😄 I consulted with the Sorbet maintainers about shapes and I do not think they would be the best option here, unfortunately. There are several reasons:
I understand the migration path isn't ideal for parameters with requiring a new object, but it would be hard to both define a type for parameters and have its rollout be nonbreaking, but I'd be glad to here any additional feedback you may have here! |
👋 Hello all Ruby devs! We're seeking feedback on a feature we're working on. The SDKs team will be adding optional static type annotation RBIs to our stripe-ruby library. We do not plan to introduce runtime dependencies or breaking changes for existing users on the resource-based pattern, and we want to continue to support users who are using extra parameters (beta users). We are seeking feedback on our proposed approach.
Resource Fields
We will add explicit attribute definitions in our resources, while still leaving the behavior where a resource will dynamically add any attribute methods that it can when deserialized, so any field returned on the API can be accessed. An example:
Method Parameters
We will add a
RequestParameter
object with subclasses for each method, both for resource and service methods. The object will have attributes defined, and we will accept the parameter for all methods in the SDK, while still accepting untyped hashes. An example, usingStripe::Account.reject
:Conclusion
Existing users shouldn't be affected by our addition of types. Users who currently use sorbet for their own projects but not for Stripe can partially migrate, as all methods will support both parameter objects and hashes.
When shipping types, we will not include any new runtime dependencies (ie inline annotations). We will maintain support for Ruby 2.3+.
The text was updated successfully, but these errors were encountered: