-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add optional AxiosRequestConfig parameter to typescript-nestjs service functions #20222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
cc57936
8bb7982
1b84522
be1754b
fb3c75b
4eecf29
dd81810
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,7 +8,7 @@ import { HttpService } from '@nestjs/axios'; | |||||||||||||
{{^useAxiosHttpModule}} | ||||||||||||||
import { HttpService, Injectable, Optional } from '@nestjs/common'; | ||||||||||||||
{{/useAxiosHttpModule}} | ||||||||||||||
import { AxiosResponse } from 'axios'; | ||||||||||||||
import { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||||||||||||||
import { Observable, from, of, switchMap } from 'rxjs'; | ||||||||||||||
{{#imports}} | ||||||||||||||
import { {{classname}} } from '../{{filename}}'; | ||||||||||||||
|
@@ -93,14 +93,15 @@ export class {{classname}} { | |||||||||||||
{{/allParams}}* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. | ||||||||||||||
* @param reportProgress flag to report request and response progress. | ||||||||||||||
{{/useSingleRequestParameter}} | ||||||||||||||
* @param {*} [{{nickname}}RequestConfig.options] Override http request option. | ||||||||||||||
*/ | ||||||||||||||
{{#useSingleRequestParameter}} | ||||||||||||||
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>; | ||||||||||||||
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}): Observable<any> { | ||||||||||||||
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}{{nickname}}RequestConfig?: { options?: AxiosRequestConfig }): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a better name, now that it is a pojo with an options config object?
Suggested change
Suggested change
or something? Given the Also:
Suggested change
given the name of the class/interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's a good idea, so more like this?
@macjohnny wdyt ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks good |
||||||||||||||
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}{{nickname}}RequestConfig?: { options?: AxiosRequestConfig }): Observable<any> { | ||||||||||||||
{{/useSingleRequestParameter}} | ||||||||||||||
{{^useSingleRequestParameter}} | ||||||||||||||
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>; | ||||||||||||||
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}): Observable<any> { | ||||||||||||||
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}{{nickname}}RequestConfig?: { options?: AxiosRequestConfig }): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>; | ||||||||||||||
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}{{nickname}}RequestConfig?: { options?: AxiosRequestConfig }): Observable<any> { | ||||||||||||||
{{/useSingleRequestParameter}} | ||||||||||||||
{{#allParams.0}} | ||||||||||||||
{{#useSingleRequestParameter}} | ||||||||||||||
|
@@ -291,7 +292,8 @@ export class {{classname}} { | |||||||||||||
responseType: "blob", | ||||||||||||||
{{/isResponseFile}} | ||||||||||||||
withCredentials: this.configuration.withCredentials, | ||||||||||||||
headers: headers | ||||||||||||||
headers: {...headers, ...{{nickname}}RequestConfig?.options?.headers}, | ||||||||||||||
...{{nickname}}RequestConfig?.options, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt the lines be swapped to make sure the original headers are not completely overwritten if some headers are set in the options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes right ! |
||||||||||||||
} | ||||||||||||||
); | ||||||||||||||
}) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed: should this be be a
type
only import if we assume TS > 3.8?refs #20064