swagger-api/swagger-codegen

[typescript-angular2] No `Content-Type` and `Accept` set in headers

Open

#6006 opened on Jul 6, 2017

View on GitHub
 (19 comments) (4 reactions) (0 assignees)HTML (12,701 stars) (5,474 forks)batch import
Client: TypeScriptGeneral: Questionhelp wanted

Description

Description

While generating the API client in typescript-angular2, the Content-Type and Accept headers are not set.

Swagger-codegen version

v2.2.2 and 2.2.3-20170703.140356-40 snapshot

Swagger declaration file content or url

not available

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i swagger.json -l typescript-angular2

Steps to reproduce

generate the client, send any request via it, but it's also very visible with code itself.

as we see in template: https://github.com/swagger-api/swagger-codegen/blob/v2.2.2/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache#L115-L127 or in generated code:

    public resourceFOOGETWithHttpInfo(authorization?: string, extraHttpRequestParams?: any): Observable<Response> {
        const path = this.basePath + '/FOO';

        let queryParameters = new URLSearchParams();
        let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
        if (authorization !== undefined && authorization !== null) {
            headers.set('Authorization', String(authorization));
        }

        // to determine the Content-Type header
        let consumes: string[] = [
        ];

        // to determine the Accept header
        let produces: string[] = [
            'application/json'
        ];

        let requestOptions: RequestOptionsArgs = new RequestOptions({
            method: RequestMethod.Get,
            headers: headers,
            search: queryParameters,
            withCredentials:this.configuration.withCredentials
        });
        // https://github.com/swagger-api/swagger-codegen/issues/4037
        if (extraHttpRequestParams) {
            requestOptions = (<any>Object).assign(requestOptions, extraHttpRequestParams);
        }

        return this.http.request(path, requestOptions);
    }

the consumes and produces vars are generated, but not used.

Related issues

not aware of

Suggest a Fix

the consumes and produces vars shall be injected into headers

Contributor guide