-
Notifications
You must be signed in to change notification settings - Fork 363
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
Add support for simple arrays and objects in resource generation #988
Add support for simple arrays and objects in resource generation #988
Conversation
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.
This looks great! Still need to review resource_utils.go
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.
Fantastic! The translation of simple array arguments looks particularly smooth.
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.
This is great! Thanks for working on this
Reviewers
r? @etsai-stripe @mnorth-stripe
cc @stripe/developer-products
Summary
In this PR, I added:
--help
flag for resource operations.Simple array parameters (that is, an array of primitive types like strings or ints) are easy to support in the CLI. In the PR, to add data as an array the user will submit the same flag multiple times:
This results in the following POST body:
Next, added flags for nested objects through dot notation. Dots look like they have the most compatibility across shells (brackets unfortunately just don't work). This command works:
Which results in the following body:
I also re-enabled a little bit of the
--help
text on generated resources so that people had a better sense for what are arrays or not:Few things to note on the
--help
:string
orstringArray
. This is because all inputs in the terminal are strings (and technically since we use form data, all requests to Stripe are strings). I added the caveat at the very end as a small clarificationrequired
anddescription
but because of how we pass the Open API data into the resource generation right now this is unfortunately a bit more complicated and may require a little more rewiring. This'll be for another time.* The one part that is still not implemented here is for an array of objects. Because brackets don't work and the flag data is inherently unordered (or at least, order is not guaranteed) there's not a good way to run flags on arrays of objects and make sure the right indexes are mapped.
For the dot notation, I tested this on a few shells and OS's and looks like it works generally okay (but not Windows, I don't have access to that at the moment). We're explicitly not following POSIX guidance which we tried to do for a while to maintain maximum compatibility but adoption of WSL (especially WSL2) should make this more bearable for Windows users (whereas previously, Powershell caused problems here).