-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Typescript-fetch: file upload and Typescript dependency updates #4852
Typescript-fetch: file upload and Typescript dependency updates #4852
Conversation
Update type definitions for core-js and isomorphic-fetch
@russtacular thanks for the PR. @Vrolijkx @leonyu would you please take a look when you've time? Thanks. |
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.
looks great only one remark.
@@ -6,16 +6,18 @@ | |||
"browser": "./dist/api.js", | |||
"typings": "./dist/api.d.ts", | |||
"dependencies": { | |||
{{^supportsES6}}"core-js": "^2.4.0", | |||
{{/supportsES6}}"isomorphic-fetch": "^2.2.1" | |||
"@types/node": "6.0.46", |
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.
Would be nice to also have this in the angular2 && angular clients.
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 started looking at updating angular2 but I'm having issues building the copy in master using either TS 1.8.10 or my installed typescript@next developers build. I'm sure my unfamiliarity with building and using the angular generated libraries isn't helping either!
I can look into this but I think it may require more extensive changes and that it's likely better suited for a follow up PR. Is that okay with you?
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.
sure.
{{/isFile}}formData["{{baseName}}"] = params["{{paramName}}"]; | ||
{{/formParams}} | ||
|
||
if (isMultipartData) { |
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.
Why not instead of this if statement in all the generated code. Use a Mustache if. This way you don't need the next strange code:
let isMultipartData = false;
isMultipartData = true;
maybe do something like this:
{{#isFile}}
let body = new FormData();
for (let key in formData) {
body.append(key, formData[key]);
}
fetchOptions.body = body;
contentTypeHeader = { "Content-Type": "multipart/form-data" };
{{/isFile}}
{{^isFile}}
fetchOptions.body = querystring.stringify(formData);
contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" };
{{#isFile}}
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 originally used a very similar implementation to the one you suggested and also mentioned in #3921 but noticed that, since {{#isFile}}
is scoped to the individual parameter, it didn't work for requests that included a file and regular form parameters. I checked again and, unless I'm looping through the individual formParams
, {{#isFile}}
always maps to false.
Is there a Mustache template variable available that tracks if any of the included FormData
attributes is of type file? If so, that would allow me to simplify the mustache template to essentially match your suggestion and get rid of the seemingly extraneous code.
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.
Is there a Mustache template variable available that tracks if any of the included FormData attributes is of type file?
Not that I'm aware of. If it helps, we can introduce the variable.
Hold off on this PR for a bit… I think it needs a small update and I'm also going to see about adding that form-level variable. Notably I need to remove the explicit set of the |
…mically generated
Also removes references to typings in the Readme
Ensures that content-type is set for urlencoded forms but is specifically left unset for multipart form data since the content-type header value is dynamically generated to include a boundary.
…ile-upload-and-dependency-updates * swagger/master: (59 commits) [Java][Retrofit2] update gradle, sbt build file with latest dependencies (swagger-api#5238) update retrofit2 dependencies (swagger-api#5235) Issue swagger-api#3084: remove timestamps from undertow samples (swagger-api#5231) add port 80 to swagger spec (swagger-api#5232) fix msf4j bin script fix c# docstring typo (swagger-api#5223) add comments to csharp methods (swagger-api#5222) fix retrofit2 indentation (swagger-api#5221) Updating samples for spring-stubs, springboot-delegate, springboot-delegate-j8. (swagger-api#5211) export top level enumeration types in typescript-fetch mode (swagger-api#4820) [Erlang] pretty print swagger json (swagger-api#5215) add ci test for msf4j server (swagger-api#5220) Updating samples for JaxRS servers: Spec + CXF-CDI. (swagger-api#5213) Update samples for JaxRS/RestEasy/Joda. (swagger-api#5205) Update samples for Undertow. (swagger-api#5207) Update samples for okhttp-gson-parcelableModel. (swagger-api#5208) Update samples for Java Inflector. (swagger-api#5204) [java][msf4j] Update msf4j samples (and fix artifact name) (swagger-api#5210) Update samples for Ruby-Client + Rails server. (swagger-api#5214) [ASP.NET] Issue swagger-api#5196: add packageGuid parameter to AspNetCoreServerCodegen. (swagger-api#5199) ...
@russtacular the CI (travis) failed with the following errors:
Would you please take a look when you've time? |
Is there a timeline on this one? It would solve the same problem I'm having with file uploads via generated code. |
@wing328 @zetlan — Thanks for prodding me on this, I definitely still want to get this fix merged. The failing test, however, points out a bit of a problem with using Node doesn't support
Those are the options I see, although I could definitely be missing something obvious. I happy to submit a fix that uses any of the options I identified above but I don't feel like I can make that decision unilaterally since I don't know how others are using this client (at Bitly, we're only using the generated TS Fetch client within browsers). |
Can someone have a look at this please? @russtacular |
}); | ||
|
||
it('should not set a content-type header when uploading a file', () => { | ||
return new PetApi(parameterInspector).uploadFile({ petId: fixture.id, file: new File(['snoopy'], 'Snoopy.png')}).then(({arguments: [url, init]}) => { |
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.
File is not defined, that's why tests are failing
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.
@AmazingTurtle good catch!
cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx to review and see how we can proceed with this PR. |
Hey, guys! What about this issue? When you planning to fix that bug? |
Have a look at a fork I’ve made over at
https://github.com/Place1/swagger-codegen-typescript-browser
You can download a jar from the releases page
It works with multipart form data requests and fixes a bunch of other bugs.
…On Thu, 28 Jun 2018 at 2:41 am, Alexey Trofimov ***@***.***> wrote:
Hey, guys! What about this issue? When you planning to fix that bug?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4852 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALMBllIbuIUxp9E2iFq8m-E-US6hNEWyks5uA7W9gaJpZM4MLqzD>
.
|
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0
branch for breaking (non-backward compatible) changes.Description of the PR
This updates the typescript-fetch client with the latest dependencies based on work originally done in #4153 but in need of updates due to additional changes to
@types/isomorphic-fetch
that were causing build errors.Additionally this adds the ability to upload files using the typescript-fetch client as requested in #3921. Given the limitations of the mustache template, I assumed that form parameters did not include files but, if so, it set a flag that caused the form parameters to be appended to a
FormData
object which is uploaded with aContent-Type: 'multipart/form-data'
header opposed to the standard'application/x-www-form-urlencoded'