Description
The TypeScript fetch client currently falls back to returning a Promise<any> in cases where the spec does not dictate a schema for the response.
At runtime, what it's actually returning is a fetch API Response, which needs to be consumed buffer by buffer, or turned into text or something before the request can actually be considered complete.
The any being returned provides no indication of this, so users can end up misusing the API by simply awaiting the Promise<any> (which only represents the start of the response), and expecting that server is done talking to them.
Swagger-codegen version
Present in master:
|
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}> { |
Swagger declaration file content or url
Docker API spec
Command line used for generation
generate -i /moby/api/swagger.yaml -l typescript-fetch -o /package
Suggest a fix/enhancement
The return type should be changed to Promise<Response> (the Response type is built in to lib.d.ts), to make it clear to users of the fetch API that they still need to .json() or .text() the response and await the resulting promise.
Description
The TypeScript fetch client currently falls back to returning a
Promise<any>in cases where the spec does not dictate a schema for the response.At runtime, what it's actually returning is a fetch API
Response, which needs to be consumed buffer by buffer, or turned intotextor something before the request can actually be considered complete.The
anybeing returned provides no indication of this, so users can end up misusing the API by simply awaiting thePromise<any>(which only represents the start of the response), and expecting that server is done talking to them.Swagger-codegen version
Present in master:
swagger-codegen/modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache
Line 256 in 4d994a2
Swagger declaration file content or url
Docker API spec
Command line used for generation
Suggest a fix/enhancement
The return type should be changed to
Promise<Response>(theResponsetype is built in tolib.d.ts), to make it clear to users of the fetch API that they still need to.json()or.text()the response and await the resulting promise.