Skip to content

[TypeScript-Fetch] Return type for non-parsed endpoints should be Response #6772

@masaeedu

Description

@masaeedu
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions