Skip to content

[Typescript-Fetch] Routes with non-JSON body parameters still get sent JSON #6940

Description

@masaeedu
Description

In the TypeScript-Fetch client generator, payloads sent to any routes with body parameters are unconditionally tagged with a Content-Type of application/json and JSON.stringify-ed before being sent. Routes that expect content such as tar archives are broken by this behavior.

Swagger-codegen version

2.3.0-snapshot

Swagger declaration file content or url

https://raw.githubusercontent.com/moby/moby/master/api/swagger.yaml

See for example the PutContainerArchive operation route, which consumes: ["application/x-tar", "application/octet-stream"].

Command line used for generation
generate -i /moby/api/swagger.yaml -l typescript-fetch -o /package
Steps to reproduce

Generate the client with the linked spec (or use the docker-client package from npm, which is generated in this way), inspect the code for putContainerArchive and observe that it adds a Content-Type application/json header and invokes JSON.stringify on the content. If you actually try this against a Docker instance you'll get an invalid tar archive error.

Suggest a fix/enhancement

The codegen should look at the route's consumes attribute to figure out the content type header, and if it isn't JSON, send it through without JSON stringify-ing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions