@aws/nx-plugin 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/open-api/ts-client/__snapshots__/generator.spec.ts.snap +978 -356
- package/src/open-api/ts-client/__snapshots__/generator.streaming.spec.ts.snap +1678 -0
- package/src/open-api/ts-client/files/client.gen.ts.template +85 -38
- package/src/open-api/utils/codegen-data.js +24 -8
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +22 -2
- package/src/py/fast-api/files/app/__name__/init.py.template +21 -2
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +2 -9
- package/src/py/fast-api/react/files/fast-api/scripts/generate_open_api.py.template +1 -8
- package/src/trpc/react/README.md +45 -24
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +42 -41
- package/src/trpc/react/files/src/components/TrpcClients/{IsolatedTrpcProvider.tsx.template → TrpcProvider.tsx.template} +13 -16
- package/src/trpc/react/generator.js +13 -3
- package/src/trpc/react/generator.js.map +1 -1
- package/src/utils/ast.js +1 -1
- package/src/utils/ast.js.map +1 -1
- package/src/utils/files/website/components/tanstack-query/QueryClientProvider.tsx.template +18 -0
|
@@ -0,0 +1,1678 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`openApiTsClientGenerator - streaming > should handle error responses for streaming operations 1`] = `
|
|
4
|
+
"export type GetStream400Response = {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
export type GetStream500Response = {
|
|
9
|
+
error: string;
|
|
10
|
+
details?: string;
|
|
11
|
+
};
|
|
12
|
+
export type GetStream400Error = {
|
|
13
|
+
status: 400;
|
|
14
|
+
error: GetStream400Response;
|
|
15
|
+
};
|
|
16
|
+
export type GetStream500Error = {
|
|
17
|
+
status: 500;
|
|
18
|
+
error: GetStream500Response;
|
|
19
|
+
};
|
|
20
|
+
export type GetStreamError = GetStream400Error | GetStream500Error;
|
|
21
|
+
"
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`openApiTsClientGenerator - streaming > should handle error responses for streaming operations 2`] = `
|
|
25
|
+
"import type {
|
|
26
|
+
GetStream400Response,
|
|
27
|
+
GetStream500Response,
|
|
28
|
+
} from './types.gen.js';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Utility for serialisation and deserialisation of API types.
|
|
32
|
+
*/
|
|
33
|
+
class $IO {
|
|
34
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
35
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
36
|
+
|
|
37
|
+
public static GetStream400Response = {
|
|
38
|
+
toJson: (model: GetStream400Response): any => {
|
|
39
|
+
if (model === undefined || model === null) {
|
|
40
|
+
return model;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...(model.code === undefined
|
|
44
|
+
? {}
|
|
45
|
+
: {
|
|
46
|
+
code: model.code,
|
|
47
|
+
}),
|
|
48
|
+
...(model.message === undefined
|
|
49
|
+
? {}
|
|
50
|
+
: {
|
|
51
|
+
message: model.message,
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
fromJson: (json: any): GetStream400Response => {
|
|
56
|
+
if (json === undefined || json === null) {
|
|
57
|
+
return json;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
code: json['code'],
|
|
61
|
+
message: json['message'],
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
public static GetStream500Response = {
|
|
67
|
+
toJson: (model: GetStream500Response): any => {
|
|
68
|
+
if (model === undefined || model === null) {
|
|
69
|
+
return model;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
...(model.error === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: {
|
|
75
|
+
error: model.error,
|
|
76
|
+
}),
|
|
77
|
+
...(model.details === undefined
|
|
78
|
+
? {}
|
|
79
|
+
: {
|
|
80
|
+
details: model.details,
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
fromJson: (json: any): GetStream500Response => {
|
|
85
|
+
if (json === undefined || json === null) {
|
|
86
|
+
return json;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
error: json['error'],
|
|
90
|
+
...(json['details'] === undefined
|
|
91
|
+
? {}
|
|
92
|
+
: {
|
|
93
|
+
details: json['details'],
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Client configuration for TestApi
|
|
102
|
+
*/
|
|
103
|
+
export interface TestApiConfig {
|
|
104
|
+
/**
|
|
105
|
+
* Base URL for the API
|
|
106
|
+
*/
|
|
107
|
+
url: string;
|
|
108
|
+
/**
|
|
109
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
110
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
111
|
+
*/
|
|
112
|
+
fetch?: typeof fetch;
|
|
113
|
+
/**
|
|
114
|
+
* Additional configuration
|
|
115
|
+
*/
|
|
116
|
+
options?: {
|
|
117
|
+
/**
|
|
118
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
119
|
+
* the request in the OpenAPI specification.
|
|
120
|
+
* Set this to false to omit this header.
|
|
121
|
+
*/
|
|
122
|
+
omitContentTypeHeader?: boolean;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* API Client for TestApi
|
|
128
|
+
*/
|
|
129
|
+
export class TestApi {
|
|
130
|
+
private $config: TestApiConfig;
|
|
131
|
+
|
|
132
|
+
constructor(config: TestApiConfig) {
|
|
133
|
+
this.$config = config;
|
|
134
|
+
|
|
135
|
+
this.getStream = this.getStream.bind(this);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private $url = (
|
|
139
|
+
path: string,
|
|
140
|
+
pathParameters: { [key: string]: any },
|
|
141
|
+
queryParameters: { [key: string]: any },
|
|
142
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
143
|
+
): string => {
|
|
144
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
145
|
+
? this.$config.url.slice(0, -1)
|
|
146
|
+
: this.$config.url;
|
|
147
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
148
|
+
(withParams, [key, value]) =>
|
|
149
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
150
|
+
path,
|
|
151
|
+
);
|
|
152
|
+
const queryString = Object.entries(queryParameters)
|
|
153
|
+
.map(([key, value]) => {
|
|
154
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
155
|
+
return value
|
|
156
|
+
.map(
|
|
157
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
158
|
+
)
|
|
159
|
+
.join('&');
|
|
160
|
+
}
|
|
161
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
162
|
+
})
|
|
163
|
+
.join('&');
|
|
164
|
+
return (
|
|
165
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
private $headers = (
|
|
170
|
+
headerParameters: { [key: string]: any },
|
|
171
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
172
|
+
): [string, string][] => {
|
|
173
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
174
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
175
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
176
|
+
}
|
|
177
|
+
return [[key, String(value)]];
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
private $fetch: typeof fetch = (...args) =>
|
|
182
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
183
|
+
|
|
184
|
+
public async *getStream(): AsyncIterableIterator<number> {
|
|
185
|
+
const pathParameters: { [key: string]: any } = {};
|
|
186
|
+
const queryParameters: { [key: string]: any } = {};
|
|
187
|
+
const headerParameters: { [key: string]: any } = {};
|
|
188
|
+
|
|
189
|
+
const body = undefined;
|
|
190
|
+
|
|
191
|
+
const response = await this.$fetch(
|
|
192
|
+
this.$url('/stream', pathParameters, queryParameters),
|
|
193
|
+
{
|
|
194
|
+
headers: this.$headers(headerParameters),
|
|
195
|
+
method: 'GET',
|
|
196
|
+
body,
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
if (response.status === 200) {
|
|
201
|
+
const reader = response.body
|
|
202
|
+
?.pipeThrough(new TextDecoderStream())
|
|
203
|
+
.getReader();
|
|
204
|
+
while (reader) {
|
|
205
|
+
const { value, done } = await reader.read();
|
|
206
|
+
if (done) return;
|
|
207
|
+
yield Number(value);
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (response.status === 400) {
|
|
212
|
+
throw {
|
|
213
|
+
status: response.status,
|
|
214
|
+
error: $IO.GetStream400Response.fromJson(await response.json()),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if (response.status === 500) {
|
|
218
|
+
throw {
|
|
219
|
+
status: response.status,
|
|
220
|
+
error: $IO.GetStream500Response.fromJson(await response.json()),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
throw new Error(
|
|
224
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
"
|
|
229
|
+
`;
|
|
230
|
+
|
|
231
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of arrays 1`] = `
|
|
232
|
+
"export type GetObjectArrays200ResponseItem = {
|
|
233
|
+
id: number;
|
|
234
|
+
name: string;
|
|
235
|
+
};
|
|
236
|
+
export type GetBooleanArraysError = never;
|
|
237
|
+
export type GetDateArraysError = never;
|
|
238
|
+
export type GetNumberArraysError = never;
|
|
239
|
+
export type GetObjectArraysError = never;
|
|
240
|
+
export type GetStringArraysError = never;
|
|
241
|
+
"
|
|
242
|
+
`;
|
|
243
|
+
|
|
244
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of arrays 2`] = `
|
|
245
|
+
"import type { GetObjectArrays200ResponseItem } from './types.gen.js';
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Utility for serialisation and deserialisation of API types.
|
|
249
|
+
*/
|
|
250
|
+
class $IO {
|
|
251
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
252
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
253
|
+
|
|
254
|
+
public static GetObjectArrays200ResponseItem = {
|
|
255
|
+
toJson: (model: GetObjectArrays200ResponseItem): any => {
|
|
256
|
+
if (model === undefined || model === null) {
|
|
257
|
+
return model;
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
...(model.id === undefined
|
|
261
|
+
? {}
|
|
262
|
+
: {
|
|
263
|
+
id: model.id,
|
|
264
|
+
}),
|
|
265
|
+
...(model.name === undefined
|
|
266
|
+
? {}
|
|
267
|
+
: {
|
|
268
|
+
name: model.name,
|
|
269
|
+
}),
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
fromJson: (json: any): GetObjectArrays200ResponseItem => {
|
|
273
|
+
if (json === undefined || json === null) {
|
|
274
|
+
return json;
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
id: json['id'],
|
|
278
|
+
name: json['name'],
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Client configuration for TestApi
|
|
286
|
+
*/
|
|
287
|
+
export interface TestApiConfig {
|
|
288
|
+
/**
|
|
289
|
+
* Base URL for the API
|
|
290
|
+
*/
|
|
291
|
+
url: string;
|
|
292
|
+
/**
|
|
293
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
294
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
295
|
+
*/
|
|
296
|
+
fetch?: typeof fetch;
|
|
297
|
+
/**
|
|
298
|
+
* Additional configuration
|
|
299
|
+
*/
|
|
300
|
+
options?: {
|
|
301
|
+
/**
|
|
302
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
303
|
+
* the request in the OpenAPI specification.
|
|
304
|
+
* Set this to false to omit this header.
|
|
305
|
+
*/
|
|
306
|
+
omitContentTypeHeader?: boolean;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* API Client for TestApi
|
|
312
|
+
*/
|
|
313
|
+
export class TestApi {
|
|
314
|
+
private $config: TestApiConfig;
|
|
315
|
+
|
|
316
|
+
constructor(config: TestApiConfig) {
|
|
317
|
+
this.$config = config;
|
|
318
|
+
|
|
319
|
+
this.getBooleanArrays = this.getBooleanArrays.bind(this);
|
|
320
|
+
this.getDateArrays = this.getDateArrays.bind(this);
|
|
321
|
+
this.getNumberArrays = this.getNumberArrays.bind(this);
|
|
322
|
+
this.getObjectArrays = this.getObjectArrays.bind(this);
|
|
323
|
+
this.getStringArrays = this.getStringArrays.bind(this);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private $url = (
|
|
327
|
+
path: string,
|
|
328
|
+
pathParameters: { [key: string]: any },
|
|
329
|
+
queryParameters: { [key: string]: any },
|
|
330
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
331
|
+
): string => {
|
|
332
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
333
|
+
? this.$config.url.slice(0, -1)
|
|
334
|
+
: this.$config.url;
|
|
335
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
336
|
+
(withParams, [key, value]) =>
|
|
337
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
338
|
+
path,
|
|
339
|
+
);
|
|
340
|
+
const queryString = Object.entries(queryParameters)
|
|
341
|
+
.map(([key, value]) => {
|
|
342
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
343
|
+
return value
|
|
344
|
+
.map(
|
|
345
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
346
|
+
)
|
|
347
|
+
.join('&');
|
|
348
|
+
}
|
|
349
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
350
|
+
})
|
|
351
|
+
.join('&');
|
|
352
|
+
return (
|
|
353
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
354
|
+
);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
private $headers = (
|
|
358
|
+
headerParameters: { [key: string]: any },
|
|
359
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
360
|
+
): [string, string][] => {
|
|
361
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
362
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
363
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
364
|
+
}
|
|
365
|
+
return [[key, String(value)]];
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
private $fetch: typeof fetch = (...args) =>
|
|
370
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
371
|
+
|
|
372
|
+
public async *getBooleanArrays(): AsyncIterableIterator<Array<boolean>> {
|
|
373
|
+
const pathParameters: { [key: string]: any } = {};
|
|
374
|
+
const queryParameters: { [key: string]: any } = {};
|
|
375
|
+
const headerParameters: { [key: string]: any } = {};
|
|
376
|
+
|
|
377
|
+
const body = undefined;
|
|
378
|
+
|
|
379
|
+
const response = await this.$fetch(
|
|
380
|
+
this.$url('/test/boolean-arrays', pathParameters, queryParameters),
|
|
381
|
+
{
|
|
382
|
+
headers: this.$headers(headerParameters),
|
|
383
|
+
method: 'GET',
|
|
384
|
+
body,
|
|
385
|
+
},
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
if (response.status === 200) {
|
|
389
|
+
const reader = response.body
|
|
390
|
+
?.pipeThrough(new TextDecoderStream())
|
|
391
|
+
.getReader();
|
|
392
|
+
while (reader) {
|
|
393
|
+
const { value, done } = await reader.read();
|
|
394
|
+
if (done) return;
|
|
395
|
+
yield JSON.parse(value);
|
|
396
|
+
}
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
throw new Error(
|
|
400
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
public async *getDateArrays(): AsyncIterableIterator<Array<Date>> {
|
|
405
|
+
const pathParameters: { [key: string]: any } = {};
|
|
406
|
+
const queryParameters: { [key: string]: any } = {};
|
|
407
|
+
const headerParameters: { [key: string]: any } = {};
|
|
408
|
+
|
|
409
|
+
const body = undefined;
|
|
410
|
+
|
|
411
|
+
const response = await this.$fetch(
|
|
412
|
+
this.$url('/test/date-arrays', pathParameters, queryParameters),
|
|
413
|
+
{
|
|
414
|
+
headers: this.$headers(headerParameters),
|
|
415
|
+
method: 'GET',
|
|
416
|
+
body,
|
|
417
|
+
},
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
if (response.status === 200) {
|
|
421
|
+
const reader = response.body
|
|
422
|
+
?.pipeThrough(new TextDecoderStream())
|
|
423
|
+
.getReader();
|
|
424
|
+
while (reader) {
|
|
425
|
+
const { value, done } = await reader.read();
|
|
426
|
+
if (done) return;
|
|
427
|
+
yield (JSON.parse(value) as Array<any>).map((item0) => new Date(item0));
|
|
428
|
+
}
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
throw new Error(
|
|
432
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
public async *getNumberArrays(): AsyncIterableIterator<Array<number>> {
|
|
437
|
+
const pathParameters: { [key: string]: any } = {};
|
|
438
|
+
const queryParameters: { [key: string]: any } = {};
|
|
439
|
+
const headerParameters: { [key: string]: any } = {};
|
|
440
|
+
|
|
441
|
+
const body = undefined;
|
|
442
|
+
|
|
443
|
+
const response = await this.$fetch(
|
|
444
|
+
this.$url('/test/number-arrays', pathParameters, queryParameters),
|
|
445
|
+
{
|
|
446
|
+
headers: this.$headers(headerParameters),
|
|
447
|
+
method: 'GET',
|
|
448
|
+
body,
|
|
449
|
+
},
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
if (response.status === 200) {
|
|
453
|
+
const reader = response.body
|
|
454
|
+
?.pipeThrough(new TextDecoderStream())
|
|
455
|
+
.getReader();
|
|
456
|
+
while (reader) {
|
|
457
|
+
const { value, done } = await reader.read();
|
|
458
|
+
if (done) return;
|
|
459
|
+
yield JSON.parse(value);
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
throw new Error(
|
|
464
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
public async *getObjectArrays(): AsyncIterableIterator<
|
|
469
|
+
Array<GetObjectArrays200ResponseItem>
|
|
470
|
+
> {
|
|
471
|
+
const pathParameters: { [key: string]: any } = {};
|
|
472
|
+
const queryParameters: { [key: string]: any } = {};
|
|
473
|
+
const headerParameters: { [key: string]: any } = {};
|
|
474
|
+
|
|
475
|
+
const body = undefined;
|
|
476
|
+
|
|
477
|
+
const response = await this.$fetch(
|
|
478
|
+
this.$url('/test/object-arrays', pathParameters, queryParameters),
|
|
479
|
+
{
|
|
480
|
+
headers: this.$headers(headerParameters),
|
|
481
|
+
method: 'GET',
|
|
482
|
+
body,
|
|
483
|
+
},
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
if (response.status === 200) {
|
|
487
|
+
const reader = response.body
|
|
488
|
+
?.pipeThrough(new TextDecoderStream())
|
|
489
|
+
.getReader();
|
|
490
|
+
while (reader) {
|
|
491
|
+
const { value, done } = await reader.read();
|
|
492
|
+
if (done) return;
|
|
493
|
+
yield (JSON.parse(value) as Array<any>).map(
|
|
494
|
+
$IO.GetObjectArrays200ResponseItem.fromJson,
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
throw new Error(
|
|
500
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
public async *getStringArrays(): AsyncIterableIterator<Array<string>> {
|
|
505
|
+
const pathParameters: { [key: string]: any } = {};
|
|
506
|
+
const queryParameters: { [key: string]: any } = {};
|
|
507
|
+
const headerParameters: { [key: string]: any } = {};
|
|
508
|
+
|
|
509
|
+
const body = undefined;
|
|
510
|
+
|
|
511
|
+
const response = await this.$fetch(
|
|
512
|
+
this.$url('/test/string-arrays', pathParameters, queryParameters),
|
|
513
|
+
{
|
|
514
|
+
headers: this.$headers(headerParameters),
|
|
515
|
+
method: 'GET',
|
|
516
|
+
body,
|
|
517
|
+
},
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
if (response.status === 200) {
|
|
521
|
+
const reader = response.body
|
|
522
|
+
?.pipeThrough(new TextDecoderStream())
|
|
523
|
+
.getReader();
|
|
524
|
+
while (reader) {
|
|
525
|
+
const { value, done } = await reader.read();
|
|
526
|
+
if (done) return;
|
|
527
|
+
yield JSON.parse(value);
|
|
528
|
+
}
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
throw new Error(
|
|
532
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
"
|
|
537
|
+
`;
|
|
538
|
+
|
|
539
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of dictionaries 1`] = `
|
|
540
|
+
"export type GetArrayDict200Response = {
|
|
541
|
+
[key: string]: Array<number>;
|
|
542
|
+
};
|
|
543
|
+
export type GetBooleanDict200Response = {
|
|
544
|
+
[key: string]: boolean;
|
|
545
|
+
};
|
|
546
|
+
export type GetDateDict200Response = {
|
|
547
|
+
[key: string]: Date;
|
|
548
|
+
};
|
|
549
|
+
export type GetEnumDict200Response = {
|
|
550
|
+
[key: string]: string;
|
|
551
|
+
};
|
|
552
|
+
export type GetEnumDict200ResponseValue = 'RED' | 'GREEN' | 'BLUE';
|
|
553
|
+
export type GetNestedDict200Response = {
|
|
554
|
+
[key: string]: { [key: string]: GetNestedDict200ResponseValueValue };
|
|
555
|
+
};
|
|
556
|
+
export type GetNestedDict200ResponseValueValue = {
|
|
557
|
+
value: number;
|
|
558
|
+
tags: Array<string>;
|
|
559
|
+
};
|
|
560
|
+
export type GetNumberDict200Response = {
|
|
561
|
+
[key: string]: number;
|
|
562
|
+
};
|
|
563
|
+
export type GetObjectArrayDict200Response = {
|
|
564
|
+
[key: string]: Array<GetObjectArrayDict200ResponseValueItem>;
|
|
565
|
+
};
|
|
566
|
+
export type GetObjectArrayDict200ResponseValueItem = {
|
|
567
|
+
id: number;
|
|
568
|
+
name: string;
|
|
569
|
+
};
|
|
570
|
+
export type GetStringDict200Response = {
|
|
571
|
+
[key: string]: string;
|
|
572
|
+
};
|
|
573
|
+
export type GetArrayDictError = never;
|
|
574
|
+
export type GetBooleanDictError = never;
|
|
575
|
+
export type GetDateDictError = never;
|
|
576
|
+
export type GetEnumDictError = never;
|
|
577
|
+
export type GetNestedDictError = never;
|
|
578
|
+
export type GetNumberDictError = never;
|
|
579
|
+
export type GetObjectArrayDictError = never;
|
|
580
|
+
export type GetStringDictError = never;
|
|
581
|
+
"
|
|
582
|
+
`;
|
|
583
|
+
|
|
584
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of dictionaries 2`] = `
|
|
585
|
+
"import type {
|
|
586
|
+
GetArrayDict200Response,
|
|
587
|
+
GetBooleanDict200Response,
|
|
588
|
+
GetDateDict200Response,
|
|
589
|
+
GetEnumDict200Response,
|
|
590
|
+
GetEnumDict200ResponseValue,
|
|
591
|
+
GetNestedDict200Response,
|
|
592
|
+
GetNestedDict200ResponseValueValue,
|
|
593
|
+
GetNumberDict200Response,
|
|
594
|
+
GetObjectArrayDict200Response,
|
|
595
|
+
GetObjectArrayDict200ResponseValueItem,
|
|
596
|
+
GetStringDict200Response,
|
|
597
|
+
} from './types.gen.js';
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Utility for serialisation and deserialisation of API types.
|
|
601
|
+
*/
|
|
602
|
+
class $IO {
|
|
603
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
604
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
605
|
+
|
|
606
|
+
public static GetArrayDict200Response = {
|
|
607
|
+
toJson: (model: GetArrayDict200Response): any => {
|
|
608
|
+
if (model === undefined || model === null) {
|
|
609
|
+
return model;
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
...model,
|
|
613
|
+
};
|
|
614
|
+
},
|
|
615
|
+
fromJson: (json: any): GetArrayDict200Response => {
|
|
616
|
+
if (json === undefined || json === null) {
|
|
617
|
+
return json;
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
...json,
|
|
621
|
+
};
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
public static GetBooleanDict200Response = {
|
|
626
|
+
toJson: (model: GetBooleanDict200Response): any => {
|
|
627
|
+
if (model === undefined || model === null) {
|
|
628
|
+
return model;
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
...model,
|
|
632
|
+
};
|
|
633
|
+
},
|
|
634
|
+
fromJson: (json: any): GetBooleanDict200Response => {
|
|
635
|
+
if (json === undefined || json === null) {
|
|
636
|
+
return json;
|
|
637
|
+
}
|
|
638
|
+
return {
|
|
639
|
+
...json,
|
|
640
|
+
};
|
|
641
|
+
},
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
public static GetDateDict200Response = {
|
|
645
|
+
toJson: (model: GetDateDict200Response): any => {
|
|
646
|
+
if (model === undefined || model === null) {
|
|
647
|
+
return model;
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
...$IO.$mapValues(model, (item0) => item0.toISOString()),
|
|
651
|
+
};
|
|
652
|
+
},
|
|
653
|
+
fromJson: (json: any): GetDateDict200Response => {
|
|
654
|
+
if (json === undefined || json === null) {
|
|
655
|
+
return json;
|
|
656
|
+
}
|
|
657
|
+
return {
|
|
658
|
+
...$IO.$mapValues(json, (item0) => new Date(item0)),
|
|
659
|
+
};
|
|
660
|
+
},
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
public static GetEnumDict200Response = {
|
|
664
|
+
toJson: (model: GetEnumDict200Response): any => {
|
|
665
|
+
if (model === undefined || model === null) {
|
|
666
|
+
return model;
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
...model,
|
|
670
|
+
};
|
|
671
|
+
},
|
|
672
|
+
fromJson: (json: any): GetEnumDict200Response => {
|
|
673
|
+
if (json === undefined || json === null) {
|
|
674
|
+
return json;
|
|
675
|
+
}
|
|
676
|
+
return {
|
|
677
|
+
...json,
|
|
678
|
+
};
|
|
679
|
+
},
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
public static GetNestedDict200Response = {
|
|
683
|
+
toJson: (model: GetNestedDict200Response): any => {
|
|
684
|
+
if (model === undefined || model === null) {
|
|
685
|
+
return model;
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
...$IO.$mapValues(model, (item0) =>
|
|
689
|
+
$IO.$mapValues(item0, $IO.GetNestedDict200ResponseValueValue.toJson),
|
|
690
|
+
),
|
|
691
|
+
};
|
|
692
|
+
},
|
|
693
|
+
fromJson: (json: any): GetNestedDict200Response => {
|
|
694
|
+
if (json === undefined || json === null) {
|
|
695
|
+
return json;
|
|
696
|
+
}
|
|
697
|
+
return {
|
|
698
|
+
...$IO.$mapValues(json, (item0) =>
|
|
699
|
+
$IO.$mapValues(
|
|
700
|
+
item0,
|
|
701
|
+
$IO.GetNestedDict200ResponseValueValue.fromJson,
|
|
702
|
+
),
|
|
703
|
+
),
|
|
704
|
+
};
|
|
705
|
+
},
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
public static GetNestedDict200ResponseValueValue = {
|
|
709
|
+
toJson: (model: GetNestedDict200ResponseValueValue): any => {
|
|
710
|
+
if (model === undefined || model === null) {
|
|
711
|
+
return model;
|
|
712
|
+
}
|
|
713
|
+
return {
|
|
714
|
+
...(model.value === undefined
|
|
715
|
+
? {}
|
|
716
|
+
: {
|
|
717
|
+
value: model.value,
|
|
718
|
+
}),
|
|
719
|
+
...(model.tags === undefined
|
|
720
|
+
? {}
|
|
721
|
+
: {
|
|
722
|
+
tags: model.tags,
|
|
723
|
+
}),
|
|
724
|
+
};
|
|
725
|
+
},
|
|
726
|
+
fromJson: (json: any): GetNestedDict200ResponseValueValue => {
|
|
727
|
+
if (json === undefined || json === null) {
|
|
728
|
+
return json;
|
|
729
|
+
}
|
|
730
|
+
return {
|
|
731
|
+
value: json['value'],
|
|
732
|
+
tags: json['tags'],
|
|
733
|
+
};
|
|
734
|
+
},
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
public static GetNumberDict200Response = {
|
|
738
|
+
toJson: (model: GetNumberDict200Response): any => {
|
|
739
|
+
if (model === undefined || model === null) {
|
|
740
|
+
return model;
|
|
741
|
+
}
|
|
742
|
+
return {
|
|
743
|
+
...model,
|
|
744
|
+
};
|
|
745
|
+
},
|
|
746
|
+
fromJson: (json: any): GetNumberDict200Response => {
|
|
747
|
+
if (json === undefined || json === null) {
|
|
748
|
+
return json;
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
...json,
|
|
752
|
+
};
|
|
753
|
+
},
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
public static GetObjectArrayDict200Response = {
|
|
757
|
+
toJson: (model: GetObjectArrayDict200Response): any => {
|
|
758
|
+
if (model === undefined || model === null) {
|
|
759
|
+
return model;
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
...$IO.$mapValues(model, (item0) =>
|
|
763
|
+
item0.map($IO.GetObjectArrayDict200ResponseValueItem.toJson),
|
|
764
|
+
),
|
|
765
|
+
};
|
|
766
|
+
},
|
|
767
|
+
fromJson: (json: any): GetObjectArrayDict200Response => {
|
|
768
|
+
if (json === undefined || json === null) {
|
|
769
|
+
return json;
|
|
770
|
+
}
|
|
771
|
+
return {
|
|
772
|
+
...$IO.$mapValues(json, (item0) =>
|
|
773
|
+
item0.map($IO.GetObjectArrayDict200ResponseValueItem.fromJson),
|
|
774
|
+
),
|
|
775
|
+
};
|
|
776
|
+
},
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
public static GetObjectArrayDict200ResponseValueItem = {
|
|
780
|
+
toJson: (model: GetObjectArrayDict200ResponseValueItem): any => {
|
|
781
|
+
if (model === undefined || model === null) {
|
|
782
|
+
return model;
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
...(model.id === undefined
|
|
786
|
+
? {}
|
|
787
|
+
: {
|
|
788
|
+
id: model.id,
|
|
789
|
+
}),
|
|
790
|
+
...(model.name === undefined
|
|
791
|
+
? {}
|
|
792
|
+
: {
|
|
793
|
+
name: model.name,
|
|
794
|
+
}),
|
|
795
|
+
};
|
|
796
|
+
},
|
|
797
|
+
fromJson: (json: any): GetObjectArrayDict200ResponseValueItem => {
|
|
798
|
+
if (json === undefined || json === null) {
|
|
799
|
+
return json;
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
id: json['id'],
|
|
803
|
+
name: json['name'],
|
|
804
|
+
};
|
|
805
|
+
},
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
public static GetStringDict200Response = {
|
|
809
|
+
toJson: (model: GetStringDict200Response): any => {
|
|
810
|
+
if (model === undefined || model === null) {
|
|
811
|
+
return model;
|
|
812
|
+
}
|
|
813
|
+
return {
|
|
814
|
+
...model,
|
|
815
|
+
};
|
|
816
|
+
},
|
|
817
|
+
fromJson: (json: any): GetStringDict200Response => {
|
|
818
|
+
if (json === undefined || json === null) {
|
|
819
|
+
return json;
|
|
820
|
+
}
|
|
821
|
+
return {
|
|
822
|
+
...json,
|
|
823
|
+
};
|
|
824
|
+
},
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Client configuration for TestApi
|
|
830
|
+
*/
|
|
831
|
+
export interface TestApiConfig {
|
|
832
|
+
/**
|
|
833
|
+
* Base URL for the API
|
|
834
|
+
*/
|
|
835
|
+
url: string;
|
|
836
|
+
/**
|
|
837
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
838
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
839
|
+
*/
|
|
840
|
+
fetch?: typeof fetch;
|
|
841
|
+
/**
|
|
842
|
+
* Additional configuration
|
|
843
|
+
*/
|
|
844
|
+
options?: {
|
|
845
|
+
/**
|
|
846
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
847
|
+
* the request in the OpenAPI specification.
|
|
848
|
+
* Set this to false to omit this header.
|
|
849
|
+
*/
|
|
850
|
+
omitContentTypeHeader?: boolean;
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* API Client for TestApi
|
|
856
|
+
*/
|
|
857
|
+
export class TestApi {
|
|
858
|
+
private $config: TestApiConfig;
|
|
859
|
+
|
|
860
|
+
constructor(config: TestApiConfig) {
|
|
861
|
+
this.$config = config;
|
|
862
|
+
|
|
863
|
+
this.getArrayDict = this.getArrayDict.bind(this);
|
|
864
|
+
this.getBooleanDict = this.getBooleanDict.bind(this);
|
|
865
|
+
this.getDateDict = this.getDateDict.bind(this);
|
|
866
|
+
this.getEnumDict = this.getEnumDict.bind(this);
|
|
867
|
+
this.getNestedDict = this.getNestedDict.bind(this);
|
|
868
|
+
this.getNumberDict = this.getNumberDict.bind(this);
|
|
869
|
+
this.getObjectArrayDict = this.getObjectArrayDict.bind(this);
|
|
870
|
+
this.getStringDict = this.getStringDict.bind(this);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
private $url = (
|
|
874
|
+
path: string,
|
|
875
|
+
pathParameters: { [key: string]: any },
|
|
876
|
+
queryParameters: { [key: string]: any },
|
|
877
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
878
|
+
): string => {
|
|
879
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
880
|
+
? this.$config.url.slice(0, -1)
|
|
881
|
+
: this.$config.url;
|
|
882
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
883
|
+
(withParams, [key, value]) =>
|
|
884
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
885
|
+
path,
|
|
886
|
+
);
|
|
887
|
+
const queryString = Object.entries(queryParameters)
|
|
888
|
+
.map(([key, value]) => {
|
|
889
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
890
|
+
return value
|
|
891
|
+
.map(
|
|
892
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
893
|
+
)
|
|
894
|
+
.join('&');
|
|
895
|
+
}
|
|
896
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
897
|
+
})
|
|
898
|
+
.join('&');
|
|
899
|
+
return (
|
|
900
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
901
|
+
);
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
private $headers = (
|
|
905
|
+
headerParameters: { [key: string]: any },
|
|
906
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
907
|
+
): [string, string][] => {
|
|
908
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
909
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
910
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
911
|
+
}
|
|
912
|
+
return [[key, String(value)]];
|
|
913
|
+
});
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
private $fetch: typeof fetch = (...args) =>
|
|
917
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
918
|
+
|
|
919
|
+
public async *getArrayDict(): AsyncIterableIterator<GetArrayDict200Response> {
|
|
920
|
+
const pathParameters: { [key: string]: any } = {};
|
|
921
|
+
const queryParameters: { [key: string]: any } = {};
|
|
922
|
+
const headerParameters: { [key: string]: any } = {};
|
|
923
|
+
|
|
924
|
+
const body = undefined;
|
|
925
|
+
|
|
926
|
+
const response = await this.$fetch(
|
|
927
|
+
this.$url('/test/array-dict', pathParameters, queryParameters),
|
|
928
|
+
{
|
|
929
|
+
headers: this.$headers(headerParameters),
|
|
930
|
+
method: 'GET',
|
|
931
|
+
body,
|
|
932
|
+
},
|
|
933
|
+
);
|
|
934
|
+
|
|
935
|
+
if (response.status === 200) {
|
|
936
|
+
const reader = response.body
|
|
937
|
+
?.pipeThrough(new TextDecoderStream())
|
|
938
|
+
.getReader();
|
|
939
|
+
while (reader) {
|
|
940
|
+
const { value, done } = await reader.read();
|
|
941
|
+
if (done) return;
|
|
942
|
+
yield $IO.GetArrayDict200Response.fromJson(JSON.parse(value));
|
|
943
|
+
}
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
throw new Error(
|
|
947
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
public async *getBooleanDict(): AsyncIterableIterator<GetBooleanDict200Response> {
|
|
952
|
+
const pathParameters: { [key: string]: any } = {};
|
|
953
|
+
const queryParameters: { [key: string]: any } = {};
|
|
954
|
+
const headerParameters: { [key: string]: any } = {};
|
|
955
|
+
|
|
956
|
+
const body = undefined;
|
|
957
|
+
|
|
958
|
+
const response = await this.$fetch(
|
|
959
|
+
this.$url('/test/boolean-dict', pathParameters, queryParameters),
|
|
960
|
+
{
|
|
961
|
+
headers: this.$headers(headerParameters),
|
|
962
|
+
method: 'GET',
|
|
963
|
+
body,
|
|
964
|
+
},
|
|
965
|
+
);
|
|
966
|
+
|
|
967
|
+
if (response.status === 200) {
|
|
968
|
+
const reader = response.body
|
|
969
|
+
?.pipeThrough(new TextDecoderStream())
|
|
970
|
+
.getReader();
|
|
971
|
+
while (reader) {
|
|
972
|
+
const { value, done } = await reader.read();
|
|
973
|
+
if (done) return;
|
|
974
|
+
yield $IO.GetBooleanDict200Response.fromJson(JSON.parse(value));
|
|
975
|
+
}
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
throw new Error(
|
|
979
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
public async *getDateDict(): AsyncIterableIterator<GetDateDict200Response> {
|
|
984
|
+
const pathParameters: { [key: string]: any } = {};
|
|
985
|
+
const queryParameters: { [key: string]: any } = {};
|
|
986
|
+
const headerParameters: { [key: string]: any } = {};
|
|
987
|
+
|
|
988
|
+
const body = undefined;
|
|
989
|
+
|
|
990
|
+
const response = await this.$fetch(
|
|
991
|
+
this.$url('/test/date-dict', pathParameters, queryParameters),
|
|
992
|
+
{
|
|
993
|
+
headers: this.$headers(headerParameters),
|
|
994
|
+
method: 'GET',
|
|
995
|
+
body,
|
|
996
|
+
},
|
|
997
|
+
);
|
|
998
|
+
|
|
999
|
+
if (response.status === 200) {
|
|
1000
|
+
const reader = response.body
|
|
1001
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1002
|
+
.getReader();
|
|
1003
|
+
while (reader) {
|
|
1004
|
+
const { value, done } = await reader.read();
|
|
1005
|
+
if (done) return;
|
|
1006
|
+
yield $IO.GetDateDict200Response.fromJson(JSON.parse(value));
|
|
1007
|
+
}
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
throw new Error(
|
|
1011
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
public async *getEnumDict(): AsyncIterableIterator<GetEnumDict200Response> {
|
|
1016
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1017
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1018
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1019
|
+
|
|
1020
|
+
const body = undefined;
|
|
1021
|
+
|
|
1022
|
+
const response = await this.$fetch(
|
|
1023
|
+
this.$url('/test/enum-dict', pathParameters, queryParameters),
|
|
1024
|
+
{
|
|
1025
|
+
headers: this.$headers(headerParameters),
|
|
1026
|
+
method: 'GET',
|
|
1027
|
+
body,
|
|
1028
|
+
},
|
|
1029
|
+
);
|
|
1030
|
+
|
|
1031
|
+
if (response.status === 200) {
|
|
1032
|
+
const reader = response.body
|
|
1033
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1034
|
+
.getReader();
|
|
1035
|
+
while (reader) {
|
|
1036
|
+
const { value, done } = await reader.read();
|
|
1037
|
+
if (done) return;
|
|
1038
|
+
yield $IO.GetEnumDict200Response.fromJson(JSON.parse(value));
|
|
1039
|
+
}
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
throw new Error(
|
|
1043
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
public async *getNestedDict(): AsyncIterableIterator<GetNestedDict200Response> {
|
|
1048
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1049
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1050
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1051
|
+
|
|
1052
|
+
const body = undefined;
|
|
1053
|
+
|
|
1054
|
+
const response = await this.$fetch(
|
|
1055
|
+
this.$url('/test/nested-dict', pathParameters, queryParameters),
|
|
1056
|
+
{
|
|
1057
|
+
headers: this.$headers(headerParameters),
|
|
1058
|
+
method: 'GET',
|
|
1059
|
+
body,
|
|
1060
|
+
},
|
|
1061
|
+
);
|
|
1062
|
+
|
|
1063
|
+
if (response.status === 200) {
|
|
1064
|
+
const reader = response.body
|
|
1065
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1066
|
+
.getReader();
|
|
1067
|
+
while (reader) {
|
|
1068
|
+
const { value, done } = await reader.read();
|
|
1069
|
+
if (done) return;
|
|
1070
|
+
yield $IO.GetNestedDict200Response.fromJson(JSON.parse(value));
|
|
1071
|
+
}
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
throw new Error(
|
|
1075
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
public async *getNumberDict(): AsyncIterableIterator<GetNumberDict200Response> {
|
|
1080
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1081
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1082
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1083
|
+
|
|
1084
|
+
const body = undefined;
|
|
1085
|
+
|
|
1086
|
+
const response = await this.$fetch(
|
|
1087
|
+
this.$url('/test/number-dict', pathParameters, queryParameters),
|
|
1088
|
+
{
|
|
1089
|
+
headers: this.$headers(headerParameters),
|
|
1090
|
+
method: 'GET',
|
|
1091
|
+
body,
|
|
1092
|
+
},
|
|
1093
|
+
);
|
|
1094
|
+
|
|
1095
|
+
if (response.status === 200) {
|
|
1096
|
+
const reader = response.body
|
|
1097
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1098
|
+
.getReader();
|
|
1099
|
+
while (reader) {
|
|
1100
|
+
const { value, done } = await reader.read();
|
|
1101
|
+
if (done) return;
|
|
1102
|
+
yield $IO.GetNumberDict200Response.fromJson(JSON.parse(value));
|
|
1103
|
+
}
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
throw new Error(
|
|
1107
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
public async *getObjectArrayDict(): AsyncIterableIterator<GetObjectArrayDict200Response> {
|
|
1112
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1113
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1114
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1115
|
+
|
|
1116
|
+
const body = undefined;
|
|
1117
|
+
|
|
1118
|
+
const response = await this.$fetch(
|
|
1119
|
+
this.$url('/test/object-array-dict', pathParameters, queryParameters),
|
|
1120
|
+
{
|
|
1121
|
+
headers: this.$headers(headerParameters),
|
|
1122
|
+
method: 'GET',
|
|
1123
|
+
body,
|
|
1124
|
+
},
|
|
1125
|
+
);
|
|
1126
|
+
|
|
1127
|
+
if (response.status === 200) {
|
|
1128
|
+
const reader = response.body
|
|
1129
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1130
|
+
.getReader();
|
|
1131
|
+
while (reader) {
|
|
1132
|
+
const { value, done } = await reader.read();
|
|
1133
|
+
if (done) return;
|
|
1134
|
+
yield $IO.GetObjectArrayDict200Response.fromJson(JSON.parse(value));
|
|
1135
|
+
}
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
throw new Error(
|
|
1139
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
public async *getStringDict(): AsyncIterableIterator<GetStringDict200Response> {
|
|
1144
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1145
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1146
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1147
|
+
|
|
1148
|
+
const body = undefined;
|
|
1149
|
+
|
|
1150
|
+
const response = await this.$fetch(
|
|
1151
|
+
this.$url('/test/string-dict', pathParameters, queryParameters),
|
|
1152
|
+
{
|
|
1153
|
+
headers: this.$headers(headerParameters),
|
|
1154
|
+
method: 'GET',
|
|
1155
|
+
body,
|
|
1156
|
+
},
|
|
1157
|
+
);
|
|
1158
|
+
|
|
1159
|
+
if (response.status === 200) {
|
|
1160
|
+
const reader = response.body
|
|
1161
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1162
|
+
.getReader();
|
|
1163
|
+
while (reader) {
|
|
1164
|
+
const { value, done } = await reader.read();
|
|
1165
|
+
if (done) return;
|
|
1166
|
+
yield $IO.GetStringDict200Response.fromJson(JSON.parse(value));
|
|
1167
|
+
}
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
throw new Error(
|
|
1171
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
"
|
|
1176
|
+
`;
|
|
1177
|
+
|
|
1178
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of numbers, booleans and dates 1`] = `
|
|
1179
|
+
"export type GetBooleansError = never;
|
|
1180
|
+
export type GetDatesError = never;
|
|
1181
|
+
export type GetNumbersError = never;
|
|
1182
|
+
"
|
|
1183
|
+
`;
|
|
1184
|
+
|
|
1185
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of numbers, booleans and dates 2`] = `
|
|
1186
|
+
"/**
|
|
1187
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1188
|
+
*/
|
|
1189
|
+
class $IO {
|
|
1190
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1191
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* Client configuration for TestApi
|
|
1196
|
+
*/
|
|
1197
|
+
export interface TestApiConfig {
|
|
1198
|
+
/**
|
|
1199
|
+
* Base URL for the API
|
|
1200
|
+
*/
|
|
1201
|
+
url: string;
|
|
1202
|
+
/**
|
|
1203
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1204
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1205
|
+
*/
|
|
1206
|
+
fetch?: typeof fetch;
|
|
1207
|
+
/**
|
|
1208
|
+
* Additional configuration
|
|
1209
|
+
*/
|
|
1210
|
+
options?: {
|
|
1211
|
+
/**
|
|
1212
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1213
|
+
* the request in the OpenAPI specification.
|
|
1214
|
+
* Set this to false to omit this header.
|
|
1215
|
+
*/
|
|
1216
|
+
omitContentTypeHeader?: boolean;
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* API Client for TestApi
|
|
1222
|
+
*/
|
|
1223
|
+
export class TestApi {
|
|
1224
|
+
private $config: TestApiConfig;
|
|
1225
|
+
|
|
1226
|
+
constructor(config: TestApiConfig) {
|
|
1227
|
+
this.$config = config;
|
|
1228
|
+
|
|
1229
|
+
this.getBooleans = this.getBooleans.bind(this);
|
|
1230
|
+
this.getDates = this.getDates.bind(this);
|
|
1231
|
+
this.getNumbers = this.getNumbers.bind(this);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
private $url = (
|
|
1235
|
+
path: string,
|
|
1236
|
+
pathParameters: { [key: string]: any },
|
|
1237
|
+
queryParameters: { [key: string]: any },
|
|
1238
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1239
|
+
): string => {
|
|
1240
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1241
|
+
? this.$config.url.slice(0, -1)
|
|
1242
|
+
: this.$config.url;
|
|
1243
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1244
|
+
(withParams, [key, value]) =>
|
|
1245
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
1246
|
+
path,
|
|
1247
|
+
);
|
|
1248
|
+
const queryString = Object.entries(queryParameters)
|
|
1249
|
+
.map(([key, value]) => {
|
|
1250
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1251
|
+
return value
|
|
1252
|
+
.map(
|
|
1253
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
1254
|
+
)
|
|
1255
|
+
.join('&');
|
|
1256
|
+
}
|
|
1257
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
1258
|
+
})
|
|
1259
|
+
.join('&');
|
|
1260
|
+
return (
|
|
1261
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1262
|
+
);
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
private $headers = (
|
|
1266
|
+
headerParameters: { [key: string]: any },
|
|
1267
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1268
|
+
): [string, string][] => {
|
|
1269
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1270
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1271
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1272
|
+
}
|
|
1273
|
+
return [[key, String(value)]];
|
|
1274
|
+
});
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1278
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1279
|
+
|
|
1280
|
+
public async *getBooleans(): AsyncIterableIterator<boolean> {
|
|
1281
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1282
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1283
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1284
|
+
|
|
1285
|
+
const body = undefined;
|
|
1286
|
+
|
|
1287
|
+
const response = await this.$fetch(
|
|
1288
|
+
this.$url('/test/booleans', pathParameters, queryParameters),
|
|
1289
|
+
{
|
|
1290
|
+
headers: this.$headers(headerParameters),
|
|
1291
|
+
method: 'GET',
|
|
1292
|
+
body,
|
|
1293
|
+
},
|
|
1294
|
+
);
|
|
1295
|
+
|
|
1296
|
+
if (response.status === 200) {
|
|
1297
|
+
const reader = response.body
|
|
1298
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1299
|
+
.getReader();
|
|
1300
|
+
while (reader) {
|
|
1301
|
+
const { value, done } = await reader.read();
|
|
1302
|
+
if (done) return;
|
|
1303
|
+
yield value === 'true' ? true : false;
|
|
1304
|
+
}
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
throw new Error(
|
|
1308
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
public async *getDates(): AsyncIterableIterator<Date> {
|
|
1313
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1314
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1315
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1316
|
+
|
|
1317
|
+
const body = undefined;
|
|
1318
|
+
|
|
1319
|
+
const response = await this.$fetch(
|
|
1320
|
+
this.$url('/test/dates', pathParameters, queryParameters),
|
|
1321
|
+
{
|
|
1322
|
+
headers: this.$headers(headerParameters),
|
|
1323
|
+
method: 'GET',
|
|
1324
|
+
body,
|
|
1325
|
+
},
|
|
1326
|
+
);
|
|
1327
|
+
|
|
1328
|
+
if (response.status === 200) {
|
|
1329
|
+
const reader = response.body
|
|
1330
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1331
|
+
.getReader();
|
|
1332
|
+
while (reader) {
|
|
1333
|
+
const { value, done } = await reader.read();
|
|
1334
|
+
if (done) return;
|
|
1335
|
+
yield new Date(value);
|
|
1336
|
+
}
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
throw new Error(
|
|
1340
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
public async *getNumbers(): AsyncIterableIterator<number> {
|
|
1345
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1346
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1347
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1348
|
+
|
|
1349
|
+
const body = undefined;
|
|
1350
|
+
|
|
1351
|
+
const response = await this.$fetch(
|
|
1352
|
+
this.$url('/test/numbers', pathParameters, queryParameters),
|
|
1353
|
+
{
|
|
1354
|
+
headers: this.$headers(headerParameters),
|
|
1355
|
+
method: 'GET',
|
|
1356
|
+
body,
|
|
1357
|
+
},
|
|
1358
|
+
);
|
|
1359
|
+
|
|
1360
|
+
if (response.status === 200) {
|
|
1361
|
+
const reader = response.body
|
|
1362
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1363
|
+
.getReader();
|
|
1364
|
+
while (reader) {
|
|
1365
|
+
const { value, done } = await reader.read();
|
|
1366
|
+
if (done) return;
|
|
1367
|
+
yield Number(value);
|
|
1368
|
+
}
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
throw new Error(
|
|
1372
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
"
|
|
1377
|
+
`;
|
|
1378
|
+
|
|
1379
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of objects 1`] = `
|
|
1380
|
+
"export type GetTest200Response = {
|
|
1381
|
+
foo: string;
|
|
1382
|
+
bar: number;
|
|
1383
|
+
};
|
|
1384
|
+
export type GetTestError = never;
|
|
1385
|
+
"
|
|
1386
|
+
`;
|
|
1387
|
+
|
|
1388
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of objects 2`] = `
|
|
1389
|
+
"import type { GetTest200Response } from './types.gen.js';
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1393
|
+
*/
|
|
1394
|
+
class $IO {
|
|
1395
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1396
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1397
|
+
|
|
1398
|
+
public static GetTest200Response = {
|
|
1399
|
+
toJson: (model: GetTest200Response): any => {
|
|
1400
|
+
if (model === undefined || model === null) {
|
|
1401
|
+
return model;
|
|
1402
|
+
}
|
|
1403
|
+
return {
|
|
1404
|
+
...(model.foo === undefined
|
|
1405
|
+
? {}
|
|
1406
|
+
: {
|
|
1407
|
+
foo: model.foo,
|
|
1408
|
+
}),
|
|
1409
|
+
...(model.bar === undefined
|
|
1410
|
+
? {}
|
|
1411
|
+
: {
|
|
1412
|
+
bar: model.bar,
|
|
1413
|
+
}),
|
|
1414
|
+
};
|
|
1415
|
+
},
|
|
1416
|
+
fromJson: (json: any): GetTest200Response => {
|
|
1417
|
+
if (json === undefined || json === null) {
|
|
1418
|
+
return json;
|
|
1419
|
+
}
|
|
1420
|
+
return {
|
|
1421
|
+
foo: json['foo'],
|
|
1422
|
+
bar: json['bar'],
|
|
1423
|
+
};
|
|
1424
|
+
},
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* Client configuration for TestApi
|
|
1430
|
+
*/
|
|
1431
|
+
export interface TestApiConfig {
|
|
1432
|
+
/**
|
|
1433
|
+
* Base URL for the API
|
|
1434
|
+
*/
|
|
1435
|
+
url: string;
|
|
1436
|
+
/**
|
|
1437
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1438
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1439
|
+
*/
|
|
1440
|
+
fetch?: typeof fetch;
|
|
1441
|
+
/**
|
|
1442
|
+
* Additional configuration
|
|
1443
|
+
*/
|
|
1444
|
+
options?: {
|
|
1445
|
+
/**
|
|
1446
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1447
|
+
* the request in the OpenAPI specification.
|
|
1448
|
+
* Set this to false to omit this header.
|
|
1449
|
+
*/
|
|
1450
|
+
omitContentTypeHeader?: boolean;
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* API Client for TestApi
|
|
1456
|
+
*/
|
|
1457
|
+
export class TestApi {
|
|
1458
|
+
private $config: TestApiConfig;
|
|
1459
|
+
|
|
1460
|
+
constructor(config: TestApiConfig) {
|
|
1461
|
+
this.$config = config;
|
|
1462
|
+
|
|
1463
|
+
this.getTest = this.getTest.bind(this);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
private $url = (
|
|
1467
|
+
path: string,
|
|
1468
|
+
pathParameters: { [key: string]: any },
|
|
1469
|
+
queryParameters: { [key: string]: any },
|
|
1470
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1471
|
+
): string => {
|
|
1472
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1473
|
+
? this.$config.url.slice(0, -1)
|
|
1474
|
+
: this.$config.url;
|
|
1475
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1476
|
+
(withParams, [key, value]) =>
|
|
1477
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
1478
|
+
path,
|
|
1479
|
+
);
|
|
1480
|
+
const queryString = Object.entries(queryParameters)
|
|
1481
|
+
.map(([key, value]) => {
|
|
1482
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1483
|
+
return value
|
|
1484
|
+
.map(
|
|
1485
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
1486
|
+
)
|
|
1487
|
+
.join('&');
|
|
1488
|
+
}
|
|
1489
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
1490
|
+
})
|
|
1491
|
+
.join('&');
|
|
1492
|
+
return (
|
|
1493
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1494
|
+
);
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
private $headers = (
|
|
1498
|
+
headerParameters: { [key: string]: any },
|
|
1499
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1500
|
+
): [string, string][] => {
|
|
1501
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1502
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1503
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1504
|
+
}
|
|
1505
|
+
return [[key, String(value)]];
|
|
1506
|
+
});
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1510
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1511
|
+
|
|
1512
|
+
public async *getTest(): AsyncIterableIterator<GetTest200Response> {
|
|
1513
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1514
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1515
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1516
|
+
|
|
1517
|
+
const body = undefined;
|
|
1518
|
+
|
|
1519
|
+
const response = await this.$fetch(
|
|
1520
|
+
this.$url('/test', pathParameters, queryParameters),
|
|
1521
|
+
{
|
|
1522
|
+
headers: this.$headers(headerParameters),
|
|
1523
|
+
method: 'GET',
|
|
1524
|
+
body,
|
|
1525
|
+
},
|
|
1526
|
+
);
|
|
1527
|
+
|
|
1528
|
+
if (response.status === 200) {
|
|
1529
|
+
const reader = response.body
|
|
1530
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1531
|
+
.getReader();
|
|
1532
|
+
while (reader) {
|
|
1533
|
+
const { value, done } = await reader.read();
|
|
1534
|
+
if (done) return;
|
|
1535
|
+
yield $IO.GetTest200Response.fromJson(JSON.parse(value));
|
|
1536
|
+
}
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
throw new Error(
|
|
1540
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
"
|
|
1545
|
+
`;
|
|
1546
|
+
|
|
1547
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of strings 1`] = `
|
|
1548
|
+
"export type GetTestError = never;
|
|
1549
|
+
"
|
|
1550
|
+
`;
|
|
1551
|
+
|
|
1552
|
+
exports[`openApiTsClientGenerator - streaming > should return an iterator over a stream of strings 2`] = `
|
|
1553
|
+
"/**
|
|
1554
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1555
|
+
*/
|
|
1556
|
+
class $IO {
|
|
1557
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1558
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
/**
|
|
1562
|
+
* Client configuration for TestApi
|
|
1563
|
+
*/
|
|
1564
|
+
export interface TestApiConfig {
|
|
1565
|
+
/**
|
|
1566
|
+
* Base URL for the API
|
|
1567
|
+
*/
|
|
1568
|
+
url: string;
|
|
1569
|
+
/**
|
|
1570
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1571
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1572
|
+
*/
|
|
1573
|
+
fetch?: typeof fetch;
|
|
1574
|
+
/**
|
|
1575
|
+
* Additional configuration
|
|
1576
|
+
*/
|
|
1577
|
+
options?: {
|
|
1578
|
+
/**
|
|
1579
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1580
|
+
* the request in the OpenAPI specification.
|
|
1581
|
+
* Set this to false to omit this header.
|
|
1582
|
+
*/
|
|
1583
|
+
omitContentTypeHeader?: boolean;
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* API Client for TestApi
|
|
1589
|
+
*/
|
|
1590
|
+
export class TestApi {
|
|
1591
|
+
private $config: TestApiConfig;
|
|
1592
|
+
|
|
1593
|
+
constructor(config: TestApiConfig) {
|
|
1594
|
+
this.$config = config;
|
|
1595
|
+
|
|
1596
|
+
this.getTest = this.getTest.bind(this);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
private $url = (
|
|
1600
|
+
path: string,
|
|
1601
|
+
pathParameters: { [key: string]: any },
|
|
1602
|
+
queryParameters: { [key: string]: any },
|
|
1603
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1604
|
+
): string => {
|
|
1605
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1606
|
+
? this.$config.url.slice(0, -1)
|
|
1607
|
+
: this.$config.url;
|
|
1608
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1609
|
+
(withParams, [key, value]) =>
|
|
1610
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
1611
|
+
path,
|
|
1612
|
+
);
|
|
1613
|
+
const queryString = Object.entries(queryParameters)
|
|
1614
|
+
.map(([key, value]) => {
|
|
1615
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1616
|
+
return value
|
|
1617
|
+
.map(
|
|
1618
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
1619
|
+
)
|
|
1620
|
+
.join('&');
|
|
1621
|
+
}
|
|
1622
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
1623
|
+
})
|
|
1624
|
+
.join('&');
|
|
1625
|
+
return (
|
|
1626
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1627
|
+
);
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
private $headers = (
|
|
1631
|
+
headerParameters: { [key: string]: any },
|
|
1632
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
1633
|
+
): [string, string][] => {
|
|
1634
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1635
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1636
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1637
|
+
}
|
|
1638
|
+
return [[key, String(value)]];
|
|
1639
|
+
});
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1642
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1643
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1644
|
+
|
|
1645
|
+
public async *getTest(): AsyncIterableIterator<string> {
|
|
1646
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1647
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1648
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1649
|
+
|
|
1650
|
+
const body = undefined;
|
|
1651
|
+
|
|
1652
|
+
const response = await this.$fetch(
|
|
1653
|
+
this.$url('/test', pathParameters, queryParameters),
|
|
1654
|
+
{
|
|
1655
|
+
headers: this.$headers(headerParameters),
|
|
1656
|
+
method: 'GET',
|
|
1657
|
+
body,
|
|
1658
|
+
},
|
|
1659
|
+
);
|
|
1660
|
+
|
|
1661
|
+
if (response.status === 200) {
|
|
1662
|
+
const reader = response.body
|
|
1663
|
+
?.pipeThrough(new TextDecoderStream())
|
|
1664
|
+
.getReader();
|
|
1665
|
+
while (reader) {
|
|
1666
|
+
const { value, done } = await reader.read();
|
|
1667
|
+
if (done) return;
|
|
1668
|
+
yield value;
|
|
1669
|
+
}
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
throw new Error(
|
|
1673
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
"
|
|
1678
|
+
`;
|