[typescript-fetch] support custom stringify for query string (#3327)

* [typescript-fetch] support custom query stringify

* [typescript-fetch] support custom query stringify
This commit is contained in:
hello-brsd 2019-07-15 07:58:08 +02:00 committed by Esteban Gehring
parent d117506b8a
commit 3eac8391f5
5 changed files with 30 additions and 5 deletions

View File

@ -47,7 +47,7 @@ export class BaseAPI {
// only add the querystring to the URL if there are query parameters.
// this is done to avoid urls ending with a "?" character which buggy webservers
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
url += '?' + this.configuration.queryParamsStringify(context.query);
}
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
@ -116,6 +116,7 @@ export interface ConfigurationParameters {
basePath?: string; // override base path
fetchApi?: FetchAPI; // override for fetch implementation
middleware?: Middleware[]; // middleware to apply before/after fetch requests
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
username?: string; // parameter for basic security
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
@ -137,6 +138,10 @@ export class Configuration {
return this.configuration.middleware || [];
}
get queryParamsStringify(): (params: HTTPQuery) => string {
return this.configuration.queryParamsStringify || querystring;
}
get username(): string | undefined {
return this.configuration.username;
}

View File

@ -58,7 +58,7 @@ export class BaseAPI {
// only add the querystring to the URL if there are query parameters.
// this is done to avoid urls ending with a "?" character which buggy webservers
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
url += '?' + this.configuration.queryParamsStringify(context.query);
}
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
@ -127,6 +127,7 @@ export interface ConfigurationParameters {
basePath?: string; // override base path
fetchApi?: FetchAPI; // override for fetch implementation
middleware?: Middleware[]; // middleware to apply before/after fetch requests
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
username?: string; // parameter for basic security
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
@ -148,6 +149,10 @@ export class Configuration {
return this.configuration.middleware || [];
}
get queryParamsStringify(): (params: HTTPQuery) => string {
return this.configuration.queryParamsStringify || querystring;
}
get username(): string | undefined {
return this.configuration.username;
}

View File

@ -58,7 +58,7 @@ export class BaseAPI {
// only add the querystring to the URL if there are query parameters.
// this is done to avoid urls ending with a "?" character which buggy webservers
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
url += '?' + this.configuration.queryParamsStringify(context.query);
}
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
@ -127,6 +127,7 @@ export interface ConfigurationParameters {
basePath?: string; // override base path
fetchApi?: FetchAPI; // override for fetch implementation
middleware?: Middleware[]; // middleware to apply before/after fetch requests
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
username?: string; // parameter for basic security
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
@ -148,6 +149,10 @@ export class Configuration {
return this.configuration.middleware || [];
}
get queryParamsStringify(): (params: HTTPQuery) => string {
return this.configuration.queryParamsStringify || querystring;
}
get username(): string | undefined {
return this.configuration.username;
}

View File

@ -58,7 +58,7 @@ export class BaseAPI {
// only add the querystring to the URL if there are query parameters.
// this is done to avoid urls ending with a "?" character which buggy webservers
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
url += '?' + this.configuration.queryParamsStringify(context.query);
}
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
@ -127,6 +127,7 @@ export interface ConfigurationParameters {
basePath?: string; // override base path
fetchApi?: FetchAPI; // override for fetch implementation
middleware?: Middleware[]; // middleware to apply before/after fetch requests
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
username?: string; // parameter for basic security
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
@ -148,6 +149,10 @@ export class Configuration {
return this.configuration.middleware || [];
}
get queryParamsStringify(): (params: HTTPQuery) => string {
return this.configuration.queryParamsStringify || querystring;
}
get username(): string | undefined {
return this.configuration.username;
}

View File

@ -58,7 +58,7 @@ export class BaseAPI {
// only add the querystring to the URL if there are query parameters.
// this is done to avoid urls ending with a "?" character which buggy webservers
// do not handle correctly sometimes.
url += '?' + querystring(context.query);
url += '?' + this.configuration.queryParamsStringify(context.query);
}
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
@ -127,6 +127,7 @@ export interface ConfigurationParameters {
basePath?: string; // override base path
fetchApi?: FetchAPI; // override for fetch implementation
middleware?: Middleware[]; // middleware to apply before/after fetch requests
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
username?: string; // parameter for basic security
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
@ -148,6 +149,10 @@ export class Configuration {
return this.configuration.middleware || [];
}
get queryParamsStringify(): (params: HTTPQuery) => string {
return this.configuration.queryParamsStringify || querystring;
}
get username(): string | undefined {
return this.configuration.username;
}