-
Notifications
You must be signed in to change notification settings - Fork 6
fix: handling of multipart/form-data requests #1
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
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 does not look like it was fun to code, but the code looks amazingly good for what it is/does/has to be. Super useful comments too. (Could still probably use another set of eyes, but I did read through it pretty closely.)
| * @param {FormData} form | ||
| * @param {string} boundary | ||
| */ | ||
| module.exports.formDataIterator = function * (form, boundary) { |
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.
Oh wow. A generator in action. I think it's the first time I've actually seen one in usage.
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 had to look up function * to see what that was because I'd also never seen a JS generator in action before.
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.
A bit difficult to imagine how this would integrate into the explorer, but the code looks sound!
multipart/form-datacontent types in order to accommodate library utilization within the browser where the nativeFormDatacomponent is used.form-dataandFormDatathat was causing the library to fail in the browser were two issues:FormData.appendhas three arguments, and the third should only be present if the second is aBloborUSVString. It is never an object, asform-datarequires it to be.FormData.pipe()isn't a function.requesttarget that was causingfs.createReadStreampointers to be stringified and unusable.param.fileNameif it's present, even ifparam.valuealso is:requestrequesttarget to prefer single quotes inrequirestatements andrequest.cookiecalls. Since the rest of the snippet already preferred this, this change makes the whole snippet look a touch more cohesive and consistent.Since I'm not sure on how we can actually test the browser side of things within this library, you can instead test it out with this PR in the Explorer repo: readmeio/api-explorer#867. That is currently loading this PR within the
@readme/oas-to-snippetlibrary: