Skip to content

Commit 5a8c2a4

Browse files
committed
Merge branch 'master' into feature/angular
2 parents 09e6c5f + abfd97b commit 5a8c2a4

File tree

8 files changed

+38
-20
lines changed

8 files changed

+38
-20
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.16.2] - 2021-01-26
5+
### Fixed
6+
- Removed dependency on `URLSearchParams` to support browser and node without any additional imports
7+
8+
## [0.16.1] - 2021-01-26
9+
### Fixed
10+
- Correct export inside `index.ts` when giving a custom name
11+
412
## [0.16.0] - 2021-01-25
513
### Added
614
- Added option to set the indentation (spaces and tabs)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Supports generation through CLI, Node.js and NPX
2121
- Supports tsc and @babel/plugin-transform-typescript
2222
- Supports aborting of requests (cancelable promise pattern)
23-
- Supports external references using [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser/)
23+
- Supports external references using [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser/)
2424

2525
## Install
2626

@@ -117,7 +117,7 @@ const appClient = new AppClient({
117117
});
118118

119119
// Use the client instance to make the API call
120-
const res = await appClient.organizations.createOrganization({
120+
const response = await appClient.organizations.createOrganization({
121121
name: 'OrgName',
122122
description: 'OrgDescription',
123123
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.16.0",
3+
"version": "0.16.2",
44
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",

src/templates/core/functions/getQueryString.hbs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const getQueryString = (params: Record<string, any>): string => {
2-
const searchParams = new URLSearchParams();
2+
const qs: string[] = [];
3+
4+
const append = (key: string, value: any) => {
5+
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
6+
};
37

48
const process = (key: string, value: any) => {
59
if (isDefined(value)) {
@@ -12,7 +16,7 @@ const getQueryString = (params: Record<string, any>): string => {
1216
process(`${key}[${k}]`, v);
1317
});
1418
} else {
15-
searchParams.append(key, value);
19+
append(key, value);
1620
}
1721
}
1822
};
@@ -21,9 +25,8 @@ const getQueryString = (params: Record<string, any>): string => {
2125
process(key, value);
2226
});
2327

24-
const query = searchParams.toString();
25-
if (query.length) {
26-
return `?${query}`;
28+
if (qs.length > 0) {
29+
return `?${qs.join('&')}`;
2730
}
2831

2932
return '';

src/templates/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{>header}}
22

33
{{#if @root.exportClient}}
4-
export { AppClient } from './client';
4+
export { {{{clientName}}} } from './client';
55
{{/if}}
66
{{#if @root.exportCore}}
77
export { ApiError } from './core/ApiError';

src/utils/writeClientIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const writeClientIndex = async (
4141
exportSchemas,
4242
useUnionTypes,
4343
postfix,
44+
clientName,
4445
server: client.server,
4546
version: client.version,
4647
models: sortModelsByName(client.models),

test/__snapshots__/index.spec.ts.snap

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ const base64 = (str: string): string => {
271271
};
272272

273273
const getQueryString = (params: Record<string, any>): string => {
274-
const searchParams = new URLSearchParams();
274+
const qs: string[] = [];
275+
276+
const append = (key: string, value: any) => {
277+
qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`);
278+
};
275279

276280
const process = (key: string, value: any) => {
277281
if (isDefined(value)) {
@@ -284,7 +288,7 @@ const getQueryString = (params: Record<string, any>): string => {
284288
process(\`\${key}[\${k}]\`, v);
285289
});
286290
} else {
287-
searchParams.append(key, value);
291+
append(key, value);
288292
}
289293
}
290294
};
@@ -293,9 +297,8 @@ const getQueryString = (params: Record<string, any>): string => {
293297
process(key, value);
294298
});
295299

296-
const query = searchParams.toString();
297-
if (query.length) {
298-
return \`?\${query}\`;
300+
if (qs.length > 0) {
301+
return \`?\${qs.join('&')}\`;
299302
}
300303

301304
return '';
@@ -3171,7 +3174,11 @@ const base64 = (str: string): string => {
31713174
};
31723175

31733176
const getQueryString = (params: Record<string, any>): string => {
3174-
const searchParams = new URLSearchParams();
3177+
const qs: string[] = [];
3178+
3179+
const append = (key: string, value: any) => {
3180+
qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`);
3181+
};
31753182

31763183
const process = (key: string, value: any) => {
31773184
if (isDefined(value)) {
@@ -3184,7 +3191,7 @@ const getQueryString = (params: Record<string, any>): string => {
31843191
process(\`\${key}[\${k}]\`, v);
31853192
});
31863193
} else {
3187-
searchParams.append(key, value);
3194+
append(key, value);
31883195
}
31893196
}
31903197
};
@@ -3193,9 +3200,8 @@ const getQueryString = (params: Record<string, any>): string => {
31933200
process(key, value);
31943201
});
31953202

3196-
const query = searchParams.toString();
3197-
if (query.length) {
3198-
return \`?\${query}\`;
3203+
if (qs.length > 0) {
3204+
return \`?\${qs.join('&')}\`;
31993205
}
32003206

32013207
return '';

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const generate = async (input, output) => {
1414
exportSchemas: true,
1515
exportModels: true,
1616
exportServices: true,
17-
// clientName: 'AppClient',
17+
// clientName: 'DemoAppClient',
1818
// indent: OpenAPI.Indent.SPACE_2,
1919
// postfix: 'Api',
2020
// request: './test/custom/request.ts',

0 commit comments

Comments
 (0)