diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a3ec6ea..a5a289b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # 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 ### Added - Added option to set the indentation (spaces and tabs) 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', }); diff --git a/package.json b/package.json index 85e10e9b..3b1f65ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.16.0", + "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", 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/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/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index 00967140..22ac736b 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 ''; @@ -3171,7 +3174,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)) { @@ -3184,7 +3191,7 @@ const getQueryString = (params: Record): string => { process(\`\${key}[\${k}]\`, v); }); } else { - searchParams.append(key, value); + append(key, value); } } }; @@ -3193,9 +3200,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/index.js b/test/index.js index 3a7ae817..548506a4 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',