swagger-api / swagger-api/swagger-codegen
[typescript-angular2] No `Content-Type` and `Accept` set in headers
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache around the referenced request-generation block, then compare it with the generated client shown in the issue. Verify how the generated consumes and produces arrays should affect request headers, and confirm completion by sending a generated client request with the expected Content-Type and Accept headers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100