From a159e7724519a67fd9225e4e8e74680fe61fe44c Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 26 Jan 2022 10:25:08 +0100 Subject: [PATCH 1/6] - Fixed issue #940 --- src/templates/index.hbs | 2 +- src/utils/writeClientIndex.ts | 1 + test/index.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/templates/index.hbs b/src/templates/index.hbs index 3c58e1cf..855d0c63 100644 --- a/src/templates/index.hbs +++ b/src/templates/index.hbs @@ -1,7 +1,7 @@ {{>header}} {{#if @root.exportClient}} -export { AppClient } from './client'; +export { {{{clientName}}} } from './client'; {{/if}} {{#if @root.exportCore}} export { ApiError } from './core/ApiError'; diff --git a/src/utils/writeClientIndex.ts b/src/utils/writeClientIndex.ts index 67ef0ced..eaecd1b4 100644 --- a/src/utils/writeClientIndex.ts +++ b/src/utils/writeClientIndex.ts @@ -41,6 +41,7 @@ export const writeClientIndex = async ( exportSchemas, useUnionTypes, postfix, + clientName, server: client.server, version: client.version, models: sortModelsByName(client.models), diff --git a/test/index.js b/test/index.js index 9ed5fd85..2d4bc491 100644 --- a/test/index.js +++ b/test/index.js @@ -14,7 +14,7 @@ const generate = async (input, output) => { exportSchemas: true, exportModels: true, exportServices: true, - // clientName: 'AppClient', + // clientName: 'DemoAppClient', // indent: OpenAPI.Indent.SPACE_2, // postfix: 'Api', // request: './test/custom/request.ts', From d418a8d9c65f93c2fd9044968cd5ad6fe41bfe1b Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 26 Jan 2022 10:26:12 +0100 Subject: [PATCH 2/6] v0.16.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58cf089b..4538409d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.16.0", + "version": "0.16.1", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", From dd9019c205d6a115843655f891148e214793d9b8 Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 26 Jan 2022 10:26:23 +0100 Subject: [PATCH 3/6] - New patch update --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a3ec6ea..8231fc65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.16.1] - 2021-01-26 +- Correct export inside `index.ts` when giving a custom name + ## [0.16.0] - 2021-01-25 ### Added - Added option to set the indentation (spaces and tabs) From ca09ad536798c67914d14fdfa4b86cfec921354d Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 26 Jan 2022 11:32:18 +0100 Subject: [PATCH 4/6] - Removed dependency if URLSearchParams --- CHANGELOG.md | 5 ++++ .../core/functions/getQueryString.hbs | 13 ++++++---- test/__snapshots__/index.spec.ts.snap | 26 ++++++++++++------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8231fc65..a5a289b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,12 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.16.2] - 2021-01-26 +### Fixed +- Removed dependency on `URLSearchParams` to support browser and node without any additional imports + ## [0.16.1] - 2021-01-26 +### Fixed - Correct export inside `index.ts` when giving a custom name ## [0.16.0] - 2021-01-25 diff --git a/src/templates/core/functions/getQueryString.hbs b/src/templates/core/functions/getQueryString.hbs index 686d9bf5..eac37f5e 100644 --- a/src/templates/core/functions/getQueryString.hbs +++ b/src/templates/core/functions/getQueryString.hbs @@ -1,5 +1,9 @@ const getQueryString = (params: Record): string => { - const searchParams = new URLSearchParams(); + const qs: string[] = []; + + const append = (key: string, value: any) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; const process = (key: string, value: any) => { if (isDefined(value)) { @@ -12,7 +16,7 @@ const getQueryString = (params: Record): string => { process(`${key}[${k}]`, v); }); } else { - searchParams.append(key, value); + append(key, value); } } }; @@ -21,9 +25,8 @@ const getQueryString = (params: Record): string => { process(key, value); }); - const query = searchParams.toString(); - if (query.length) { - return `?${query}`; + if (qs.length > 0) { + return `?${qs.join('&')}`; } return ''; diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index f280a93b..062e39f2 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -271,7 +271,11 @@ const base64 = (str: string): string => { }; const getQueryString = (params: Record): string => { - const searchParams = new URLSearchParams(); + const qs: string[] = []; + + const append = (key: string, value: any) => { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + }; const process = (key: string, value: any) => { if (isDefined(value)) { @@ -284,7 +288,7 @@ const getQueryString = (params: Record): string => { process(\`\${key}[\${k}]\`, v); }); } else { - searchParams.append(key, value); + append(key, value); } } }; @@ -293,9 +297,8 @@ const getQueryString = (params: Record): string => { process(key, value); }); - const query = searchParams.toString(); - if (query.length) { - return \`?\${query}\`; + if (qs.length > 0) { + return \`?\${qs.join('&')}\`; } return ''; @@ -3168,7 +3171,11 @@ const base64 = (str: string): string => { }; const getQueryString = (params: Record): string => { - const searchParams = new URLSearchParams(); + const qs: string[] = []; + + const append = (key: string, value: any) => { + qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); + }; const process = (key: string, value: any) => { if (isDefined(value)) { @@ -3181,7 +3188,7 @@ const getQueryString = (params: Record): string => { process(\`\${key}[\${k}]\`, v); }); } else { - searchParams.append(key, value); + append(key, value); } } }; @@ -3190,9 +3197,8 @@ const getQueryString = (params: Record): string => { process(key, value); }); - const query = searchParams.toString(); - if (query.length) { - return \`?\${query}\`; + if (qs.length > 0) { + return \`?\${qs.join('&')}\`; } return ''; From 5910c72d72a24e9b2e4fc3ccedea6221bc2e50c3 Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 26 Jan 2022 11:32:51 +0100 Subject: [PATCH 5/6] - New patch release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4538409d..6512f501 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.16.1", + "version": "0.16.2", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", From abfd97bcba8a6e7b953bb6497e6eb217a563ebcb Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Wed, 26 Jan 2022 11:38:35 +0100 Subject: [PATCH 6/6] - Minor cleanup of readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 03d076f7..397f6a19 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ - Supports generation through CLI, Node.js and NPX - Supports tsc and @babel/plugin-transform-typescript - Supports aborting of requests (cancelable promise pattern) -- Supports external references using [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser/) +- Supports external references using [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser/) ## Install @@ -117,7 +117,7 @@ const appClient = new AppClient({ }); // Use the client instance to make the API call -const res = await appClient.organizations.createOrganization({ +const response = await appClient.organizations.createOrganization({ name: 'OrgName', description: 'OrgDescription', });