From 3eac8391f5d79a3e738b0380dc16e77d546ce435 Mon Sep 17 00:00:00 2001 From: hello-brsd Date: Mon, 15 Jul 2019 07:58:08 +0200 Subject: [PATCH] [typescript-fetch] support custom stringify for query string (#3327) * [typescript-fetch] support custom query stringify * [typescript-fetch] support custom query stringify --- .../src/main/resources/typescript-fetch/runtime.mustache | 7 ++++++- .../petstore/typescript-fetch/builds/default/runtime.ts | 7 ++++++- .../petstore/typescript-fetch/builds/es6-target/runtime.ts | 7 ++++++- .../typescript-fetch/builds/with-interfaces/runtime.ts | 7 ++++++- .../typescript-fetch/builds/with-npm-version/runtime.ts | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index cb7f747ea45..6878fd84958 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -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; } diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 5b07f811186..c95a101fbac 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -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; } diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts index 5b07f811186..c95a101fbac 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts @@ -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; } diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 5b07f811186..c95a101fbac 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -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; } diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts index 5b07f811186..c95a101fbac 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts @@ -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; }