Created by: luaks
When sending a request with a client generated by typescript-nestjs, the default headers are modified. This occurs when headers such as "Accept" are appended by the client. The root of the issue is that a reference to the default headers is stored instead of a clone.
Previously the code would have been generated like this:
public deletePet(petId: number, apiKey?: string, ): Observable<any> {
/* ... */
let headers = this.defaultHeaders;
if (apiKey !== undefined && apiKey !== null) {
headers['api_key'] = String(apiKey);
}
This adds the api_key
to the default headers, which then leaks to all following requests, until another request might change the api_key
header.
This PR changes the generated code to:
public deletePet(petId: number, apiKey?: string, ): Observable<any> {
/* ... */
let headers = {...this.defaultHeaders};
if (apiKey !== undefined && apiKey !== null) {
headers['api_key'] = String(apiKey);
}
Instead of changing the default headers, the headers are copied and the header is only set in the scope of the single request.
Mentioning technical comittee for typescript: @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks) -
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.