Skip to content

[typescript-angular2] Bug: Request Content-Type other than json not allowed #6588

Closed
@macjohnny

Description

@macjohnny
Description

The changes in #6454 introduced setting the request content-type from the consumes property.

if (consumes != null && consumes.length > 0) {
    headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));
}

However, the content type is limited to json-like mime types. Therefore the content-type is set to an empty string if we e.g. upload a file and have

let consumes: string[] = [
     'multipart/form-data'
];

and since multipart/form-data is not a json mime-type, this results in setting and empty string value.
This in turn, results in an invalid content-type header being set, as explained e.g. here: angular/angular#11819

Content-Length: 315
Content-Type: , multipart/form-data; boundary=----WebKitFormBoundarys7BwSTvRA7Nf3WwQ
Host: petstore.swagger.io

This breaks e.g. the PetStore.uploadFile() API in the petStore example:

public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<ApiResponse> {

Swagger-codegen version

2.3.0

Swagger declaration file content or url

See the petstore example

headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));

Command line used for generation
Steps to reproduce
Related issues/PRs

Maybe this is resolved with #6080

Suggest a fix/enhancement

Do not restrict the conten-type to json mime types.
Let angular detect the content-type automatically from the data.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions