From 473dbafefa3168425765dfac77ed1c64dfd70323 Mon Sep 17 00:00:00 2001 From: svolkov Date: Sat, 6 Mar 2021 02:00:50 +0300 Subject: [PATCH 01/19] feat: add "onFormatRouteName" hook --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48bd593b..2b029ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,9 @@ Fixes: Features: - `onFormatRouteName(routeInfo: RawRouteInfo, templateRouteName: string)` hook. Allows to format route name, as you like :) +Features: +- `onFormatRouteName(routeInfo: RawRouteInfo, templateRouteName: string)` hook. Allows to format route name, as you like :) + Fixes: - Bug with wrong complex types (anyOf, oneOf, allOf) when some child schema contains only description ![example](./assets/changelog_assets/fixComplexTypeAny.jpg) From 4e7133a61370ba27ecb363e9385da002649ff427 Mon Sep 17 00:00:00 2001 From: svolkov Date: Sat, 6 Mar 2021 02:09:44 +0300 Subject: [PATCH 02/19] chore: try to add github workflows --- .github/workflows/blank.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/blank.yml diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml new file mode 100644 index 00000000..764d824d --- /dev/null +++ b/.github/workflows/blank.yml @@ -0,0 +1,27 @@ +name: CI + +on: + pull_request: + branches: + - next + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: use node + uses: actions/setup-node@v1 + with: + node-version: 10 + + - name: install deps + run: npm i + + - name: simple-tests + run: npm run generate && npm run validate + + - name: specific-tests + run: npm run test-specific From 04de7647353a7d1038ee1bf410737f4169927c8a Mon Sep 17 00:00:00 2001 From: svolkov Date: Sat, 6 Mar 2021 02:34:32 +0300 Subject: [PATCH 03/19] chore: rename gh workflow file to main --- .github/workflows/blank.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/blank.yml diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml deleted file mode 100644 index 764d824d..00000000 --- a/.github/workflows/blank.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: CI - -on: - pull_request: - branches: - - next - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - - name: use node - uses: actions/setup-node@v1 - with: - node-version: 10 - - - name: install deps - run: npm i - - - name: simple-tests - run: npm run generate && npm run validate - - - name: specific-tests - run: npm run test-specific From 188162c1e347690be39529a0f604f06bc568f4f9 Mon Sep 17 00:00:00 2001 From: svolkov Date: Sat, 6 Mar 2021 02:38:20 +0300 Subject: [PATCH 04/19] chore: fix changelog after rebase --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b029ffd..48bd593b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,9 +63,6 @@ Fixes: Features: - `onFormatRouteName(routeInfo: RawRouteInfo, templateRouteName: string)` hook. Allows to format route name, as you like :) -Features: -- `onFormatRouteName(routeInfo: RawRouteInfo, templateRouteName: string)` hook. Allows to format route name, as you like :) - Fixes: - Bug with wrong complex types (anyOf, oneOf, allOf) when some child schema contains only description ![example](./assets/changelog_assets/fixComplexTypeAny.jpg) From 5d82dd422c43af3943f1c19232b7abbdf138aa83 Mon Sep 17 00:00:00 2001 From: "Sergey S. Volkov" Date: Thu, 11 Mar 2021 23:02:45 +0300 Subject: [PATCH 05/19] fix incorrect working --route-types with --modular option (#207) * chore: try to fix modular route types problem * fix: --route-types with --modular option; fix: better format namespace name (--route-types) --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index 7bb79ad3..073a110d 100644 --- a/src/index.js +++ b/src/index.js @@ -21,6 +21,8 @@ const { generateOutputFiles } = require("./output"); const formatFileContent = require("./formatFileContent"); const { eventLog, successLog } = require("./logger"); +const { SCHEMA_TYPES } = constants; + module.exports = { constants: constants, generateApi: ({ From ad970b4bd149643d088df906e815d110c4c65fad Mon Sep 17 00:00:00 2001 From: svolkov Date: Thu, 11 Mar 2021 23:25:07 +0300 Subject: [PATCH 06/19] feat: add extra output util functions --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ src/index.js | 2 -- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48bd593b..41fc5a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,33 @@ Features: }) ``` +Features: +- Add output util functions +```ts + createFile: (params: { + path: string; + fileName: string; + content: string; + withPrefix?: boolean; + }) => void; + renderTemplate: ( + templateContent: string, + data: Record, + etaOptions?: import("eta/dist/types/config").PartialConfig + ) => string; + getTemplate: (params: { + fileName: string; + name?: string + }) => string + + + // ... + + generateApi({ /* ... */ }).then(({ createFile, renderTemplate, getTemplate }) => { + // do something + }) +``` + # 6.4.2 Fixes: diff --git a/src/index.js b/src/index.js index 073a110d..7bb79ad3 100644 --- a/src/index.js +++ b/src/index.js @@ -21,8 +21,6 @@ const { generateOutputFiles } = require("./output"); const formatFileContent = require("./formatFileContent"); const { eventLog, successLog } = require("./logger"); -const { SCHEMA_TYPES } = constants; - module.exports = { constants: constants, generateApi: ({ From 9d6b956f1355e51000a8e5e570c92cac336aac7d Mon Sep 17 00:00:00 2001 From: svolkov Date: Thu, 11 Mar 2021 23:49:55 +0300 Subject: [PATCH 07/19] chore: improve getTemplate function --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41fc5a16..6bd19634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,8 +62,9 @@ Features: etaOptions?: import("eta/dist/types/config").PartialConfig ) => string; getTemplate: (params: { - fileName: string; - name?: string + fileName?: string; + name?: string; + path?: string; }) => string From 552a9d70e1e681378c175308cf179ec78db89b4b Mon Sep 17 00:00:00 2001 From: svolkov Date: Fri, 12 Mar 2021 00:19:26 +0300 Subject: [PATCH 08/19] feat: add formatTSContent util function --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd19634..a2f7f01a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ Features: name?: string; path?: string; }) => string + formatTSContent: (content: string) => string; // ... From 704672b6f3b280d20111e6b6f7bd9becf962a882 Mon Sep 17 00:00:00 2001 From: svolkov Date: Fri, 19 Mar 2021 11:30:48 +0300 Subject: [PATCH 09/19] fix: bugs after rebase --- CHANGELOG.md | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2f7f01a..48bd593b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,35 +47,6 @@ Features: }) ``` -Features: -- Add output util functions -```ts - createFile: (params: { - path: string; - fileName: string; - content: string; - withPrefix?: boolean; - }) => void; - renderTemplate: ( - templateContent: string, - data: Record, - etaOptions?: import("eta/dist/types/config").PartialConfig - ) => string; - getTemplate: (params: { - fileName?: string; - name?: string; - path?: string; - }) => string - formatTSContent: (content: string) => string; - - - // ... - - generateApi({ /* ... */ }).then(({ createFile, renderTemplate, getTemplate }) => { - // do something - }) -``` - # 6.4.2 Fixes: From 4910840d88150ec4dbce24749fbee50ad2ba0e97 Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 29 Mar 2021 11:43:39 +0300 Subject: [PATCH 10/19] BREAKING_CHANGES: remove default `json` format of the response type --- CHANGELOG.md | 10 ++++++ .../base/http-clients/axios-http-client.eta | 5 +-- .../base/http-clients/fetch-http-client.eta | 5 +-- tests/generated/v2.0/adafruit.ts | 31 ++++++++++--------- tests/generated/v2.0/another-example.ts | 31 ++++++++++--------- tests/generated/v2.0/another-schema.ts | 31 ++++++++++--------- tests/generated/v2.0/api-with-examples.ts | 31 ++++++++++--------- tests/generated/v2.0/authentiq.ts | 31 ++++++++++--------- tests/generated/v2.0/enums.ts | 31 ++++++++++--------- tests/generated/v2.0/example1.ts | 31 ++++++++++--------- tests/generated/v2.0/file-formdata-example.ts | 31 ++++++++++--------- tests/generated/v2.0/furkot-example.ts | 31 ++++++++++--------- tests/generated/v2.0/giphy.ts | 31 ++++++++++--------- tests/generated/v2.0/github-swagger.ts | 31 ++++++++++--------- tests/generated/v2.0/path-args.ts | 31 ++++++++++--------- tests/generated/v2.0/petstore-expanded.ts | 31 ++++++++++--------- tests/generated/v2.0/petstore-minimal.ts | 31 ++++++++++--------- tests/generated/v2.0/petstore-simple.ts | 31 ++++++++++--------- tests/generated/v2.0/petstore-swagger-io.ts | 31 ++++++++++--------- .../v2.0/petstore-with-external-docs.ts | 31 ++++++++++--------- tests/generated/v2.0/petstore.ts | 31 ++++++++++--------- tests/generated/v2.0/query-path-param.ts | 31 ++++++++++--------- tests/generated/v2.0/uber.ts | 31 ++++++++++--------- tests/generated/v3.0/additional-properties.ts | 31 ++++++++++--------- .../generated/v3.0/additional-properties2.ts | 31 ++++++++++--------- tests/generated/v3.0/allof-example.ts | 31 ++++++++++--------- tests/generated/v3.0/anyof-example.ts | 31 ++++++++++--------- tests/generated/v3.0/api-with-examples.ts | 31 ++++++++++--------- tests/generated/v3.0/callback-example.ts | 31 ++++++++++--------- tests/generated/v3.0/components-responses.ts | 31 ++++++++++--------- tests/generated/v3.0/explode-param-3.0.1.ts | 31 ++++++++++--------- tests/generated/v3.0/full-swagger-scheme.ts | 31 ++++++++++--------- tests/generated/v3.0/link-example.ts | 31 ++++++++++--------- tests/generated/v3.0/no-definitions-schema.ts | 31 ++++++++++--------- tests/generated/v3.0/nullable-refs.ts | 31 ++++++++++--------- tests/generated/v3.0/oneof-example.ts | 31 ++++++++++--------- tests/generated/v3.0/personal-api-example.ts | 31 ++++++++++--------- tests/generated/v3.0/petstore-expanded.ts | 31 ++++++++++--------- tests/generated/v3.0/petstore.ts | 31 ++++++++++--------- tests/generated/v3.0/recursive-schema.ts | 31 ++++++++++--------- tests/generated/v3.0/responses.ts | 31 ++++++++++--------- tests/generated/v3.0/swaggerhub-template.ts | 31 ++++++++++--------- tests/generated/v3.0/tsoa-odd-types-3.0.2.ts | 31 ++++++++++--------- tests/generated/v3.0/up-banking.ts | 31 ++++++++++--------- tests/generated/v3.0/uspto.ts | 31 ++++++++++--------- tests/generated/v3.0/wrong-enum-subtypes.ts | 31 ++++++++++--------- tests/generated/v3.0/wrong-schema-names.ts | 31 ++++++++++--------- tests/spec/axios/schema.ts | 5 +-- tests/spec/axiosSingleHttpClient/schema.ts | 5 +-- tests/spec/defaultAsSuccess/schema.ts | 31 ++++++++++--------- tests/spec/defaultResponse/schema.ts | 31 ++++++++++--------- tests/spec/enumNamesAsValues/schema.ts | 31 ++++++++++--------- tests/spec/extractRequestParams/schema.ts | 31 ++++++++++--------- tests/spec/js/schema.js | 31 ++++++++++--------- tests/spec/jsAxios/schema.js | 5 +-- tests/spec/modular/http-client.ts | 31 ++++++++++--------- tests/spec/moduleNameFirstTag/schema.ts | 31 ++++++++++--------- tests/spec/moduleNameIndex/schema.ts | 31 ++++++++++--------- tests/spec/partialBaseTemplate/schema.ts | 31 ++++++++++--------- tests/spec/partialDefaultTemplate/schema.ts | 31 ++++++++++--------- tests/spec/responses/schema.ts | 31 ++++++++++--------- tests/spec/singleHttpClient/schema.ts | 31 ++++++++++--------- tests/spec/typeSuffixPrefix/schema.ts | 31 ++++++++++--------- tests/spec/unionEnums/schema.ts | 31 ++++++++++--------- 64 files changed, 1011 insertions(+), 822 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48bd593b..48400728 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # next release +BREAKING_CHANGES: +- remove default `json` format of the response type (both for `axios` and `fetch` http clients) +Features: +- Allow to set global response type format through `HttpClient` constructor + Example: +```ts + const httpClient = new HttpClient({ format: 'json' }); + // all request responses will been formatted as json +``` + # 7.0.1 Fixes: diff --git a/templates/base/http-clients/axios-http-client.eta b/templates/base/http-clients/axios-http-client.eta index 86c87ecd..64b31542 100644 --- a/templates/base/http-clients/axios-http-client.eta +++ b/templates/base/http-clients/axios-http-client.eta @@ -68,12 +68,13 @@ export class HttpClient { path, type, query, - format = "json", + format, body, ...params }: FullRequestParams): Promise> => { const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); + const responseFormat = format && requestParams.format; return this.instance.request({ ...requestParams, @@ -82,7 +83,7 @@ export class HttpClient { ...(requestParams.headers || {}), }, params: query, - responseType: format, + responseType: responseFormat, data: body, url: path, }); diff --git a/templates/base/http-clients/fetch-http-client.eta b/templates/base/http-clients/fetch-http-client.eta index cd5a29eb..2fa3d5f1 100644 --- a/templates/base/http-clients/fetch-http-client.eta +++ b/templates/base/http-clients/fetch-http-client.eta @@ -148,7 +148,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -157,6 +157,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch( `${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, @@ -174,7 +175,7 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() + const data = !responseFormat ? r : await response[responseFormat]() .then((data) => { if (r.ok) { r.data = data; diff --git a/tests/generated/v2.0/adafruit.ts b/tests/generated/v2.0/adafruit.ts index ac1f44f1..6637dbfa 100644 --- a/tests/generated/v2.0/adafruit.ts +++ b/tests/generated/v2.0/adafruit.ts @@ -308,7 +308,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -321,6 +321,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -335,19 +336,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/another-example.ts b/tests/generated/v2.0/another-example.ts index 548f8b02..c2ecd8e5 100644 --- a/tests/generated/v2.0/another-example.ts +++ b/tests/generated/v2.0/another-example.ts @@ -284,7 +284,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -297,6 +297,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -311,19 +312,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/another-schema.ts b/tests/generated/v2.0/another-schema.ts index 5c2a12b5..dde7244b 100644 --- a/tests/generated/v2.0/another-schema.ts +++ b/tests/generated/v2.0/another-schema.ts @@ -176,7 +176,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -189,6 +189,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -203,19 +204,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/api-with-examples.ts b/tests/generated/v2.0/api-with-examples.ts index d655bb99..b6526875 100644 --- a/tests/generated/v2.0/api-with-examples.ts +++ b/tests/generated/v2.0/api-with-examples.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/authentiq.ts b/tests/generated/v2.0/authentiq.ts index 8866c0e4..7ceaf4dd 100644 --- a/tests/generated/v2.0/authentiq.ts +++ b/tests/generated/v2.0/authentiq.ts @@ -205,7 +205,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -218,6 +218,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -232,19 +233,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/enums.ts b/tests/generated/v2.0/enums.ts index 96478218..80d82f0d 100644 --- a/tests/generated/v2.0/enums.ts +++ b/tests/generated/v2.0/enums.ts @@ -218,7 +218,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -231,6 +231,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -245,19 +246,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/example1.ts b/tests/generated/v2.0/example1.ts index ec9decec..f9b97962 100644 --- a/tests/generated/v2.0/example1.ts +++ b/tests/generated/v2.0/example1.ts @@ -180,7 +180,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -193,6 +193,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -207,19 +208,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/file-formdata-example.ts b/tests/generated/v2.0/file-formdata-example.ts index 68983b3e..39f4028d 100644 --- a/tests/generated/v2.0/file-formdata-example.ts +++ b/tests/generated/v2.0/file-formdata-example.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/furkot-example.ts b/tests/generated/v2.0/furkot-example.ts index 90548a41..cb481ce7 100644 --- a/tests/generated/v2.0/furkot-example.ts +++ b/tests/generated/v2.0/furkot-example.ts @@ -216,7 +216,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -229,6 +229,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -243,19 +244,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/giphy.ts b/tests/generated/v2.0/giphy.ts index 0f151ac9..af47fd42 100644 --- a/tests/generated/v2.0/giphy.ts +++ b/tests/generated/v2.0/giphy.ts @@ -435,7 +435,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -448,6 +448,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -462,19 +463,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/github-swagger.ts b/tests/generated/v2.0/github-swagger.ts index 46ccbe0f..cb649cdf 100644 --- a/tests/generated/v2.0/github-swagger.ts +++ b/tests/generated/v2.0/github-swagger.ts @@ -1588,7 +1588,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -1601,6 +1601,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -1615,19 +1616,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/path-args.ts b/tests/generated/v2.0/path-args.ts index 57ccad47..dcc4ea6c 100644 --- a/tests/generated/v2.0/path-args.ts +++ b/tests/generated/v2.0/path-args.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/petstore-expanded.ts b/tests/generated/v2.0/petstore-expanded.ts index 72c05765..7c812ad2 100644 --- a/tests/generated/v2.0/petstore-expanded.ts +++ b/tests/generated/v2.0/petstore-expanded.ts @@ -190,7 +190,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -203,6 +203,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -217,19 +218,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/petstore-minimal.ts b/tests/generated/v2.0/petstore-minimal.ts index 381fa225..e4833c9e 100644 --- a/tests/generated/v2.0/petstore-minimal.ts +++ b/tests/generated/v2.0/petstore-minimal.ts @@ -161,7 +161,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -174,6 +174,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -188,19 +189,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/petstore-simple.ts b/tests/generated/v2.0/petstore-simple.ts index fd0f646f..e1c62580 100644 --- a/tests/generated/v2.0/petstore-simple.ts +++ b/tests/generated/v2.0/petstore-simple.ts @@ -176,7 +176,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -189,6 +189,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -203,19 +204,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/petstore-swagger-io.ts b/tests/generated/v2.0/petstore-swagger-io.ts index fb977013..77729a98 100644 --- a/tests/generated/v2.0/petstore-swagger-io.ts +++ b/tests/generated/v2.0/petstore-swagger-io.ts @@ -221,7 +221,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -234,6 +234,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -248,19 +249,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/petstore-with-external-docs.ts b/tests/generated/v2.0/petstore-with-external-docs.ts index c903a343..e144eca4 100644 --- a/tests/generated/v2.0/petstore-with-external-docs.ts +++ b/tests/generated/v2.0/petstore-with-external-docs.ts @@ -166,7 +166,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -179,6 +179,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -193,19 +194,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/petstore.ts b/tests/generated/v2.0/petstore.ts index cb3169d2..cc9b15e7 100644 --- a/tests/generated/v2.0/petstore.ts +++ b/tests/generated/v2.0/petstore.ts @@ -168,7 +168,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -181,6 +181,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -195,19 +196,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/query-path-param.ts b/tests/generated/v2.0/query-path-param.ts index ffff4f64..c18fa6cd 100644 --- a/tests/generated/v2.0/query-path-param.ts +++ b/tests/generated/v2.0/query-path-param.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v2.0/uber.ts b/tests/generated/v2.0/uber.ts index d7a5bc8a..fc094849 100644 --- a/tests/generated/v2.0/uber.ts +++ b/tests/generated/v2.0/uber.ts @@ -248,7 +248,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -261,6 +261,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -275,19 +276,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/additional-properties.ts b/tests/generated/v3.0/additional-properties.ts index e6906ee6..6460803e 100644 --- a/tests/generated/v3.0/additional-properties.ts +++ b/tests/generated/v3.0/additional-properties.ts @@ -160,7 +160,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -173,6 +173,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -187,19 +188,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/additional-properties2.ts b/tests/generated/v3.0/additional-properties2.ts index e488763a..93964261 100644 --- a/tests/generated/v3.0/additional-properties2.ts +++ b/tests/generated/v3.0/additional-properties2.ts @@ -157,7 +157,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -170,6 +170,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -184,19 +185,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/allof-example.ts b/tests/generated/v3.0/allof-example.ts index e65a7689..1b4e43f7 100644 --- a/tests/generated/v3.0/allof-example.ts +++ b/tests/generated/v3.0/allof-example.ts @@ -161,7 +161,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -174,6 +174,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -188,19 +189,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/anyof-example.ts b/tests/generated/v3.0/anyof-example.ts index 58de0d18..6a36362a 100644 --- a/tests/generated/v3.0/anyof-example.ts +++ b/tests/generated/v3.0/anyof-example.ts @@ -163,7 +163,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -176,6 +176,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -190,19 +191,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/api-with-examples.ts b/tests/generated/v3.0/api-with-examples.ts index ec5fa6a2..29e0e7c2 100644 --- a/tests/generated/v3.0/api-with-examples.ts +++ b/tests/generated/v3.0/api-with-examples.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/callback-example.ts b/tests/generated/v3.0/callback-example.ts index 4fe7a648..fdae63d8 100644 --- a/tests/generated/v3.0/callback-example.ts +++ b/tests/generated/v3.0/callback-example.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/components-responses.ts b/tests/generated/v3.0/components-responses.ts index 5b8762af..3188e2e7 100644 --- a/tests/generated/v3.0/components-responses.ts +++ b/tests/generated/v3.0/components-responses.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/explode-param-3.0.1.ts b/tests/generated/v3.0/explode-param-3.0.1.ts index 7f96e23f..b1dff77d 100644 --- a/tests/generated/v3.0/explode-param-3.0.1.ts +++ b/tests/generated/v3.0/explode-param-3.0.1.ts @@ -173,7 +173,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -186,6 +186,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -200,19 +201,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/full-swagger-scheme.ts b/tests/generated/v3.0/full-swagger-scheme.ts index dd6b8c7a..50df13d6 100644 --- a/tests/generated/v3.0/full-swagger-scheme.ts +++ b/tests/generated/v3.0/full-swagger-scheme.ts @@ -9097,7 +9097,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -9110,6 +9110,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -9124,19 +9125,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/link-example.ts b/tests/generated/v3.0/link-example.ts index 795512e2..65ebac12 100644 --- a/tests/generated/v3.0/link-example.ts +++ b/tests/generated/v3.0/link-example.ts @@ -170,7 +170,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -183,6 +183,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -197,19 +198,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/no-definitions-schema.ts b/tests/generated/v3.0/no-definitions-schema.ts index 405f3434..a4065bda 100644 --- a/tests/generated/v3.0/no-definitions-schema.ts +++ b/tests/generated/v3.0/no-definitions-schema.ts @@ -166,7 +166,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -179,6 +179,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -193,19 +194,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/nullable-refs.ts b/tests/generated/v3.0/nullable-refs.ts index eba313e4..b3f70268 100644 --- a/tests/generated/v3.0/nullable-refs.ts +++ b/tests/generated/v3.0/nullable-refs.ts @@ -167,7 +167,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -180,6 +180,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -194,19 +195,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/oneof-example.ts b/tests/generated/v3.0/oneof-example.ts index 89d00ac4..0f2bc91c 100644 --- a/tests/generated/v3.0/oneof-example.ts +++ b/tests/generated/v3.0/oneof-example.ts @@ -163,7 +163,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -176,6 +176,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -190,19 +191,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/personal-api-example.ts b/tests/generated/v3.0/personal-api-example.ts index 611dbc2f..c16284dd 100644 --- a/tests/generated/v3.0/personal-api-example.ts +++ b/tests/generated/v3.0/personal-api-example.ts @@ -354,7 +354,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -367,6 +367,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -381,19 +382,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/petstore-expanded.ts b/tests/generated/v3.0/petstore-expanded.ts index 69b12319..a740bfb7 100644 --- a/tests/generated/v3.0/petstore-expanded.ts +++ b/tests/generated/v3.0/petstore-expanded.ts @@ -166,7 +166,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -179,6 +179,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -193,19 +194,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/petstore.ts b/tests/generated/v3.0/petstore.ts index 746205c7..97544bd8 100644 --- a/tests/generated/v3.0/petstore.ts +++ b/tests/generated/v3.0/petstore.ts @@ -170,7 +170,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -183,6 +183,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -197,19 +198,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/recursive-schema.ts b/tests/generated/v3.0/recursive-schema.ts index 1144d17f..dce6b380 100644 --- a/tests/generated/v3.0/recursive-schema.ts +++ b/tests/generated/v3.0/recursive-schema.ts @@ -167,7 +167,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -180,6 +180,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -194,19 +195,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/responses.ts b/tests/generated/v3.0/responses.ts index 5e56e815..cbc1d267 100644 --- a/tests/generated/v3.0/responses.ts +++ b/tests/generated/v3.0/responses.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/swaggerhub-template.ts b/tests/generated/v3.0/swaggerhub-template.ts index 6aa1354c..1612a36a 100644 --- a/tests/generated/v3.0/swaggerhub-template.ts +++ b/tests/generated/v3.0/swaggerhub-template.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts index 0d7a02c4..96993846 100644 --- a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts +++ b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts @@ -274,7 +274,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -287,6 +287,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -301,19 +302,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/up-banking.ts b/tests/generated/v3.0/up-banking.ts index 9d94e477..fac58171 100644 --- a/tests/generated/v3.0/up-banking.ts +++ b/tests/generated/v3.0/up-banking.ts @@ -681,7 +681,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -694,6 +694,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -708,19 +709,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/uspto.ts b/tests/generated/v3.0/uspto.ts index 13ff46da..e6cd590b 100644 --- a/tests/generated/v3.0/uspto.ts +++ b/tests/generated/v3.0/uspto.ts @@ -170,7 +170,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -183,6 +183,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -197,19 +198,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/wrong-enum-subtypes.ts b/tests/generated/v3.0/wrong-enum-subtypes.ts index d38352df..54ec0d72 100644 --- a/tests/generated/v3.0/wrong-enum-subtypes.ts +++ b/tests/generated/v3.0/wrong-enum-subtypes.ts @@ -155,7 +155,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -168,6 +168,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -182,19 +183,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/generated/v3.0/wrong-schema-names.ts b/tests/generated/v3.0/wrong-schema-names.ts index d6a904c4..fcc72fda 100644 --- a/tests/generated/v3.0/wrong-schema-names.ts +++ b/tests/generated/v3.0/wrong-schema-names.ts @@ -177,7 +177,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -190,6 +190,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -204,19 +205,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/axios/schema.ts b/tests/spec/axios/schema.ts index 0aa129ce..b6b8aa45 100644 --- a/tests/spec/axios/schema.ts +++ b/tests/spec/axios/schema.ts @@ -1512,7 +1512,7 @@ export class HttpClient { path, type, query, - format = "json", + format, body, ...params }: FullRequestParams): Promise> => { @@ -1522,6 +1522,7 @@ export class HttpClient { (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); + const responseFormat = format && requestParams.format; return this.instance.request({ ...requestParams, @@ -1530,7 +1531,7 @@ export class HttpClient { ...(requestParams.headers || {}), }, params: query, - responseType: format, + responseType: responseFormat, data: body, url: path, }); diff --git a/tests/spec/axiosSingleHttpClient/schema.ts b/tests/spec/axiosSingleHttpClient/schema.ts index a987e97e..ceb0f017 100644 --- a/tests/spec/axiosSingleHttpClient/schema.ts +++ b/tests/spec/axiosSingleHttpClient/schema.ts @@ -1512,7 +1512,7 @@ export class HttpClient { path, type, query, - format = "json", + format, body, ...params }: FullRequestParams): Promise> => { @@ -1522,6 +1522,7 @@ export class HttpClient { (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); + const responseFormat = format && requestParams.format; return this.instance.request({ ...requestParams, @@ -1530,7 +1531,7 @@ export class HttpClient { ...(requestParams.headers || {}), }, params: query, - responseType: format, + responseType: responseFormat, data: body, url: path, }); diff --git a/tests/spec/defaultAsSuccess/schema.ts b/tests/spec/defaultAsSuccess/schema.ts index 13f8dcec..d2e27d77 100644 --- a/tests/spec/defaultAsSuccess/schema.ts +++ b/tests/spec/defaultAsSuccess/schema.ts @@ -205,7 +205,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -218,6 +218,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -232,19 +233,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/defaultResponse/schema.ts b/tests/spec/defaultResponse/schema.ts index bb09c563..b734e421 100644 --- a/tests/spec/defaultResponse/schema.ts +++ b/tests/spec/defaultResponse/schema.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/enumNamesAsValues/schema.ts b/tests/spec/enumNamesAsValues/schema.ts index 97158894..b4cc57ce 100644 --- a/tests/spec/enumNamesAsValues/schema.ts +++ b/tests/spec/enumNamesAsValues/schema.ts @@ -351,7 +351,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -364,6 +364,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -378,19 +379,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/extractRequestParams/schema.ts b/tests/spec/extractRequestParams/schema.ts index d132cd5f..03d220fc 100644 --- a/tests/spec/extractRequestParams/schema.ts +++ b/tests/spec/extractRequestParams/schema.ts @@ -245,7 +245,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -258,6 +258,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -272,19 +273,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/js/schema.js b/tests/spec/js/schema.js index cbd9910f..5b0104c4 100644 --- a/tests/spec/js/schema.js +++ b/tests/spec/js/schema.js @@ -58,7 +58,7 @@ export class HttpClient { this.abortControllers.delete(cancelToken); } }; - this.request = async ({ body, secure, path, type, query, format = "json", baseUrl, cancelToken, ...params }) => { + this.request = async ({ body, secure, path, type, query, format, baseUrl, cancelToken, ...params }) => { const secureParams = ((typeof secure === "boolean" ? secure : this.baseApiParams.secure) && this.securityWorker && @@ -67,6 +67,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { @@ -79,19 +80,21 @@ export class HttpClient { const r = response; r.data = null; r.error = null; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); } diff --git a/tests/spec/jsAxios/schema.js b/tests/spec/jsAxios/schema.js index fc81ef3f..73960bd9 100644 --- a/tests/spec/jsAxios/schema.js +++ b/tests/spec/jsAxios/schema.js @@ -22,13 +22,14 @@ export class HttpClient { this.setSecurityData = (data) => { this.securityData = data; }; - this.request = async ({ secure, path, type, query, format = "json", body, ...params }) => { + this.request = async ({ secure, path, type, query, format, body, ...params }) => { const secureParams = ((typeof secure === "boolean" ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); + const responseFormat = format && requestParams.format; return this.instance.request({ ...requestParams, headers: { @@ -36,7 +37,7 @@ export class HttpClient { ...(requestParams.headers || {}), }, params: query, - responseType: format, + responseType: responseFormat, data: body, url: path, }); diff --git a/tests/spec/modular/http-client.ts b/tests/spec/modular/http-client.ts index f2f70b5c..6ef50c38 100644 --- a/tests/spec/modular/http-client.ts +++ b/tests/spec/modular/http-client.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/moduleNameFirstTag/schema.ts b/tests/spec/moduleNameFirstTag/schema.ts index 455e2641..0ce5859c 100644 --- a/tests/spec/moduleNameFirstTag/schema.ts +++ b/tests/spec/moduleNameFirstTag/schema.ts @@ -281,7 +281,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -294,6 +294,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -308,19 +309,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/moduleNameIndex/schema.ts b/tests/spec/moduleNameIndex/schema.ts index c3d68aec..62afac40 100644 --- a/tests/spec/moduleNameIndex/schema.ts +++ b/tests/spec/moduleNameIndex/schema.ts @@ -281,7 +281,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -294,6 +294,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -308,19 +309,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/partialBaseTemplate/schema.ts b/tests/spec/partialBaseTemplate/schema.ts index 2691f04d..edc5620c 100644 --- a/tests/spec/partialBaseTemplate/schema.ts +++ b/tests/spec/partialBaseTemplate/schema.ts @@ -165,7 +165,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -178,6 +178,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -192,19 +193,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/partialDefaultTemplate/schema.ts b/tests/spec/partialDefaultTemplate/schema.ts index 3e853066..1ba7a3e8 100644 --- a/tests/spec/partialDefaultTemplate/schema.ts +++ b/tests/spec/partialDefaultTemplate/schema.ts @@ -161,7 +161,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -174,6 +174,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -188,19 +189,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/responses/schema.ts b/tests/spec/responses/schema.ts index f67ef1ad..8f462d0f 100644 --- a/tests/spec/responses/schema.ts +++ b/tests/spec/responses/schema.ts @@ -205,7 +205,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -218,6 +218,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -232,19 +233,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/singleHttpClient/schema.ts b/tests/spec/singleHttpClient/schema.ts index 324b4ab1..58a07cdf 100644 --- a/tests/spec/singleHttpClient/schema.ts +++ b/tests/spec/singleHttpClient/schema.ts @@ -153,7 +153,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -166,6 +166,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -180,19 +181,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/typeSuffixPrefix/schema.ts b/tests/spec/typeSuffixPrefix/schema.ts index 818275f5..0f516c6e 100644 --- a/tests/spec/typeSuffixPrefix/schema.ts +++ b/tests/spec/typeSuffixPrefix/schema.ts @@ -1598,7 +1598,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -1611,6 +1611,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -1625,19 +1626,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); diff --git a/tests/spec/unionEnums/schema.ts b/tests/spec/unionEnums/schema.ts index cb14c7a3..9f611759 100644 --- a/tests/spec/unionEnums/schema.ts +++ b/tests/spec/unionEnums/schema.ts @@ -165,7 +165,7 @@ export class HttpClient { path, type, query, - format = "json", + format, baseUrl, cancelToken, ...params @@ -178,6 +178,7 @@ export class HttpClient { const requestParams = this.mergeRequestParams(params, secureParams); const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; + const responseFormat = format && requestParams.format; return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -192,19 +193,21 @@ export class HttpClient { r.data = (null as unknown) as T; r.error = (null as unknown) as E; - const data = await response[format]() - .then((data) => { - if (r.ok) { - r.data = data; - } else { - r.error = data; - } - return r; - }) - .catch((e) => { - r.error = e; - return r; - }); + const data = !responseFormat + ? r + : await response[responseFormat]() + .then((data) => { + if (r.ok) { + r.data = data; + } else { + r.error = data; + } + return r; + }) + .catch((e) => { + r.error = e; + return r; + }); if (cancelToken) { this.abortControllers.delete(cancelToken); From 14e40cf9e5f852813a7aa77a1229a65217bf949a Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 29 Mar 2021 16:48:06 +0300 Subject: [PATCH 11/19] fix: missing `schema.$ref` in inline enum schemas --- CHANGELOG.md | 3 +++ package.json | 4 ++-- src/schema.js | 4 ++++ src/typeFormatters.js | 14 ++++++++------ tests/generated/v3.0/up-banking.ts | 11 +++++++++++ tests/schemas/v3.0/up-banking.json | 15 +++++++++++++++ 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48400728..5e50c6be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ BREAKING_CHANGES: - remove default `json` format of the response type (both for `axios` and `fetch` http clients) + Features: - Allow to set global response type format through `HttpClient` constructor Example: @@ -9,6 +10,8 @@ Features: const httpClient = new HttpClient({ format: 'json' }); // all request responses will been formatted as json ``` +Fixes: +- Missing `schema.$ref` in inline enum schemas # 7.0.1 diff --git a/package.json b/package.json index 36894bcc..4ad71966 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "node:debug": "node --nolazy swagger-test-cli/generate.js", "contributors": "all-contributors generate", "cli:help": "node index.js -h", - "test-all": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js generate validate test:* --continue-on-error", - "test-specific": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js test:* --continue-on-error", + "test-all": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js --sequential generate validate --parallel test:*", + "test-specific": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js --sequential generate validate --parallel test:*", "generate": "node tests/generate.js", "generate:debug": "node --nolazy tests/generate.js", "validate": "node tests/validate.js", diff --git a/src/schema.js b/src/schema.js index 503af388..33710049 100644 --- a/src/schema.js +++ b/src/schema.js @@ -235,6 +235,8 @@ const attachParsedRef = (originalSchema, parsedSchema) => { const schemaParsers = { [SCHEMA_TYPES.ENUM]: (schema, typeName) => { + const refType = getRefType(schema); + const $ref = (refType && refType.$ref) || null; const enumNamesAsValues = config.enumNamesAsValues; const keyType = getType(schema); const enumNames = getEnumNames(schema); @@ -277,6 +279,8 @@ const schemaParsers = { return attachParsedRef(schema, { ...(_.isObject(schema) ? schema : {}), + $ref: $ref, + typeName: ($ref && refType.typeName) || null, $parsedSchema: true, schemaType: SCHEMA_TYPES.ENUM, type: SCHEMA_TYPES.ENUM, diff --git a/src/typeFormatters.js b/src/typeFormatters.js index 937a0d6e..bca14db5 100644 --- a/src/typeFormatters.js +++ b/src/typeFormatters.js @@ -57,12 +57,14 @@ const inlineExtraFormatters = { [SCHEMA_TYPES.ENUM]: (parsedSchema) => { return { ...parsedSchema, - content: _.uniq( - _.compact([ - ..._.map(parsedSchema.content, ({ value }) => `${value}`), - parsedSchema.nullable && TS_KEYWORDS.NULL, - ]), - ).join(" | "), + content: parsedSchema.$ref + ? parsedSchema.typeName + : _.uniq( + _.compact([ + ..._.map(parsedSchema.content, ({ value }) => `${value}`), + parsedSchema.nullable && TS_KEYWORDS.NULL, + ]), + ).join(" | "), }; }, }; diff --git a/tests/generated/v3.0/up-banking.ts b/tests/generated/v3.0/up-banking.ts index fac58171..f17f7a0c 100644 --- a/tests/generated/v3.0/up-banking.ts +++ b/tests/generated/v3.0/up-banking.ts @@ -9,6 +9,16 @@ * --------------------------------------------------------------- */ +/** + * Bla bla bla foo bar baz + */ +export enum SomeEnumName { + Foo = "Foo", + Bar = "Bar", + Baz = "Baz", + Bad = "Bad", +} + /** * Specifies the type of bank account. Currently returned values are `SAVER` and `TRANSACTIONAL`. @@ -947,6 +957,7 @@ export class Api extends HttpClient Date: Fri, 2 Apr 2021 05:57:57 -0700 Subject: [PATCH 12/19] Allow passing custom fetch function (#218) * Allow passing custom fetch function * Fixing a mistake * Using ApiConfig instead of second param --- templates/base/http-clients/fetch-http-client.eta | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/base/http-clients/fetch-http-client.eta b/templates/base/http-clients/fetch-http-client.eta index 2fa3d5f1..e7d898b1 100644 --- a/templates/base/http-clients/fetch-http-client.eta +++ b/templates/base/http-clients/fetch-http-client.eta @@ -31,6 +31,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise } export interface HttpResponse extends Response { @@ -51,6 +52,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: 'same-origin', @@ -118,7 +120,7 @@ export class HttpClient { }, }; } - + private createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => { if (this.abortControllers.has(cancelToken)) { const abortController = this.abortControllers.get(cancelToken); @@ -127,7 +129,7 @@ export class HttpClient { } return void 0; } - + const abortController = new AbortController(); this.abortControllers.set(cancelToken, abortController); return abortController.signal; @@ -141,7 +143,7 @@ export class HttpClient { this.abortControllers.delete(cancelToken); } } - + public request = async ({ body, secure, @@ -159,7 +161,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch( + return this.customFetch( `${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, @@ -188,7 +190,7 @@ export class HttpClient { r.error = e; return r; }); - + if (cancelToken) { this.abortControllers.delete(cancelToken); } From 0ecdd40fe912a4869ced3b5aa157a6d058d6622a Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 5 Apr 2021 00:52:37 +0300 Subject: [PATCH 13/19] fix: tests --- package.json | 4 ++-- .../base/http-clients/axios-http-client.eta | 7 ++++-- tests/helpers/validateGeneratedModule.js | 22 ++++++------------- tests/spec/axios/schema.ts | 7 ++++-- tests/spec/axiosSingleHttpClient/schema.ts | 7 ++++-- tests/spec/jsAxios/schema.d.ts | 4 +++- tests/spec/jsAxios/schema.js | 5 +++-- tests/spec/templates/schema.ts | 2 +- .../templates/spec_templates/http-client.eta | 2 +- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 4ad71966..91ef5ad3 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "node:debug": "node --nolazy swagger-test-cli/generate.js", "contributors": "all-contributors generate", "cli:help": "node index.js -h", - "test-all": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js --sequential generate validate --parallel test:*", - "test-specific": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js --sequential generate validate --parallel test:*", + "test-all": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js generate validate test:*", + "test-specific": "node ./node_modules/npm-run-all/bin/npm-run-all/index.js generate validate test:*", "generate": "node tests/generate.js", "generate:debug": "node --nolazy tests/generate.js", "validate": "node tests/validate.js", diff --git a/templates/base/http-clients/axios-http-client.eta b/templates/base/http-clients/axios-http-client.eta index 64b31542..920cc6b4 100644 --- a/templates/base/http-clients/axios-http-client.eta +++ b/templates/base/http-clients/axios-http-client.eta @@ -26,6 +26,7 @@ export type RequestParams = Omit extends Omit { securityWorker?: (securityData: SecurityDataType | null) => Promise | AxiosRequestConfig | void; secure?: boolean; + format?: ResponseType; } export enum ContentType { @@ -39,10 +40,12 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private secure?: boolean; + private format?: ResponseType; - constructor({ securityWorker, secure, ...axiosConfig }: ApiConfig = {}) { + constructor({ securityWorker, secure, format, ...axiosConfig }: ApiConfig = {}) { this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || "<%~ apiConfig.baseUrl %>" }) this.secure = secure; + this.format = format; this.securityWorker = securityWorker; } @@ -74,7 +77,7 @@ export class HttpClient { }: FullRequestParams): Promise> => { const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); - const responseFormat = format && requestParams.format; + const responseFormat = (format && this.format) || void 0; return this.instance.request({ ...requestParams, diff --git a/tests/helpers/validateGeneratedModule.js b/tests/helpers/validateGeneratedModule.js index 2369e392..07a5efbd 100644 --- a/tests/helpers/validateGeneratedModule.js +++ b/tests/helpers/validateGeneratedModule.js @@ -21,30 +21,22 @@ const getDiagnosticsFromPath = (pathToFile) => // }).diagnostics module.exports = ({ pathToFile }) => { - process.stdout.write(`validating ${relative("", pathToFile)}: `); - const diagnostics = getDiagnosticsFromPath(pathToFile); + const relativePathToFile = relative("", pathToFile); + console.log(`validating ${relativePathToFile}: errors ${diagnostics.length}`); diagnostics.forEach(({ messageText, file, start }) => { var message = tsc.flattenDiagnosticMessageText(messageText, "\n"); if (!file) { - console.error(message); + console.error(`${relativePathToFile}\r\n`, message); return; } var { line, character } = file.getLineAndCharacterOfPosition(start); - console.error(`${file.fileName} (${line + 1},${character + 1}): ${message}`); + console.error( + `${relativePathToFile}\r\n`, + `${file.fileName} (${line + 1},${character + 1}): ${message}`, + ); }); - process.stdout.write(`errors ${diagnostics.length}`); - - if (diagnostics.length) { - process.stdout.write(`\r\n`); - } else { - if (process.stdout.clearLine && process.stdout.cursorTo) { - process.stdout.clearLine(process.stdout); - process.stdout.cursorTo(0); - } - } - return diagnostics; }; diff --git a/tests/spec/axios/schema.ts b/tests/spec/axios/schema.ts index b6b8aa45..d8f76a0f 100644 --- a/tests/spec/axios/schema.ts +++ b/tests/spec/axios/schema.ts @@ -1470,6 +1470,7 @@ export interface ApiConfig extends Omit Promise | AxiosRequestConfig | void; secure?: boolean; + format?: ResponseType; } export enum ContentType { @@ -1483,10 +1484,12 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private secure?: boolean; + private format?: ResponseType; - constructor({ securityWorker, secure, ...axiosConfig }: ApiConfig = {}) { + constructor({ securityWorker, secure, format, ...axiosConfig }: ApiConfig = {}) { this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || "https://api.github.com" }); this.secure = secure; + this.format = format; this.securityWorker = securityWorker; } @@ -1522,7 +1525,7 @@ export class HttpClient { (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); - const responseFormat = format && requestParams.format; + const responseFormat = (format && this.format) || void 0; return this.instance.request({ ...requestParams, diff --git a/tests/spec/axiosSingleHttpClient/schema.ts b/tests/spec/axiosSingleHttpClient/schema.ts index ceb0f017..9c43d8a7 100644 --- a/tests/spec/axiosSingleHttpClient/schema.ts +++ b/tests/spec/axiosSingleHttpClient/schema.ts @@ -1470,6 +1470,7 @@ export interface ApiConfig extends Omit Promise | AxiosRequestConfig | void; secure?: boolean; + format?: ResponseType; } export enum ContentType { @@ -1483,10 +1484,12 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private secure?: boolean; + private format?: ResponseType; - constructor({ securityWorker, secure, ...axiosConfig }: ApiConfig = {}) { + constructor({ securityWorker, secure, format, ...axiosConfig }: ApiConfig = {}) { this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || "https://api.github.com" }); this.secure = secure; + this.format = format; this.securityWorker = securityWorker; } @@ -1522,7 +1525,7 @@ export class HttpClient { (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); - const responseFormat = format && requestParams.format; + const responseFormat = (format && this.format) || void 0; return this.instance.request({ ...requestParams, diff --git a/tests/spec/jsAxios/schema.d.ts b/tests/spec/jsAxios/schema.d.ts index b908b8a1..2243a288 100644 --- a/tests/spec/jsAxios/schema.d.ts +++ b/tests/spec/jsAxios/schema.d.ts @@ -1724,6 +1724,7 @@ export interface ApiConfig extends Omit Promise | AxiosRequestConfig | void; secure?: boolean; + format?: ResponseType; } export declare enum ContentType { Json = "application/json", @@ -1735,7 +1736,8 @@ export declare class HttpClient { private securityData; private securityWorker?; private secure?; - constructor({ securityWorker, secure, ...axiosConfig }?: ApiConfig); + private format?; + constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig); setSecurityData: (data: SecurityDataType | null) => void; private mergeRequestParams; request: ({ diff --git a/tests/spec/jsAxios/schema.js b/tests/spec/jsAxios/schema.js index 73960bd9..226efe0e 100644 --- a/tests/spec/jsAxios/schema.js +++ b/tests/spec/jsAxios/schema.js @@ -17,7 +17,7 @@ export var ContentType; ContentType["UrlEncoded"] = "application/x-www-form-urlencoded"; })(ContentType || (ContentType = {})); export class HttpClient { - constructor({ securityWorker, secure, ...axiosConfig } = {}) { + constructor({ securityWorker, secure, format, ...axiosConfig } = {}) { this.securityData = null; this.setSecurityData = (data) => { this.securityData = data; @@ -29,7 +29,7 @@ export class HttpClient { (await this.securityWorker(this.securityData))) || {}; const requestParams = this.mergeRequestParams(params, secureParams); - const responseFormat = format && requestParams.format; + const responseFormat = (format && this.format) || void 0; return this.instance.request({ ...requestParams, headers: { @@ -44,6 +44,7 @@ export class HttpClient { }; this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || "https://api.github.com" }); this.secure = secure; + this.format = format; this.securityWorker = securityWorker; } mergeRequestParams(params1, params2) { diff --git a/tests/spec/templates/schema.ts b/tests/spec/templates/schema.ts index 25209a8f..79756117 100644 --- a/tests/spec/templates/schema.ts +++ b/tests/spec/templates/schema.ts @@ -1579,7 +1579,7 @@ export class HttpClient { }; } -/* CUSTOM TEMPLATE */ +/* HTTP CLIENT TEMPLATE */ /** * @title GitHub * @version v3 diff --git a/tests/spec/templates/spec_templates/http-client.eta b/tests/spec/templates/spec_templates/http-client.eta index 15f3a468..c2fc9560 100644 --- a/tests/spec/templates/spec_templates/http-client.eta +++ b/tests/spec/templates/spec_templates/http-client.eta @@ -137,4 +137,4 @@ export class HttpClient<<%~ apiConfig.generic.map(g => `${g.name} = unknown`).jo } } -/* CUSTOM TEMPLATE */ \ No newline at end of file +/* HTTP CLIENT TEMPLATE */ \ No newline at end of file From 26b55356d93555d08d7c67b708caac9a14a722f6 Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 5 Apr 2021 01:02:22 +0300 Subject: [PATCH 14/19] chore: refresh schemas --- CHANGELOG.md | 1 + tests/generated/v2.0/adafruit.ts | 4 +++- tests/generated/v2.0/another-example.ts | 4 +++- tests/generated/v2.0/another-schema.ts | 4 +++- tests/generated/v2.0/api-with-examples.ts | 4 +++- tests/generated/v2.0/authentiq.ts | 4 +++- tests/generated/v2.0/enums.ts | 4 +++- tests/generated/v2.0/example1.ts | 4 +++- tests/generated/v2.0/file-formdata-example.ts | 4 +++- tests/generated/v2.0/furkot-example.ts | 4 +++- tests/generated/v2.0/giphy.ts | 4 +++- tests/generated/v2.0/github-swagger.ts | 4 +++- tests/generated/v2.0/path-args.ts | 4 +++- tests/generated/v2.0/petstore-expanded.ts | 4 +++- tests/generated/v2.0/petstore-minimal.ts | 4 +++- tests/generated/v2.0/petstore-simple.ts | 4 +++- tests/generated/v2.0/petstore-swagger-io.ts | 4 +++- tests/generated/v2.0/petstore-with-external-docs.ts | 4 +++- tests/generated/v2.0/petstore.ts | 4 +++- tests/generated/v2.0/query-path-param.ts | 4 +++- tests/generated/v2.0/uber.ts | 4 +++- tests/generated/v3.0/additional-properties.ts | 4 +++- tests/generated/v3.0/additional-properties2.ts | 4 +++- tests/generated/v3.0/allof-example.ts | 4 +++- tests/generated/v3.0/anyof-example.ts | 4 +++- tests/generated/v3.0/api-with-examples.ts | 4 +++- tests/generated/v3.0/callback-example.ts | 4 +++- tests/generated/v3.0/components-responses.ts | 4 +++- tests/generated/v3.0/explode-param-3.0.1.ts | 4 +++- tests/generated/v3.0/full-swagger-scheme.ts | 4 +++- tests/generated/v3.0/link-example.ts | 4 +++- tests/generated/v3.0/no-definitions-schema.ts | 4 +++- tests/generated/v3.0/nullable-refs.ts | 4 +++- tests/generated/v3.0/oneof-example.ts | 4 +++- tests/generated/v3.0/personal-api-example.ts | 4 +++- tests/generated/v3.0/petstore-expanded.ts | 4 +++- tests/generated/v3.0/petstore.ts | 4 +++- tests/generated/v3.0/recursive-schema.ts | 4 +++- tests/generated/v3.0/responses.ts | 4 +++- tests/generated/v3.0/swaggerhub-template.ts | 4 +++- tests/generated/v3.0/tsoa-odd-types-3.0.2.ts | 4 +++- tests/generated/v3.0/up-banking.ts | 4 +++- tests/generated/v3.0/uspto.ts | 4 +++- tests/generated/v3.0/wrong-enum-subtypes.ts | 4 +++- tests/generated/v3.0/wrong-schema-names.ts | 4 +++- tests/spec/defaultAsSuccess/schema.ts | 4 +++- tests/spec/defaultResponse/schema.ts | 4 +++- tests/spec/enumNamesAsValues/schema.ts | 4 +++- tests/spec/extractRequestParams/schema.ts | 4 +++- tests/spec/js/schema.d.ts | 2 ++ tests/spec/js/schema.js | 3 ++- tests/spec/modular/http-client.ts | 4 +++- tests/spec/moduleNameFirstTag/schema.ts | 4 +++- tests/spec/moduleNameIndex/schema.ts | 4 +++- tests/spec/partialBaseTemplate/schema.ts | 4 +++- tests/spec/partialDefaultTemplate/schema.ts | 4 +++- tests/spec/responses/schema.ts | 4 +++- tests/spec/singleHttpClient/schema.ts | 4 +++- tests/spec/typeSuffixPrefix/schema.ts | 4 +++- tests/spec/unionEnums/schema.ts | 4 +++- 60 files changed, 176 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e50c6be..5bdddc0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ BREAKING_CHANGES: - remove default `json` format of the response type (both for `axios` and `fetch` http clients) Features: +- Allow passing custom fetch function (`fetch` http client only) - Allow to set global response type format through `HttpClient` constructor Example: ```ts diff --git a/tests/generated/v2.0/adafruit.ts b/tests/generated/v2.0/adafruit.ts index 6637dbfa..b84d1568 100644 --- a/tests/generated/v2.0/adafruit.ts +++ b/tests/generated/v2.0/adafruit.ts @@ -192,6 +192,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -212,6 +213,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -323,7 +325,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/another-example.ts b/tests/generated/v2.0/another-example.ts index c2ecd8e5..c3077d76 100644 --- a/tests/generated/v2.0/another-example.ts +++ b/tests/generated/v2.0/another-example.ts @@ -168,6 +168,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -188,6 +189,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -299,7 +301,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/another-schema.ts b/tests/generated/v2.0/another-schema.ts index dde7244b..8e2357ac 100644 --- a/tests/generated/v2.0/another-schema.ts +++ b/tests/generated/v2.0/another-schema.ts @@ -60,6 +60,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -80,6 +81,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -191,7 +193,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/api-with-examples.ts b/tests/generated/v2.0/api-with-examples.ts index b6526875..0c6767bd 100644 --- a/tests/generated/v2.0/api-with-examples.ts +++ b/tests/generated/v2.0/api-with-examples.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/authentiq.ts b/tests/generated/v2.0/authentiq.ts index 7ceaf4dd..2a6652d0 100644 --- a/tests/generated/v2.0/authentiq.ts +++ b/tests/generated/v2.0/authentiq.ts @@ -89,6 +89,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -109,6 +110,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -220,7 +222,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/enums.ts b/tests/generated/v2.0/enums.ts index 80d82f0d..59f4635d 100644 --- a/tests/generated/v2.0/enums.ts +++ b/tests/generated/v2.0/enums.ts @@ -102,6 +102,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -122,6 +123,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -233,7 +235,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/example1.ts b/tests/generated/v2.0/example1.ts index f9b97962..c03fa34c 100644 --- a/tests/generated/v2.0/example1.ts +++ b/tests/generated/v2.0/example1.ts @@ -64,6 +64,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -84,6 +85,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -195,7 +197,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/file-formdata-example.ts b/tests/generated/v2.0/file-formdata-example.ts index 39f4028d..2b2e9d65 100644 --- a/tests/generated/v2.0/file-formdata-example.ts +++ b/tests/generated/v2.0/file-formdata-example.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/furkot-example.ts b/tests/generated/v2.0/furkot-example.ts index cb481ce7..ae8e71c7 100644 --- a/tests/generated/v2.0/furkot-example.ts +++ b/tests/generated/v2.0/furkot-example.ts @@ -100,6 +100,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -120,6 +121,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -231,7 +233,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/giphy.ts b/tests/generated/v2.0/giphy.ts index af47fd42..db6803c7 100644 --- a/tests/generated/v2.0/giphy.ts +++ b/tests/generated/v2.0/giphy.ts @@ -319,6 +319,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -339,6 +340,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -450,7 +452,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/github-swagger.ts b/tests/generated/v2.0/github-swagger.ts index cb649cdf..f3e83e51 100644 --- a/tests/generated/v2.0/github-swagger.ts +++ b/tests/generated/v2.0/github-swagger.ts @@ -1472,6 +1472,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -1492,6 +1493,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -1603,7 +1605,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/path-args.ts b/tests/generated/v2.0/path-args.ts index dcc4ea6c..f8969630 100644 --- a/tests/generated/v2.0/path-args.ts +++ b/tests/generated/v2.0/path-args.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/petstore-expanded.ts b/tests/generated/v2.0/petstore-expanded.ts index 7c812ad2..4069bece 100644 --- a/tests/generated/v2.0/petstore-expanded.ts +++ b/tests/generated/v2.0/petstore-expanded.ts @@ -74,6 +74,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -94,6 +95,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -205,7 +207,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/petstore-minimal.ts b/tests/generated/v2.0/petstore-minimal.ts index e4833c9e..646e6786 100644 --- a/tests/generated/v2.0/petstore-minimal.ts +++ b/tests/generated/v2.0/petstore-minimal.ts @@ -45,6 +45,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -65,6 +66,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -176,7 +178,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/petstore-simple.ts b/tests/generated/v2.0/petstore-simple.ts index e1c62580..901f8b5e 100644 --- a/tests/generated/v2.0/petstore-simple.ts +++ b/tests/generated/v2.0/petstore-simple.ts @@ -60,6 +60,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -80,6 +81,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -191,7 +193,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/petstore-swagger-io.ts b/tests/generated/v2.0/petstore-swagger-io.ts index 77729a98..9c0d3670 100644 --- a/tests/generated/v2.0/petstore-swagger-io.ts +++ b/tests/generated/v2.0/petstore-swagger-io.ts @@ -105,6 +105,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -125,6 +126,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -236,7 +238,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/petstore-with-external-docs.ts b/tests/generated/v2.0/petstore-with-external-docs.ts index e144eca4..d6cbea92 100644 --- a/tests/generated/v2.0/petstore-with-external-docs.ts +++ b/tests/generated/v2.0/petstore-with-external-docs.ts @@ -50,6 +50,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -70,6 +71,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -181,7 +183,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/petstore.ts b/tests/generated/v2.0/petstore.ts index cc9b15e7..3069cd5c 100644 --- a/tests/generated/v2.0/petstore.ts +++ b/tests/generated/v2.0/petstore.ts @@ -52,6 +52,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -72,6 +73,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -183,7 +185,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/query-path-param.ts b/tests/generated/v2.0/query-path-param.ts index c18fa6cd..76f51a9b 100644 --- a/tests/generated/v2.0/query-path-param.ts +++ b/tests/generated/v2.0/query-path-param.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v2.0/uber.ts b/tests/generated/v2.0/uber.ts index fc094849..3459eac7 100644 --- a/tests/generated/v2.0/uber.ts +++ b/tests/generated/v2.0/uber.ts @@ -132,6 +132,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -152,6 +153,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -263,7 +265,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/additional-properties.ts b/tests/generated/v3.0/additional-properties.ts index 6460803e..257ed613 100644 --- a/tests/generated/v3.0/additional-properties.ts +++ b/tests/generated/v3.0/additional-properties.ts @@ -44,6 +44,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -64,6 +65,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -175,7 +177,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/additional-properties2.ts b/tests/generated/v3.0/additional-properties2.ts index 93964261..5845d189 100644 --- a/tests/generated/v3.0/additional-properties2.ts +++ b/tests/generated/v3.0/additional-properties2.ts @@ -41,6 +41,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -61,6 +62,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -172,7 +174,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/allof-example.ts b/tests/generated/v3.0/allof-example.ts index 1b4e43f7..13a39986 100644 --- a/tests/generated/v3.0/allof-example.ts +++ b/tests/generated/v3.0/allof-example.ts @@ -45,6 +45,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -65,6 +66,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -176,7 +178,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/anyof-example.ts b/tests/generated/v3.0/anyof-example.ts index 6a36362a..b7a8b864 100644 --- a/tests/generated/v3.0/anyof-example.ts +++ b/tests/generated/v3.0/anyof-example.ts @@ -47,6 +47,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -67,6 +68,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -178,7 +180,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/api-with-examples.ts b/tests/generated/v3.0/api-with-examples.ts index 29e0e7c2..69be2c4a 100644 --- a/tests/generated/v3.0/api-with-examples.ts +++ b/tests/generated/v3.0/api-with-examples.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/callback-example.ts b/tests/generated/v3.0/callback-example.ts index fdae63d8..ef6c5b28 100644 --- a/tests/generated/v3.0/callback-example.ts +++ b/tests/generated/v3.0/callback-example.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/components-responses.ts b/tests/generated/v3.0/components-responses.ts index 3188e2e7..100e9177 100644 --- a/tests/generated/v3.0/components-responses.ts +++ b/tests/generated/v3.0/components-responses.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/explode-param-3.0.1.ts b/tests/generated/v3.0/explode-param-3.0.1.ts index b1dff77d..665720dd 100644 --- a/tests/generated/v3.0/explode-param-3.0.1.ts +++ b/tests/generated/v3.0/explode-param-3.0.1.ts @@ -57,6 +57,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -77,6 +78,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -188,7 +190,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/full-swagger-scheme.ts b/tests/generated/v3.0/full-swagger-scheme.ts index 50df13d6..1bbc9903 100644 --- a/tests/generated/v3.0/full-swagger-scheme.ts +++ b/tests/generated/v3.0/full-swagger-scheme.ts @@ -8981,6 +8981,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -9001,6 +9002,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -9112,7 +9114,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/link-example.ts b/tests/generated/v3.0/link-example.ts index 65ebac12..ce84c3db 100644 --- a/tests/generated/v3.0/link-example.ts +++ b/tests/generated/v3.0/link-example.ts @@ -54,6 +54,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -74,6 +75,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -185,7 +187,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/no-definitions-schema.ts b/tests/generated/v3.0/no-definitions-schema.ts index a4065bda..d1f03c34 100644 --- a/tests/generated/v3.0/no-definitions-schema.ts +++ b/tests/generated/v3.0/no-definitions-schema.ts @@ -50,6 +50,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -70,6 +71,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -181,7 +183,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/nullable-refs.ts b/tests/generated/v3.0/nullable-refs.ts index b3f70268..d0eaf682 100644 --- a/tests/generated/v3.0/nullable-refs.ts +++ b/tests/generated/v3.0/nullable-refs.ts @@ -51,6 +51,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -71,6 +72,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -182,7 +184,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/oneof-example.ts b/tests/generated/v3.0/oneof-example.ts index 0f2bc91c..a70929ee 100644 --- a/tests/generated/v3.0/oneof-example.ts +++ b/tests/generated/v3.0/oneof-example.ts @@ -47,6 +47,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -67,6 +68,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -178,7 +180,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/personal-api-example.ts b/tests/generated/v3.0/personal-api-example.ts index c16284dd..c4b03673 100644 --- a/tests/generated/v3.0/personal-api-example.ts +++ b/tests/generated/v3.0/personal-api-example.ts @@ -238,6 +238,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -258,6 +259,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -369,7 +371,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/petstore-expanded.ts b/tests/generated/v3.0/petstore-expanded.ts index a740bfb7..20b42ffd 100644 --- a/tests/generated/v3.0/petstore-expanded.ts +++ b/tests/generated/v3.0/petstore-expanded.ts @@ -50,6 +50,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -70,6 +71,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -181,7 +183,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/petstore.ts b/tests/generated/v3.0/petstore.ts index 97544bd8..db464b4b 100644 --- a/tests/generated/v3.0/petstore.ts +++ b/tests/generated/v3.0/petstore.ts @@ -54,6 +54,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -74,6 +75,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -185,7 +187,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/recursive-schema.ts b/tests/generated/v3.0/recursive-schema.ts index dce6b380..32de4fd8 100644 --- a/tests/generated/v3.0/recursive-schema.ts +++ b/tests/generated/v3.0/recursive-schema.ts @@ -51,6 +51,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -71,6 +72,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -182,7 +184,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/responses.ts b/tests/generated/v3.0/responses.ts index cbc1d267..97941210 100644 --- a/tests/generated/v3.0/responses.ts +++ b/tests/generated/v3.0/responses.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/swaggerhub-template.ts b/tests/generated/v3.0/swaggerhub-template.ts index 1612a36a..94b82e26 100644 --- a/tests/generated/v3.0/swaggerhub-template.ts +++ b/tests/generated/v3.0/swaggerhub-template.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts index 96993846..59a6c8c7 100644 --- a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts +++ b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts @@ -158,6 +158,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -178,6 +179,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -289,7 +291,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/up-banking.ts b/tests/generated/v3.0/up-banking.ts index f17f7a0c..8582b794 100644 --- a/tests/generated/v3.0/up-banking.ts +++ b/tests/generated/v3.0/up-banking.ts @@ -575,6 +575,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -595,6 +596,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -706,7 +708,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/uspto.ts b/tests/generated/v3.0/uspto.ts index e6cd590b..56fac939 100644 --- a/tests/generated/v3.0/uspto.ts +++ b/tests/generated/v3.0/uspto.ts @@ -54,6 +54,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -74,6 +75,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -185,7 +187,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/wrong-enum-subtypes.ts b/tests/generated/v3.0/wrong-enum-subtypes.ts index 54ec0d72..3be6391e 100644 --- a/tests/generated/v3.0/wrong-enum-subtypes.ts +++ b/tests/generated/v3.0/wrong-enum-subtypes.ts @@ -39,6 +39,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -59,6 +60,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -170,7 +172,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/generated/v3.0/wrong-schema-names.ts b/tests/generated/v3.0/wrong-schema-names.ts index fcc72fda..a3fb9f65 100644 --- a/tests/generated/v3.0/wrong-schema-names.ts +++ b/tests/generated/v3.0/wrong-schema-names.ts @@ -61,6 +61,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -81,6 +82,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -192,7 +194,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/defaultAsSuccess/schema.ts b/tests/spec/defaultAsSuccess/schema.ts index d2e27d77..a2ac550d 100644 --- a/tests/spec/defaultAsSuccess/schema.ts +++ b/tests/spec/defaultAsSuccess/schema.ts @@ -89,6 +89,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -109,6 +110,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -220,7 +222,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/defaultResponse/schema.ts b/tests/spec/defaultResponse/schema.ts index b734e421..5a1bf336 100644 --- a/tests/spec/defaultResponse/schema.ts +++ b/tests/spec/defaultResponse/schema.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/enumNamesAsValues/schema.ts b/tests/spec/enumNamesAsValues/schema.ts index b4cc57ce..e90d8139 100644 --- a/tests/spec/enumNamesAsValues/schema.ts +++ b/tests/spec/enumNamesAsValues/schema.ts @@ -235,6 +235,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -255,6 +256,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -366,7 +368,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/extractRequestParams/schema.ts b/tests/spec/extractRequestParams/schema.ts index 03d220fc..c14ec5ea 100644 --- a/tests/spec/extractRequestParams/schema.ts +++ b/tests/spec/extractRequestParams/schema.ts @@ -129,6 +129,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -149,6 +150,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -260,7 +262,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/js/schema.d.ts b/tests/spec/js/schema.d.ts index 207daa47..c2ed2d19 100644 --- a/tests/spec/js/schema.d.ts +++ b/tests/spec/js/schema.d.ts @@ -1727,6 +1727,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { data: D; @@ -1743,6 +1744,7 @@ export declare class HttpClient { private securityData; private securityWorker?; private abortControllers; + private customFetch; private baseApiParams; constructor(apiConfig?: ApiConfig); setSecurityData: (data: SecurityDataType | null) => void; diff --git a/tests/spec/js/schema.js b/tests/spec/js/schema.js index 5b0104c4..c5c2959b 100644 --- a/tests/spec/js/schema.js +++ b/tests/spec/js/schema.js @@ -20,6 +20,7 @@ export class HttpClient { this.baseUrl = "https://api.github.com"; this.securityData = null; this.abortControllers = new Map(); + this.customFetch = fetch; this.baseApiParams = { credentials: "same-origin", headers: {}, @@ -68,7 +69,7 @@ export class HttpClient { const queryString = query && this.toQueryString(query); const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/modular/http-client.ts b/tests/spec/modular/http-client.ts index 6ef50c38..af2adf05 100644 --- a/tests/spec/modular/http-client.ts +++ b/tests/spec/modular/http-client.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/moduleNameFirstTag/schema.ts b/tests/spec/moduleNameFirstTag/schema.ts index 0ce5859c..92029309 100644 --- a/tests/spec/moduleNameFirstTag/schema.ts +++ b/tests/spec/moduleNameFirstTag/schema.ts @@ -165,6 +165,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -185,6 +186,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -296,7 +298,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/moduleNameIndex/schema.ts b/tests/spec/moduleNameIndex/schema.ts index 62afac40..69057230 100644 --- a/tests/spec/moduleNameIndex/schema.ts +++ b/tests/spec/moduleNameIndex/schema.ts @@ -165,6 +165,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -185,6 +186,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -296,7 +298,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/partialBaseTemplate/schema.ts b/tests/spec/partialBaseTemplate/schema.ts index edc5620c..9bd39e86 100644 --- a/tests/spec/partialBaseTemplate/schema.ts +++ b/tests/spec/partialBaseTemplate/schema.ts @@ -49,6 +49,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -69,6 +70,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -180,7 +182,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/partialDefaultTemplate/schema.ts b/tests/spec/partialDefaultTemplate/schema.ts index 1ba7a3e8..8e44d21d 100644 --- a/tests/spec/partialDefaultTemplate/schema.ts +++ b/tests/spec/partialDefaultTemplate/schema.ts @@ -45,6 +45,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -65,6 +66,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -176,7 +178,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/responses/schema.ts b/tests/spec/responses/schema.ts index 8f462d0f..e7e65740 100644 --- a/tests/spec/responses/schema.ts +++ b/tests/spec/responses/schema.ts @@ -89,6 +89,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -109,6 +110,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -220,7 +222,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/singleHttpClient/schema.ts b/tests/spec/singleHttpClient/schema.ts index 58a07cdf..945dcd45 100644 --- a/tests/spec/singleHttpClient/schema.ts +++ b/tests/spec/singleHttpClient/schema.ts @@ -37,6 +37,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -57,6 +58,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -168,7 +170,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/typeSuffixPrefix/schema.ts b/tests/spec/typeSuffixPrefix/schema.ts index 0f516c6e..0be981c2 100644 --- a/tests/spec/typeSuffixPrefix/schema.ts +++ b/tests/spec/typeSuffixPrefix/schema.ts @@ -1482,6 +1482,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -1502,6 +1503,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -1613,7 +1615,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), diff --git a/tests/spec/unionEnums/schema.ts b/tests/spec/unionEnums/schema.ts index 9f611759..835621b7 100644 --- a/tests/spec/unionEnums/schema.ts +++ b/tests/spec/unionEnums/schema.ts @@ -49,6 +49,7 @@ export interface ApiConfig { baseUrl?: string; baseApiParams?: Omit; securityWorker?: (securityData: SecurityDataType | null) => Promise | RequestParams | void; + customFetch?: (input: RequestInfo, init?: RequestInit) => Promise; } export interface HttpResponse extends Response { @@ -69,6 +70,7 @@ export class HttpClient { private securityData: SecurityDataType | null = null; private securityWorker?: ApiConfig["securityWorker"]; private abortControllers = new Map(); + private customFetch = fetch; private baseApiParams: RequestParams = { credentials: "same-origin", @@ -180,7 +182,7 @@ export class HttpClient { const payloadFormatter = this.contentFormatters[type || ContentType.Json]; const responseFormat = format && requestParams.format; - return fetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { + return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { ...requestParams, headers: { ...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), From 6ae8d417f7e5ce58c9ad6a033a49a5157e86f6d5 Mon Sep 17 00:00:00 2001 From: Stijn Lammens Date: Mon, 5 Apr 2021 00:09:35 +0200 Subject: [PATCH 15/19] Fix: query param array serialization (#223) * make the query params serialization conform to the default open api specs * uri encode second part Co-authored-by: stijn.lammens --- templates/base/http-clients/fetch-http-client.eta | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/templates/base/http-clients/fetch-http-client.eta b/templates/base/http-clients/fetch-http-client.eta index e7d898b1..b7bcf5c2 100644 --- a/templates/base/http-clients/fetch-http-client.eta +++ b/templates/base/http-clients/fetch-http-client.eta @@ -69,16 +69,10 @@ export class HttpClient { this.securityData = data; } - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + "=" + encodeURIComponent( - Array.isArray(value) ? value.join(",") : - typeof value === "number" ? value : - `${value}` - ) - ); + const encodedKey = encodeURIComponent(key); + return `${value.map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`).join('&')}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -88,7 +82,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } From fba9e811c9b8a2fc4749eb86f8e9ae754a51614f Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 5 Apr 2021 01:10:36 +0300 Subject: [PATCH 16/19] docs: update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bdddc0c..6c51b293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Features: ``` Fixes: - Missing `schema.$ref` in inline enum schemas +- Array query param values are serialized with the (non-default) comma separated style (issue #222, thanks @Styn, PR #223) # 7.0.1 From 16caeb6e080f6b65af87cb6f8c6416e30634322a Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 5 Apr 2021 01:19:46 +0300 Subject: [PATCH 17/19] fix: unused E generic type --- CHANGELOG.md | 3 ++- templates/base/http-clients/axios-http-client.eta | 2 +- tests/spec/axios/schema.ts | 2 +- tests/spec/axiosSingleHttpClient/schema.ts | 2 +- tests/spec/jsAxios/schema.d.ts | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c51b293..fde3be9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # next release BREAKING_CHANGES: -- remove default `json` format of the response type (both for `axios` and `fetch` http clients) +- remove default `json` format of the response type (both for `axios` and `fetch` http clients) (issue #213, thanks @po5i) Features: - Allow passing custom fetch function (`fetch` http client only) @@ -14,6 +14,7 @@ Features: Fixes: - Missing `schema.$ref` in inline enum schemas - Array query param values are serialized with the (non-default) comma separated style (issue #222, thanks @Styn, PR #223) +- TypeScript error "TS6133: 'E' is declared but its value is never read." (`axios` http client) (issue #220, thanks @pmbednarczyk ) # 7.0.1 diff --git a/templates/base/http-clients/axios-http-client.eta b/templates/base/http-clients/axios-http-client.eta index 920cc6b4..4958b0b1 100644 --- a/templates/base/http-clients/axios-http-client.eta +++ b/templates/base/http-clients/axios-http-client.eta @@ -66,7 +66,7 @@ export class HttpClient { }; } - public request = async ({ + public request = async ({ secure, path, type, diff --git a/tests/spec/axios/schema.ts b/tests/spec/axios/schema.ts index d8f76a0f..9d124903 100644 --- a/tests/spec/axios/schema.ts +++ b/tests/spec/axios/schema.ts @@ -1510,7 +1510,7 @@ export class HttpClient { }; } - public request = async ({ + public request = async ({ secure, path, type, diff --git a/tests/spec/axiosSingleHttpClient/schema.ts b/tests/spec/axiosSingleHttpClient/schema.ts index 9c43d8a7..d3dfc2b8 100644 --- a/tests/spec/axiosSingleHttpClient/schema.ts +++ b/tests/spec/axiosSingleHttpClient/schema.ts @@ -1510,7 +1510,7 @@ export class HttpClient { }; } - public request = async ({ + public request = async ({ secure, path, type, diff --git a/tests/spec/jsAxios/schema.d.ts b/tests/spec/jsAxios/schema.d.ts index 2243a288..8dd6346f 100644 --- a/tests/spec/jsAxios/schema.d.ts +++ b/tests/spec/jsAxios/schema.d.ts @@ -1740,7 +1740,7 @@ export declare class HttpClient { constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig); setSecurityData: (data: SecurityDataType | null) => void; private mergeRequestParams; - request: ({ + request: ({ secure, path, type, From 099f22bd181229d2c67a060366fe82eb8410b2bb Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 5 Apr 2021 01:24:31 +0300 Subject: [PATCH 18/19] chore: refresh generated test schemas --- tests/generated/v2.0/adafruit.ts | 14 ++++++-------- tests/generated/v2.0/another-example.ts | 14 ++++++-------- tests/generated/v2.0/another-schema.ts | 14 ++++++-------- tests/generated/v2.0/api-with-examples.ts | 14 ++++++-------- tests/generated/v2.0/authentiq.ts | 14 ++++++-------- tests/generated/v2.0/enums.ts | 14 ++++++-------- tests/generated/v2.0/example1.ts | 14 ++++++-------- tests/generated/v2.0/file-formdata-example.ts | 14 ++++++-------- tests/generated/v2.0/furkot-example.ts | 14 ++++++-------- tests/generated/v2.0/giphy.ts | 14 ++++++-------- tests/generated/v2.0/github-swagger.ts | 14 ++++++-------- tests/generated/v2.0/path-args.ts | 14 ++++++-------- tests/generated/v2.0/petstore-expanded.ts | 14 ++++++-------- tests/generated/v2.0/petstore-minimal.ts | 14 ++++++-------- tests/generated/v2.0/petstore-simple.ts | 14 ++++++-------- tests/generated/v2.0/petstore-swagger-io.ts | 14 ++++++-------- .../generated/v2.0/petstore-with-external-docs.ts | 14 ++++++-------- tests/generated/v2.0/petstore.ts | 14 ++++++-------- tests/generated/v2.0/query-path-param.ts | 14 ++++++-------- tests/generated/v2.0/uber.ts | 14 ++++++-------- tests/generated/v3.0/additional-properties.ts | 14 ++++++-------- tests/generated/v3.0/additional-properties2.ts | 14 ++++++-------- tests/generated/v3.0/allof-example.ts | 14 ++++++-------- tests/generated/v3.0/anyof-example.ts | 14 ++++++-------- tests/generated/v3.0/api-with-examples.ts | 14 ++++++-------- tests/generated/v3.0/callback-example.ts | 14 ++++++-------- tests/generated/v3.0/components-responses.ts | 14 ++++++-------- tests/generated/v3.0/explode-param-3.0.1.ts | 14 ++++++-------- tests/generated/v3.0/full-swagger-scheme.ts | 14 ++++++-------- tests/generated/v3.0/link-example.ts | 14 ++++++-------- tests/generated/v3.0/no-definitions-schema.ts | 14 ++++++-------- tests/generated/v3.0/nullable-refs.ts | 14 ++++++-------- tests/generated/v3.0/oneof-example.ts | 14 ++++++-------- tests/generated/v3.0/personal-api-example.ts | 14 ++++++-------- tests/generated/v3.0/petstore-expanded.ts | 14 ++++++-------- tests/generated/v3.0/petstore.ts | 14 ++++++-------- tests/generated/v3.0/recursive-schema.ts | 14 ++++++-------- tests/generated/v3.0/responses.ts | 14 ++++++-------- tests/generated/v3.0/swaggerhub-template.ts | 14 ++++++-------- tests/generated/v3.0/tsoa-odd-types-3.0.2.ts | 14 ++++++-------- tests/generated/v3.0/up-banking.ts | 14 ++++++-------- tests/generated/v3.0/uspto.ts | 14 ++++++-------- tests/generated/v3.0/wrong-enum-subtypes.ts | 14 ++++++-------- tests/generated/v3.0/wrong-schema-names.ts | 14 ++++++-------- tests/spec/defaultAsSuccess/schema.ts | 14 ++++++-------- tests/spec/defaultResponse/schema.ts | 14 ++++++-------- tests/spec/enumNamesAsValues/schema.ts | 14 ++++++-------- tests/spec/extractRequestParams/schema.ts | 14 ++++++-------- tests/spec/js/schema.d.ts | 2 +- tests/spec/js/schema.js | 13 ++++++------- tests/spec/modular/http-client.ts | 14 ++++++-------- tests/spec/moduleNameFirstTag/schema.ts | 14 ++++++-------- tests/spec/moduleNameIndex/schema.ts | 14 ++++++-------- tests/spec/partialBaseTemplate/schema.ts | 14 ++++++-------- tests/spec/partialDefaultTemplate/schema.ts | 14 ++++++-------- tests/spec/responses/schema.ts | 14 ++++++-------- tests/spec/singleHttpClient/schema.ts | 14 ++++++-------- tests/spec/typeSuffixPrefix/schema.ts | 14 ++++++-------- tests/spec/unionEnums/schema.ts | 14 ++++++-------- 59 files changed, 349 insertions(+), 464 deletions(-) diff --git a/tests/generated/v2.0/adafruit.ts b/tests/generated/v2.0/adafruit.ts index b84d1568..d1a05171 100644 --- a/tests/generated/v2.0/adafruit.ts +++ b/tests/generated/v2.0/adafruit.ts @@ -230,14 +230,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -247,7 +245,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/another-example.ts b/tests/generated/v2.0/another-example.ts index c3077d76..05e5bbd3 100644 --- a/tests/generated/v2.0/another-example.ts +++ b/tests/generated/v2.0/another-example.ts @@ -206,14 +206,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -223,7 +221,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/another-schema.ts b/tests/generated/v2.0/another-schema.ts index 8e2357ac..b3fdbbdc 100644 --- a/tests/generated/v2.0/another-schema.ts +++ b/tests/generated/v2.0/another-schema.ts @@ -98,14 +98,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -115,7 +113,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/api-with-examples.ts b/tests/generated/v2.0/api-with-examples.ts index 0c6767bd..55cf244c 100644 --- a/tests/generated/v2.0/api-with-examples.ts +++ b/tests/generated/v2.0/api-with-examples.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/authentiq.ts b/tests/generated/v2.0/authentiq.ts index 2a6652d0..e5512bc3 100644 --- a/tests/generated/v2.0/authentiq.ts +++ b/tests/generated/v2.0/authentiq.ts @@ -127,14 +127,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -144,7 +142,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/enums.ts b/tests/generated/v2.0/enums.ts index 59f4635d..2c882efe 100644 --- a/tests/generated/v2.0/enums.ts +++ b/tests/generated/v2.0/enums.ts @@ -140,14 +140,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -157,7 +155,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/example1.ts b/tests/generated/v2.0/example1.ts index c03fa34c..00b4f427 100644 --- a/tests/generated/v2.0/example1.ts +++ b/tests/generated/v2.0/example1.ts @@ -102,14 +102,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -119,7 +117,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/file-formdata-example.ts b/tests/generated/v2.0/file-formdata-example.ts index 2b2e9d65..fc6c0e78 100644 --- a/tests/generated/v2.0/file-formdata-example.ts +++ b/tests/generated/v2.0/file-formdata-example.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/furkot-example.ts b/tests/generated/v2.0/furkot-example.ts index ae8e71c7..6ae341d7 100644 --- a/tests/generated/v2.0/furkot-example.ts +++ b/tests/generated/v2.0/furkot-example.ts @@ -138,14 +138,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -155,7 +153,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/giphy.ts b/tests/generated/v2.0/giphy.ts index db6803c7..4e51559c 100644 --- a/tests/generated/v2.0/giphy.ts +++ b/tests/generated/v2.0/giphy.ts @@ -357,14 +357,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -374,7 +372,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/github-swagger.ts b/tests/generated/v2.0/github-swagger.ts index f3e83e51..e5fa0292 100644 --- a/tests/generated/v2.0/github-swagger.ts +++ b/tests/generated/v2.0/github-swagger.ts @@ -1510,14 +1510,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -1527,7 +1525,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/path-args.ts b/tests/generated/v2.0/path-args.ts index f8969630..17de507d 100644 --- a/tests/generated/v2.0/path-args.ts +++ b/tests/generated/v2.0/path-args.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/petstore-expanded.ts b/tests/generated/v2.0/petstore-expanded.ts index 4069bece..9564fcb1 100644 --- a/tests/generated/v2.0/petstore-expanded.ts +++ b/tests/generated/v2.0/petstore-expanded.ts @@ -112,14 +112,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -129,7 +127,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/petstore-minimal.ts b/tests/generated/v2.0/petstore-minimal.ts index 646e6786..ab712307 100644 --- a/tests/generated/v2.0/petstore-minimal.ts +++ b/tests/generated/v2.0/petstore-minimal.ts @@ -83,14 +83,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -100,7 +98,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/petstore-simple.ts b/tests/generated/v2.0/petstore-simple.ts index 901f8b5e..1a529ea2 100644 --- a/tests/generated/v2.0/petstore-simple.ts +++ b/tests/generated/v2.0/petstore-simple.ts @@ -98,14 +98,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -115,7 +113,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/petstore-swagger-io.ts b/tests/generated/v2.0/petstore-swagger-io.ts index 9c0d3670..2eac9a00 100644 --- a/tests/generated/v2.0/petstore-swagger-io.ts +++ b/tests/generated/v2.0/petstore-swagger-io.ts @@ -143,14 +143,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -160,7 +158,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/petstore-with-external-docs.ts b/tests/generated/v2.0/petstore-with-external-docs.ts index d6cbea92..8997920e 100644 --- a/tests/generated/v2.0/petstore-with-external-docs.ts +++ b/tests/generated/v2.0/petstore-with-external-docs.ts @@ -88,14 +88,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -105,7 +103,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/petstore.ts b/tests/generated/v2.0/petstore.ts index 3069cd5c..5cabb1e9 100644 --- a/tests/generated/v2.0/petstore.ts +++ b/tests/generated/v2.0/petstore.ts @@ -90,14 +90,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -107,7 +105,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/query-path-param.ts b/tests/generated/v2.0/query-path-param.ts index 76f51a9b..c90add11 100644 --- a/tests/generated/v2.0/query-path-param.ts +++ b/tests/generated/v2.0/query-path-param.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v2.0/uber.ts b/tests/generated/v2.0/uber.ts index 3459eac7..97ef8720 100644 --- a/tests/generated/v2.0/uber.ts +++ b/tests/generated/v2.0/uber.ts @@ -170,14 +170,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -187,7 +185,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/additional-properties.ts b/tests/generated/v3.0/additional-properties.ts index 257ed613..6dab8d21 100644 --- a/tests/generated/v3.0/additional-properties.ts +++ b/tests/generated/v3.0/additional-properties.ts @@ -82,14 +82,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -99,7 +97,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/additional-properties2.ts b/tests/generated/v3.0/additional-properties2.ts index 5845d189..35b11561 100644 --- a/tests/generated/v3.0/additional-properties2.ts +++ b/tests/generated/v3.0/additional-properties2.ts @@ -79,14 +79,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -96,7 +94,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/allof-example.ts b/tests/generated/v3.0/allof-example.ts index 13a39986..806224bb 100644 --- a/tests/generated/v3.0/allof-example.ts +++ b/tests/generated/v3.0/allof-example.ts @@ -83,14 +83,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -100,7 +98,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/anyof-example.ts b/tests/generated/v3.0/anyof-example.ts index b7a8b864..b28443fb 100644 --- a/tests/generated/v3.0/anyof-example.ts +++ b/tests/generated/v3.0/anyof-example.ts @@ -85,14 +85,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -102,7 +100,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/api-with-examples.ts b/tests/generated/v3.0/api-with-examples.ts index 69be2c4a..803cecff 100644 --- a/tests/generated/v3.0/api-with-examples.ts +++ b/tests/generated/v3.0/api-with-examples.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/callback-example.ts b/tests/generated/v3.0/callback-example.ts index ef6c5b28..0b2dbc46 100644 --- a/tests/generated/v3.0/callback-example.ts +++ b/tests/generated/v3.0/callback-example.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/components-responses.ts b/tests/generated/v3.0/components-responses.ts index 100e9177..19cb9986 100644 --- a/tests/generated/v3.0/components-responses.ts +++ b/tests/generated/v3.0/components-responses.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/explode-param-3.0.1.ts b/tests/generated/v3.0/explode-param-3.0.1.ts index 665720dd..468ae1a0 100644 --- a/tests/generated/v3.0/explode-param-3.0.1.ts +++ b/tests/generated/v3.0/explode-param-3.0.1.ts @@ -95,14 +95,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -112,7 +110,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/full-swagger-scheme.ts b/tests/generated/v3.0/full-swagger-scheme.ts index 1bbc9903..bc16b2f2 100644 --- a/tests/generated/v3.0/full-swagger-scheme.ts +++ b/tests/generated/v3.0/full-swagger-scheme.ts @@ -9019,14 +9019,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -9036,7 +9034,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/link-example.ts b/tests/generated/v3.0/link-example.ts index ce84c3db..0010ac2a 100644 --- a/tests/generated/v3.0/link-example.ts +++ b/tests/generated/v3.0/link-example.ts @@ -92,14 +92,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -109,7 +107,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/no-definitions-schema.ts b/tests/generated/v3.0/no-definitions-schema.ts index d1f03c34..5bfef145 100644 --- a/tests/generated/v3.0/no-definitions-schema.ts +++ b/tests/generated/v3.0/no-definitions-schema.ts @@ -88,14 +88,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -105,7 +103,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/nullable-refs.ts b/tests/generated/v3.0/nullable-refs.ts index d0eaf682..af503cd9 100644 --- a/tests/generated/v3.0/nullable-refs.ts +++ b/tests/generated/v3.0/nullable-refs.ts @@ -89,14 +89,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -106,7 +104,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/oneof-example.ts b/tests/generated/v3.0/oneof-example.ts index a70929ee..404c3251 100644 --- a/tests/generated/v3.0/oneof-example.ts +++ b/tests/generated/v3.0/oneof-example.ts @@ -85,14 +85,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -102,7 +100,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/personal-api-example.ts b/tests/generated/v3.0/personal-api-example.ts index c4b03673..395d7f0c 100644 --- a/tests/generated/v3.0/personal-api-example.ts +++ b/tests/generated/v3.0/personal-api-example.ts @@ -276,14 +276,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -293,7 +291,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/petstore-expanded.ts b/tests/generated/v3.0/petstore-expanded.ts index 20b42ffd..ba61ee3b 100644 --- a/tests/generated/v3.0/petstore-expanded.ts +++ b/tests/generated/v3.0/petstore-expanded.ts @@ -88,14 +88,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -105,7 +103,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/petstore.ts b/tests/generated/v3.0/petstore.ts index db464b4b..b7ef4ddb 100644 --- a/tests/generated/v3.0/petstore.ts +++ b/tests/generated/v3.0/petstore.ts @@ -92,14 +92,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -109,7 +107,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/recursive-schema.ts b/tests/generated/v3.0/recursive-schema.ts index 32de4fd8..9d5a6cf5 100644 --- a/tests/generated/v3.0/recursive-schema.ts +++ b/tests/generated/v3.0/recursive-schema.ts @@ -89,14 +89,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -106,7 +104,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/responses.ts b/tests/generated/v3.0/responses.ts index 97941210..97611894 100644 --- a/tests/generated/v3.0/responses.ts +++ b/tests/generated/v3.0/responses.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/swaggerhub-template.ts b/tests/generated/v3.0/swaggerhub-template.ts index 94b82e26..033a48a0 100644 --- a/tests/generated/v3.0/swaggerhub-template.ts +++ b/tests/generated/v3.0/swaggerhub-template.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts index 59a6c8c7..b0268624 100644 --- a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts +++ b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts @@ -196,14 +196,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -213,7 +211,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/up-banking.ts b/tests/generated/v3.0/up-banking.ts index 8582b794..b6e8417d 100644 --- a/tests/generated/v3.0/up-banking.ts +++ b/tests/generated/v3.0/up-banking.ts @@ -613,14 +613,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -630,7 +628,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/uspto.ts b/tests/generated/v3.0/uspto.ts index 56fac939..243072f7 100644 --- a/tests/generated/v3.0/uspto.ts +++ b/tests/generated/v3.0/uspto.ts @@ -92,14 +92,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -109,7 +107,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/wrong-enum-subtypes.ts b/tests/generated/v3.0/wrong-enum-subtypes.ts index 3be6391e..f1a55537 100644 --- a/tests/generated/v3.0/wrong-enum-subtypes.ts +++ b/tests/generated/v3.0/wrong-enum-subtypes.ts @@ -77,14 +77,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -94,7 +92,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/generated/v3.0/wrong-schema-names.ts b/tests/generated/v3.0/wrong-schema-names.ts index a3fb9f65..30f58c9f 100644 --- a/tests/generated/v3.0/wrong-schema-names.ts +++ b/tests/generated/v3.0/wrong-schema-names.ts @@ -99,14 +99,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -116,7 +114,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/defaultAsSuccess/schema.ts b/tests/spec/defaultAsSuccess/schema.ts index a2ac550d..49f3737b 100644 --- a/tests/spec/defaultAsSuccess/schema.ts +++ b/tests/spec/defaultAsSuccess/schema.ts @@ -127,14 +127,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -144,7 +142,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/defaultResponse/schema.ts b/tests/spec/defaultResponse/schema.ts index 5a1bf336..64463587 100644 --- a/tests/spec/defaultResponse/schema.ts +++ b/tests/spec/defaultResponse/schema.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/enumNamesAsValues/schema.ts b/tests/spec/enumNamesAsValues/schema.ts index e90d8139..06f53e2d 100644 --- a/tests/spec/enumNamesAsValues/schema.ts +++ b/tests/spec/enumNamesAsValues/schema.ts @@ -273,14 +273,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -290,7 +288,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/extractRequestParams/schema.ts b/tests/spec/extractRequestParams/schema.ts index c14ec5ea..d3de6026 100644 --- a/tests/spec/extractRequestParams/schema.ts +++ b/tests/spec/extractRequestParams/schema.ts @@ -167,14 +167,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -184,7 +182,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/js/schema.d.ts b/tests/spec/js/schema.d.ts index c2ed2d19..c4030348 100644 --- a/tests/spec/js/schema.d.ts +++ b/tests/spec/js/schema.d.ts @@ -1748,7 +1748,7 @@ export declare class HttpClient { private baseApiParams; constructor(apiConfig?: ApiConfig); setSecurityData: (data: SecurityDataType | null) => void; - private addQueryParam; + private addArrayQueryParam; protected toQueryString(rawQuery?: QueryParamsType): string; protected addQueryParams(rawQuery?: QueryParamsType): string; private contentFormatters; diff --git a/tests/spec/js/schema.js b/tests/spec/js/schema.js index c5c2959b..156726b9 100644 --- a/tests/spec/js/schema.js +++ b/tests/spec/js/schema.js @@ -105,13 +105,12 @@ export class HttpClient { }; Object.assign(this, apiConfig); } - addQueryParam(query, key) { + addArrayQueryParam(query, key) { const value = query[key]; - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } toQueryString(rawQuery) { const query = rawQuery || {}; @@ -120,7 +119,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key]) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/modular/http-client.ts b/tests/spec/modular/http-client.ts index af2adf05..985d4401 100644 --- a/tests/spec/modular/http-client.ts +++ b/tests/spec/modular/http-client.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/moduleNameFirstTag/schema.ts b/tests/spec/moduleNameFirstTag/schema.ts index 92029309..ef250ad5 100644 --- a/tests/spec/moduleNameFirstTag/schema.ts +++ b/tests/spec/moduleNameFirstTag/schema.ts @@ -203,14 +203,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -220,7 +218,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/moduleNameIndex/schema.ts b/tests/spec/moduleNameIndex/schema.ts index 69057230..3f4ec33b 100644 --- a/tests/spec/moduleNameIndex/schema.ts +++ b/tests/spec/moduleNameIndex/schema.ts @@ -203,14 +203,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -220,7 +218,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/partialBaseTemplate/schema.ts b/tests/spec/partialBaseTemplate/schema.ts index 9bd39e86..381b89ae 100644 --- a/tests/spec/partialBaseTemplate/schema.ts +++ b/tests/spec/partialBaseTemplate/schema.ts @@ -87,14 +87,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -104,7 +102,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/partialDefaultTemplate/schema.ts b/tests/spec/partialDefaultTemplate/schema.ts index 8e44d21d..a78115ce 100644 --- a/tests/spec/partialDefaultTemplate/schema.ts +++ b/tests/spec/partialDefaultTemplate/schema.ts @@ -83,14 +83,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -100,7 +98,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/responses/schema.ts b/tests/spec/responses/schema.ts index e7e65740..d2d30a1c 100644 --- a/tests/spec/responses/schema.ts +++ b/tests/spec/responses/schema.ts @@ -127,14 +127,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -144,7 +142,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/singleHttpClient/schema.ts b/tests/spec/singleHttpClient/schema.ts index 945dcd45..033b0640 100644 --- a/tests/spec/singleHttpClient/schema.ts +++ b/tests/spec/singleHttpClient/schema.ts @@ -75,14 +75,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -92,7 +90,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/typeSuffixPrefix/schema.ts b/tests/spec/typeSuffixPrefix/schema.ts index 0be981c2..4a957753 100644 --- a/tests/spec/typeSuffixPrefix/schema.ts +++ b/tests/spec/typeSuffixPrefix/schema.ts @@ -1520,14 +1520,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -1537,7 +1535,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } diff --git a/tests/spec/unionEnums/schema.ts b/tests/spec/unionEnums/schema.ts index 835621b7..84a58df1 100644 --- a/tests/spec/unionEnums/schema.ts +++ b/tests/spec/unionEnums/schema.ts @@ -87,14 +87,12 @@ export class HttpClient { this.securityData = data; }; - private addQueryParam(query: QueryParamsType, key: string) { + private addArrayQueryParam(query: QueryParamsType, key: string) { const value = query[key]; - - return ( - encodeURIComponent(key) + - "=" + - encodeURIComponent(Array.isArray(value) ? value.join(",") : typeof value === "number" ? value : `${value}`) - ); + const encodedKey = encodeURIComponent(key); + return `${value + .map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`) + .join("&")}`; } protected toQueryString(rawQuery?: QueryParamsType): string { @@ -104,7 +102,7 @@ export class HttpClient { .map((key) => typeof query[key] === "object" && !Array.isArray(query[key]) ? this.toQueryString(query[key] as QueryParamsType) - : this.addQueryParam(query, key), + : this.addArrayQueryParam(query, key), ) .join("&"); } From 1581f55842d5ec73bc81a963d6395702f166ebc1 Mon Sep 17 00:00:00 2001 From: svolkov Date: Mon, 5 Apr 2021 01:25:40 +0300 Subject: [PATCH 19/19] bump: up version to 8.0.0 --- CHANGELOG.md | 2 ++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fde3be9c..9d13e1f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # next release +# 8.0.0 + BREAKING_CHANGES: - remove default `json` format of the response type (both for `axios` and `fetch` http clients) (issue #213, thanks @po5i) diff --git a/package-lock.json b/package-lock.json index d2aba6b8..890ac917 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "swagger-typescript-api", - "version": "7.0.1", + "version": "8.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 91ef5ad3..5d9a31a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swagger-typescript-api", - "version": "7.0.1", + "version": "8.0.0", "description": "Generate typescript/javascript api from swagger schema", "scripts": { "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",