Skip to content

Commit

Permalink
[typescript-fetch] support custom stringify for query string (#3327)
Browse files Browse the repository at this point in the history
* [typescript-fetch] support custom query stringify

* [typescript-fetch] support custom query stringify
  • Loading branch information
hello-brsd authored and macjohnny committed Jul 15, 2019
1 parent d117506 commit 3eac839
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 3eac839

Please sign in to comment.