-
Notifications
You must be signed in to change notification settings - Fork 90
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
Auto generate api types with openapi specs #443
Conversation
515a31f
to
a800cb3
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #443 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 2 2
Lines 261 261
Branches 47 47
=========================================
Hits 261 261 ☔ View full report in Codecov by Sentry. |
@paypal/checkout-sdk please review this PR. |
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.
Wow, so much less to maintain. Nice!!! 🥇
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.
pretty dang cool
I was so relieved to find this, thank you! It would be great to add the original example in your PR to the docs. It provides great
With an OpenAPI spec, you could go a step further and generate a type-safe API client. Is there any interest in that? |
Summary
PayPal released the Open API 3.0 specs earlier this year: https://github.com/paypal/paypal-rest-api-specifications. Now we can auto-generate the TypeScript types for PayPal API requests and responses. This PR uses openapi-typescript to auto generate the v2 Orders API types and the v1 Subscriptions API types.
Details
These new API types will make it much easier for TypeScript developers to understand the PayPal APIs. It will also make it much easier for us to maintain. We will no longer need to manually write types to stay in sync with what's documented on https://developer.paypal.com/api/rest/.
The best way to understand this change is to take a look at this real world example of writing server-side code in TypeScript that wraps the PayPal APIs: paypal-examples/paypal-sdk-server-side-integration#37
Here's a snippet with wrapping the create order api call for reference:
Is this a breaking change?
Yes
How can I test this?
Use this beta to test out the new type contracts.