-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Meta] Multipart requests need rework #29
Comments
Thanks for reporting @tajnymag. I've got a number of other issues to prioritise first, can visit this afterwards |
+1 |
Related to: (FormData) TypeError: source.on is not a function The library we are using does not support appending blobs to FormData (axios/node-fetch). We could switch to using build in FormData, but when running axios in node it would be experimental (until node 21) see: here look at history section cc: @mrlubos |
@mrlubos I think a config option to use |
Such option would override form types across the whole spec? That wouldn't allow to support projects with mixed forms. If the feature should be hidden behind an option, perhaps Also, is it necessary for all clients to support the same feature set? |
@tajnymag we would like to have all clients support this. "File" appears to be supported in node 18+ so no issues there. As that's the minimum version we officially support. The option would make all Blob turn into File. Not sure how exactly we could support it otherwise. I don't think OpenAPI has a way of differing between those. Aside: working on fixing all the other bugs, maybe appear to be axios only now. But I have solution. Just need to decide how we want to support File type with mrlubos |
@jordanshatford You are right, that the spec does not have any explicit file identifier. The codegen internally doesn't even differentiate between binary and file (line from codegen). However, some generators do try make some assumptions. I'll try to go through them and try to understand their logic. Could the API accept both objects than? And if the given object is an instance of a file (or perhaps even more generally, if the object has a I really think having every binary be exclusively File OR Blob to be quite limiting. |
@mrlubos thoughts on changing this to File | Blob? User can narrow the type if they want to check the return value being specifically a file. For sending requests File and Blob are both accepted in the form data |
That sounds reasonable @jordanshatford |
#186 Will use |
All above issues should be fixed in v0.32.1 of the package. Please test it out and report and issues you find under a new issue. :) Thanks |
Amazing work @jordanshatford! |
Hi, I am trying this with node v20.x uploading to a remote server. The generated client uses axios and has multipart I tried to populate the object with fields and a blob, but server side I got an empty file upload. This ended up working // NOTE *not* using 'form-data' or it fails with 'TypeError: source.on is not a function'
const formData = new FormData();
formData.append("file", file); // Blob
for (const key in model) {
formData.append(key, model[key]);
}
await client.ui.saveBackground({
formData: formData as any,
}), |
@muka can you try with the latest version (released early today) which fixed a few issues with axios. v0.33.2. If you are still experiencing issues, please submit a bug report and fill out as much detail as possible. |
Thank you, just tried but axios is not happy yet my client package.json
calling the generated api with a blob (a previously described) result in this. Using a
the error from the client (but seems from axios actually)
Using a FormData as input still works. Why not just allow |
@muka can you create a new issue and file out all the bug details. that way it will be easier to reproduce |
Describe the bug
Right now, binary
multipart/form-data
requests almost always fail to work.Issues:
In my testing, I've used example requests from Swagger documentation and compared the result to the official java-based typescript-axios generator. The official generator correctly inferred the requests were containing files, made the operation input be
File
instead ofBlob
and correctly serialized and performed the request.The text was updated successfully, but these errors were encountered: