@aws/nx-plugin 0.14.2 → 0.15.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.
Files changed (34) hide show
  1. package/package.json +2 -2
  2. package/src/open-api/ts-client/__snapshots__/generator.additional-properties.spec.ts.snap +2236 -0
  3. package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +2307 -0
  4. package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +1495 -0
  5. package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +1470 -0
  6. package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +1138 -0
  7. package/src/open-api/ts-client/__snapshots__/generator.response.spec.ts.snap +732 -0
  8. package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +743 -0
  9. package/src/open-api/ts-client/files/client.gen.ts.template +52 -15
  10. package/src/open-api/ts-client/files/types.gen.ts.template +5 -0
  11. package/src/open-api/ts-hooks/__snapshots__/generator.spec.tsx.snap +1092 -0
  12. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +210 -0
  13. package/src/open-api/ts-hooks/generator.d.ts +5 -0
  14. package/src/open-api/ts-hooks/generator.js +15 -2
  15. package/src/open-api/ts-hooks/generator.js.map +1 -1
  16. package/src/open-api/ts-hooks/generator.spec.tsx +1787 -0
  17. package/src/open-api/utils/codegen-data/types.d.ts +25 -0
  18. package/src/open-api/utils/codegen-data/types.js +26 -1
  19. package/src/open-api/utils/codegen-data/types.js.map +1 -1
  20. package/src/open-api/utils/codegen-data.js +187 -79
  21. package/src/open-api/utils/codegen-data.js.map +1 -1
  22. package/src/open-api/utils/normalise.js +11 -1
  23. package/src/open-api/utils/normalise.js.map +1 -1
  24. package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +120 -10
  25. package/src/py/fast-api/react/files/website/components/__apiNameClassName__Provider.tsx.template +40 -0
  26. package/src/py/fast-api/react/files/website/hooks/use__apiNameClassName__.tsx.template +13 -18
  27. package/src/py/fast-api/react/files/website/hooks/use__apiNameClassName__Client.tsx.template +13 -0
  28. package/src/py/fast-api/react/generator.js +35 -9
  29. package/src/py/fast-api/react/generator.js.map +1 -1
  30. package/src/py/project/generator.js +5 -0
  31. package/src/py/project/generator.js.map +1 -1
  32. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +7 -9
  33. package/src/utils/files/http-api/common/constructs/src/core/http-api.ts.template +7 -9
  34. package/src/open-api/ts-client/__snapshots__/generator.spec.ts.snap +0 -7880
@@ -0,0 +1,2307 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`openApiTsClientGenerator - complex types > should generate valid TypeScript for arrays and dictionaries 1`] = `
4
+ "export type PostTest200ResponseItem = {
5
+ id: string;
6
+ tags?: Array<string>;
7
+ };
8
+ export type PostTestRequestContent = {
9
+ stringArray?: Array<string>;
10
+ numberArray?: Array<number>;
11
+ stringDict?: { [key: string]: string };
12
+ complexDict?: { [key: string]: PostTestRequestContentComplexDictValue };
13
+ };
14
+ export type PostTestRequestContentComplexDictValue = {
15
+ name: string;
16
+ value: number;
17
+ };
18
+
19
+ export type PostTestRequest = PostTestRequestContent | undefined;
20
+ export type PostTestError = never;
21
+ "
22
+ `;
23
+
24
+ exports[`openApiTsClientGenerator - complex types > should generate valid TypeScript for arrays and dictionaries 2`] = `
25
+ "import type {
26
+ PostTest200ResponseItem,
27
+ PostTestRequestContent,
28
+ PostTestRequestContentComplexDictValue,
29
+ PostTestRequest,
30
+ } from './types.gen.js';
31
+
32
+ /**
33
+ * Utility for serialisation and deserialisation of API types.
34
+ */
35
+ export class $IO {
36
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
37
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
38
+
39
+ public static PostTest200ResponseItem = {
40
+ toJson: (model: PostTest200ResponseItem): any => {
41
+ if (model === undefined || model === null) {
42
+ return model;
43
+ }
44
+ return {
45
+ ...(model.id === undefined
46
+ ? {}
47
+ : {
48
+ id: model.id,
49
+ }),
50
+ ...(model.tags === undefined
51
+ ? {}
52
+ : {
53
+ tags: model.tags,
54
+ }),
55
+ };
56
+ },
57
+ fromJson: (json: any): PostTest200ResponseItem => {
58
+ if (json === undefined || json === null) {
59
+ return json;
60
+ }
61
+ return {
62
+ id: json['id'],
63
+ ...(json['tags'] === undefined
64
+ ? {}
65
+ : {
66
+ tags: json['tags'],
67
+ }),
68
+ };
69
+ },
70
+ };
71
+
72
+ public static PostTestRequestContent = {
73
+ toJson: (model: PostTestRequestContent): any => {
74
+ if (model === undefined || model === null) {
75
+ return model;
76
+ }
77
+ return {
78
+ ...(model.stringArray === undefined
79
+ ? {}
80
+ : {
81
+ stringArray: model.stringArray,
82
+ }),
83
+ ...(model.numberArray === undefined
84
+ ? {}
85
+ : {
86
+ numberArray: model.numberArray,
87
+ }),
88
+ ...(model.stringDict === undefined
89
+ ? {}
90
+ : {
91
+ stringDict: model.stringDict,
92
+ }),
93
+ ...(model.complexDict === undefined
94
+ ? {}
95
+ : {
96
+ complexDict: $IO.$mapValues(
97
+ model.complexDict,
98
+ $IO.PostTestRequestContentComplexDictValue.toJson,
99
+ ),
100
+ }),
101
+ };
102
+ },
103
+ fromJson: (json: any): PostTestRequestContent => {
104
+ if (json === undefined || json === null) {
105
+ return json;
106
+ }
107
+ return {
108
+ ...(json['stringArray'] === undefined
109
+ ? {}
110
+ : {
111
+ stringArray: json['stringArray'],
112
+ }),
113
+ ...(json['numberArray'] === undefined
114
+ ? {}
115
+ : {
116
+ numberArray: json['numberArray'],
117
+ }),
118
+ ...(json['stringDict'] === undefined
119
+ ? {}
120
+ : {
121
+ stringDict: json['stringDict'],
122
+ }),
123
+ ...(json['complexDict'] === undefined
124
+ ? {}
125
+ : {
126
+ complexDict: $IO.$mapValues(
127
+ json['complexDict'],
128
+ $IO.PostTestRequestContentComplexDictValue.fromJson,
129
+ ),
130
+ }),
131
+ };
132
+ },
133
+ };
134
+
135
+ public static PostTestRequestContentComplexDictValue = {
136
+ toJson: (model: PostTestRequestContentComplexDictValue): any => {
137
+ if (model === undefined || model === null) {
138
+ return model;
139
+ }
140
+ return {
141
+ ...(model.name === undefined
142
+ ? {}
143
+ : {
144
+ name: model.name,
145
+ }),
146
+ ...(model.value === undefined
147
+ ? {}
148
+ : {
149
+ value: model.value,
150
+ }),
151
+ };
152
+ },
153
+ fromJson: (json: any): PostTestRequestContentComplexDictValue => {
154
+ if (json === undefined || json === null) {
155
+ return json;
156
+ }
157
+ return {
158
+ name: json['name'],
159
+ value: json['value'],
160
+ };
161
+ },
162
+ };
163
+ }
164
+
165
+ /**
166
+ * Client configuration for TestApi
167
+ */
168
+ export interface TestApiConfig {
169
+ /**
170
+ * Base URL for the API
171
+ */
172
+ url: string;
173
+ /**
174
+ * Custom instance of fetch. By default the global 'fetch' is used.
175
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
176
+ */
177
+ fetch?: typeof fetch;
178
+ /**
179
+ * Additional configuration
180
+ */
181
+ options?: {
182
+ /**
183
+ * By default, the client will add a Content-Type header, set to the media type defined for
184
+ * the request in the OpenAPI specification.
185
+ * Set this to false to omit this header.
186
+ */
187
+ omitContentTypeHeader?: boolean;
188
+ };
189
+ }
190
+
191
+ /**
192
+ * API Client for TestApi
193
+ */
194
+ export class TestApi {
195
+ private $config: TestApiConfig;
196
+
197
+ constructor(config: TestApiConfig) {
198
+ this.$config = config;
199
+
200
+ this.postTest = this.postTest.bind(this);
201
+ }
202
+
203
+ private $url = (
204
+ path: string,
205
+ pathParameters: { [key: string]: any },
206
+ queryParameters: { [key: string]: any },
207
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
208
+ ): string => {
209
+ const baseUrl = this.$config.url.endsWith('/')
210
+ ? this.$config.url.slice(0, -1)
211
+ : this.$config.url;
212
+ const pathWithParameters = Object.entries(pathParameters).reduce(
213
+ (withParams, [key, value]) =>
214
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
215
+ path,
216
+ );
217
+ const queryString = Object.entries(queryParameters)
218
+ .map(([key, value]) => {
219
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
220
+ return value
221
+ .map(
222
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
223
+ )
224
+ .join('&');
225
+ }
226
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
227
+ })
228
+ .join('&');
229
+ return (
230
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
231
+ );
232
+ };
233
+
234
+ private $headers = (
235
+ headerParameters: { [key: string]: any },
236
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
237
+ ): [string, string][] => {
238
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
239
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
240
+ return value.map((v) => [key, String(v)]) as [string, string][];
241
+ }
242
+ return [[key, String(value)]];
243
+ });
244
+ };
245
+
246
+ private $fetch: typeof fetch = (...args) =>
247
+ (this.$config.fetch ?? fetch)(...args);
248
+
249
+ public async postTest(
250
+ input?: PostTestRequest,
251
+ ): Promise<Array<PostTest200ResponseItem>> {
252
+ const pathParameters: { [key: string]: any } = {};
253
+ const queryParameters: { [key: string]: any } = {};
254
+ const headerParameters: { [key: string]: any } = {};
255
+ if (!this.$config.options?.omitContentTypeHeader) {
256
+ headerParameters['Content-Type'] = 'application/json';
257
+ }
258
+ const body =
259
+ input === undefined
260
+ ? undefined
261
+ : typeof input === 'object'
262
+ ? JSON.stringify($IO.PostTestRequestContent.toJson(input))
263
+ : String($IO.PostTestRequestContent.toJson(input));
264
+
265
+ const response = await this.$fetch(
266
+ this.$url('/test', pathParameters, queryParameters),
267
+ {
268
+ headers: this.$headers(headerParameters),
269
+ method: 'POST',
270
+ body,
271
+ },
272
+ );
273
+
274
+ if (response.status === 200) {
275
+ return ((await response.json()) as Array<any>).map(
276
+ $IO.PostTest200ResponseItem.fromJson,
277
+ );
278
+ }
279
+ throw new Error(
280
+ \`Unknown response status \${response.status} returned by API\`,
281
+ );
282
+ }
283
+ }
284
+ "
285
+ `;
286
+
287
+ exports[`openApiTsClientGenerator - complex types > should handle nullable schemas in various contexts 1`] = `
288
+ "export type PostSingleNullableObjectRequestContent = null | {
289
+ key?: string;
290
+ };
291
+ export type TestNullable200Response = {
292
+ nullableString?: string | null;
293
+ nullableNumber?: number | null;
294
+ nullableInteger?: number | null;
295
+ nullableBoolean?: boolean | null;
296
+ nullableArray?: Array<string> | null;
297
+ nullableObject?: TestNullable200ResponseNullableObject;
298
+ };
299
+ export type TestNullable200ResponseNullableObject = null | {
300
+ key?: string;
301
+ };
302
+ export type TestNullableRequestContent = {
303
+ nullableString?: string | null;
304
+ nullableNumber?: number | null;
305
+ nullableInteger?: number | null;
306
+ nullableBoolean?: boolean | null;
307
+ nullableArray?: Array<string> | null;
308
+ nullableObject?: TestNullableRequestContentNullableObject;
309
+ objectWithNullableProps?: TestNullableRequestContentObjectWithNullableProps;
310
+ };
311
+ export type TestNullableRequestContentNullableObject = null | {
312
+ key?: string;
313
+ };
314
+ export type TestNullableRequestContentObjectWithNullableProps = {
315
+ nullableString?: string | null;
316
+ nullableNumber?: number | null;
317
+ nullableInteger?: number | null;
318
+ nullableBoolean?: boolean | null;
319
+ nullableArray?: Array<string> | null;
320
+ nullableObject?: TestNullableRequestContentObjectWithNullablePropsNullableObject;
321
+ };
322
+ export type TestNullableRequestContentObjectWithNullablePropsNullableObject =
323
+ null | {
324
+ key?: string;
325
+ };
326
+ export type TestNullableRequestPathParameters = {
327
+ pathParam: string | null;
328
+ };
329
+ export type TestNullableRequestQueryParameters = {
330
+ queryString?: string | null;
331
+ queryNumber?: number | null;
332
+ queryInteger?: number | null;
333
+ queryBoolean?: boolean | null;
334
+ queryArray?: Array<string> | null;
335
+ queryObject?: unknown | null;
336
+ };
337
+
338
+ export type PostSingleNullableArrayRequest = Array<string> | undefined;
339
+ export type PostSingleNullableArrayError = never;
340
+
341
+ export type PostSingleNullableBooleanRequest = boolean | undefined;
342
+ export type PostSingleNullableBooleanError = never;
343
+
344
+ export type PostSingleNullableNumberRequest = number | undefined;
345
+ export type PostSingleNullableNumberError = never;
346
+
347
+ export type PostSingleNullableObjectRequest =
348
+ | PostSingleNullableObjectRequestContent
349
+ | undefined;
350
+ export type PostSingleNullableObjectError = never;
351
+
352
+ export type PostSingleNullableStringRequest = string | undefined;
353
+ export type PostSingleNullableStringError = never;
354
+
355
+ export type TestNullableRequest = TestNullableRequestPathParameters &
356
+ TestNullableRequestQueryParameters &
357
+ TestNullableRequestContent;
358
+ export type TestNullableError = never;
359
+ "
360
+ `;
361
+
362
+ exports[`openApiTsClientGenerator - complex types > should handle nullable schemas in various contexts 2`] = `
363
+ "import type {
364
+ PostSingleNullableObjectRequestContent,
365
+ TestNullable200Response,
366
+ TestNullable200ResponseNullableObject,
367
+ TestNullableRequestContent,
368
+ TestNullableRequestContentNullableObject,
369
+ TestNullableRequestContentObjectWithNullableProps,
370
+ TestNullableRequestContentObjectWithNullablePropsNullableObject,
371
+ TestNullableRequestPathParameters,
372
+ TestNullableRequestQueryParameters,
373
+ PostSingleNullableArrayRequest,
374
+ PostSingleNullableBooleanRequest,
375
+ PostSingleNullableNumberRequest,
376
+ PostSingleNullableObjectRequest,
377
+ PostSingleNullableStringRequest,
378
+ TestNullableRequest,
379
+ } from './types.gen.js';
380
+
381
+ /**
382
+ * Utility for serialisation and deserialisation of API types.
383
+ */
384
+ export class $IO {
385
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
386
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
387
+
388
+ public static PostSingleNullableObjectRequestContent = {
389
+ toJson: (model: PostSingleNullableObjectRequestContent): any => {
390
+ if (model === undefined || model === null) {
391
+ return model;
392
+ }
393
+ return {
394
+ ...(model.key === undefined
395
+ ? {}
396
+ : {
397
+ key: model.key,
398
+ }),
399
+ };
400
+ },
401
+ fromJson: (json: any): PostSingleNullableObjectRequestContent => {
402
+ if (json === undefined || json === null) {
403
+ return json;
404
+ }
405
+ return {
406
+ ...(json['key'] === undefined
407
+ ? {}
408
+ : {
409
+ key: json['key'],
410
+ }),
411
+ };
412
+ },
413
+ };
414
+
415
+ public static TestNullable200Response = {
416
+ toJson: (model: TestNullable200Response): any => {
417
+ if (model === undefined || model === null) {
418
+ return model;
419
+ }
420
+ return {
421
+ ...(model.nullableString === undefined
422
+ ? {}
423
+ : {
424
+ nullableString: model.nullableString,
425
+ }),
426
+ ...(model.nullableNumber === undefined
427
+ ? {}
428
+ : {
429
+ nullableNumber: model.nullableNumber,
430
+ }),
431
+ ...(model.nullableInteger === undefined
432
+ ? {}
433
+ : {
434
+ nullableInteger: model.nullableInteger,
435
+ }),
436
+ ...(model.nullableBoolean === undefined
437
+ ? {}
438
+ : {
439
+ nullableBoolean: model.nullableBoolean,
440
+ }),
441
+ ...(model.nullableArray === undefined
442
+ ? {}
443
+ : {
444
+ nullableArray:
445
+ model.nullableArray === null ? null : model.nullableArray,
446
+ }),
447
+ ...(model.nullableObject === undefined
448
+ ? {}
449
+ : {
450
+ nullableObject: $IO.TestNullable200ResponseNullableObject.toJson(
451
+ model.nullableObject,
452
+ ),
453
+ }),
454
+ };
455
+ },
456
+ fromJson: (json: any): TestNullable200Response => {
457
+ if (json === undefined || json === null) {
458
+ return json;
459
+ }
460
+ return {
461
+ ...(json['nullableString'] === undefined
462
+ ? {}
463
+ : {
464
+ nullableString:
465
+ json['nullableString'] === null ? null : json['nullableString'],
466
+ }),
467
+ ...(json['nullableNumber'] === undefined
468
+ ? {}
469
+ : {
470
+ nullableNumber:
471
+ json['nullableNumber'] === null ? null : json['nullableNumber'],
472
+ }),
473
+ ...(json['nullableInteger'] === undefined
474
+ ? {}
475
+ : {
476
+ nullableInteger:
477
+ json['nullableInteger'] === null
478
+ ? null
479
+ : json['nullableInteger'],
480
+ }),
481
+ ...(json['nullableBoolean'] === undefined
482
+ ? {}
483
+ : {
484
+ nullableBoolean:
485
+ json['nullableBoolean'] === null
486
+ ? null
487
+ : json['nullableBoolean'],
488
+ }),
489
+ ...(json['nullableArray'] === undefined
490
+ ? {}
491
+ : {
492
+ nullableArray:
493
+ json['nullableArray'] === null ? null : json['nullableArray'],
494
+ }),
495
+ ...(json['nullableObject'] === undefined
496
+ ? {}
497
+ : {
498
+ nullableObject:
499
+ $IO.TestNullable200ResponseNullableObject.fromJson(
500
+ json['nullableObject'],
501
+ ),
502
+ }),
503
+ };
504
+ },
505
+ };
506
+
507
+ public static TestNullable200ResponseNullableObject = {
508
+ toJson: (model: TestNullable200ResponseNullableObject): any => {
509
+ if (model === undefined || model === null) {
510
+ return model;
511
+ }
512
+ return {
513
+ ...(model.key === undefined
514
+ ? {}
515
+ : {
516
+ key: model.key,
517
+ }),
518
+ };
519
+ },
520
+ fromJson: (json: any): TestNullable200ResponseNullableObject => {
521
+ if (json === undefined || json === null) {
522
+ return json;
523
+ }
524
+ return {
525
+ ...(json['key'] === undefined
526
+ ? {}
527
+ : {
528
+ key: json['key'],
529
+ }),
530
+ };
531
+ },
532
+ };
533
+
534
+ public static TestNullableRequestContent = {
535
+ toJson: (model: TestNullableRequestContent): any => {
536
+ if (model === undefined || model === null) {
537
+ return model;
538
+ }
539
+ return {
540
+ ...(model.nullableString === undefined
541
+ ? {}
542
+ : {
543
+ nullableString: model.nullableString,
544
+ }),
545
+ ...(model.nullableNumber === undefined
546
+ ? {}
547
+ : {
548
+ nullableNumber: model.nullableNumber,
549
+ }),
550
+ ...(model.nullableInteger === undefined
551
+ ? {}
552
+ : {
553
+ nullableInteger: model.nullableInteger,
554
+ }),
555
+ ...(model.nullableBoolean === undefined
556
+ ? {}
557
+ : {
558
+ nullableBoolean: model.nullableBoolean,
559
+ }),
560
+ ...(model.nullableArray === undefined
561
+ ? {}
562
+ : {
563
+ nullableArray:
564
+ model.nullableArray === null ? null : model.nullableArray,
565
+ }),
566
+ ...(model.nullableObject === undefined
567
+ ? {}
568
+ : {
569
+ nullableObject:
570
+ $IO.TestNullableRequestContentNullableObject.toJson(
571
+ model.nullableObject,
572
+ ),
573
+ }),
574
+ ...(model.objectWithNullableProps === undefined
575
+ ? {}
576
+ : {
577
+ objectWithNullableProps:
578
+ $IO.TestNullableRequestContentObjectWithNullableProps.toJson(
579
+ model.objectWithNullableProps,
580
+ ),
581
+ }),
582
+ };
583
+ },
584
+ fromJson: (json: any): TestNullableRequestContent => {
585
+ if (json === undefined || json === null) {
586
+ return json;
587
+ }
588
+ return {
589
+ ...(json['nullableString'] === undefined
590
+ ? {}
591
+ : {
592
+ nullableString:
593
+ json['nullableString'] === null ? null : json['nullableString'],
594
+ }),
595
+ ...(json['nullableNumber'] === undefined
596
+ ? {}
597
+ : {
598
+ nullableNumber:
599
+ json['nullableNumber'] === null ? null : json['nullableNumber'],
600
+ }),
601
+ ...(json['nullableInteger'] === undefined
602
+ ? {}
603
+ : {
604
+ nullableInteger:
605
+ json['nullableInteger'] === null
606
+ ? null
607
+ : json['nullableInteger'],
608
+ }),
609
+ ...(json['nullableBoolean'] === undefined
610
+ ? {}
611
+ : {
612
+ nullableBoolean:
613
+ json['nullableBoolean'] === null
614
+ ? null
615
+ : json['nullableBoolean'],
616
+ }),
617
+ ...(json['nullableArray'] === undefined
618
+ ? {}
619
+ : {
620
+ nullableArray:
621
+ json['nullableArray'] === null ? null : json['nullableArray'],
622
+ }),
623
+ ...(json['nullableObject'] === undefined
624
+ ? {}
625
+ : {
626
+ nullableObject:
627
+ $IO.TestNullableRequestContentNullableObject.fromJson(
628
+ json['nullableObject'],
629
+ ),
630
+ }),
631
+ ...(json['objectWithNullableProps'] === undefined
632
+ ? {}
633
+ : {
634
+ objectWithNullableProps:
635
+ $IO.TestNullableRequestContentObjectWithNullableProps.fromJson(
636
+ json['objectWithNullableProps'],
637
+ ),
638
+ }),
639
+ };
640
+ },
641
+ };
642
+
643
+ public static TestNullableRequestContentNullableObject = {
644
+ toJson: (model: TestNullableRequestContentNullableObject): any => {
645
+ if (model === undefined || model === null) {
646
+ return model;
647
+ }
648
+ return {
649
+ ...(model.key === undefined
650
+ ? {}
651
+ : {
652
+ key: model.key,
653
+ }),
654
+ };
655
+ },
656
+ fromJson: (json: any): TestNullableRequestContentNullableObject => {
657
+ if (json === undefined || json === null) {
658
+ return json;
659
+ }
660
+ return {
661
+ ...(json['key'] === undefined
662
+ ? {}
663
+ : {
664
+ key: json['key'],
665
+ }),
666
+ };
667
+ },
668
+ };
669
+
670
+ public static TestNullableRequestContentObjectWithNullableProps = {
671
+ toJson: (model: TestNullableRequestContentObjectWithNullableProps): any => {
672
+ if (model === undefined || model === null) {
673
+ return model;
674
+ }
675
+ return {
676
+ ...(model.nullableString === undefined
677
+ ? {}
678
+ : {
679
+ nullableString: model.nullableString,
680
+ }),
681
+ ...(model.nullableNumber === undefined
682
+ ? {}
683
+ : {
684
+ nullableNumber: model.nullableNumber,
685
+ }),
686
+ ...(model.nullableInteger === undefined
687
+ ? {}
688
+ : {
689
+ nullableInteger: model.nullableInteger,
690
+ }),
691
+ ...(model.nullableBoolean === undefined
692
+ ? {}
693
+ : {
694
+ nullableBoolean: model.nullableBoolean,
695
+ }),
696
+ ...(model.nullableArray === undefined
697
+ ? {}
698
+ : {
699
+ nullableArray:
700
+ model.nullableArray === null ? null : model.nullableArray,
701
+ }),
702
+ ...(model.nullableObject === undefined
703
+ ? {}
704
+ : {
705
+ nullableObject:
706
+ $IO.TestNullableRequestContentObjectWithNullablePropsNullableObject.toJson(
707
+ model.nullableObject,
708
+ ),
709
+ }),
710
+ };
711
+ },
712
+ fromJson: (
713
+ json: any,
714
+ ): TestNullableRequestContentObjectWithNullableProps => {
715
+ if (json === undefined || json === null) {
716
+ return json;
717
+ }
718
+ return {
719
+ ...(json['nullableString'] === undefined
720
+ ? {}
721
+ : {
722
+ nullableString:
723
+ json['nullableString'] === null ? null : json['nullableString'],
724
+ }),
725
+ ...(json['nullableNumber'] === undefined
726
+ ? {}
727
+ : {
728
+ nullableNumber:
729
+ json['nullableNumber'] === null ? null : json['nullableNumber'],
730
+ }),
731
+ ...(json['nullableInteger'] === undefined
732
+ ? {}
733
+ : {
734
+ nullableInteger:
735
+ json['nullableInteger'] === null
736
+ ? null
737
+ : json['nullableInteger'],
738
+ }),
739
+ ...(json['nullableBoolean'] === undefined
740
+ ? {}
741
+ : {
742
+ nullableBoolean:
743
+ json['nullableBoolean'] === null
744
+ ? null
745
+ : json['nullableBoolean'],
746
+ }),
747
+ ...(json['nullableArray'] === undefined
748
+ ? {}
749
+ : {
750
+ nullableArray:
751
+ json['nullableArray'] === null ? null : json['nullableArray'],
752
+ }),
753
+ ...(json['nullableObject'] === undefined
754
+ ? {}
755
+ : {
756
+ nullableObject:
757
+ $IO.TestNullableRequestContentObjectWithNullablePropsNullableObject.fromJson(
758
+ json['nullableObject'],
759
+ ),
760
+ }),
761
+ };
762
+ },
763
+ };
764
+
765
+ public static TestNullableRequestContentObjectWithNullablePropsNullableObject =
766
+ {
767
+ toJson: (
768
+ model: TestNullableRequestContentObjectWithNullablePropsNullableObject,
769
+ ): any => {
770
+ if (model === undefined || model === null) {
771
+ return model;
772
+ }
773
+ return {
774
+ ...(model.key === undefined
775
+ ? {}
776
+ : {
777
+ key: model.key,
778
+ }),
779
+ };
780
+ },
781
+ fromJson: (
782
+ json: any,
783
+ ): TestNullableRequestContentObjectWithNullablePropsNullableObject => {
784
+ if (json === undefined || json === null) {
785
+ return json;
786
+ }
787
+ return {
788
+ ...(json['key'] === undefined
789
+ ? {}
790
+ : {
791
+ key: json['key'],
792
+ }),
793
+ };
794
+ },
795
+ };
796
+
797
+ public static TestNullableRequestPathParameters = {
798
+ toJson: (model: TestNullableRequestPathParameters): any => {
799
+ if (model === undefined || model === null) {
800
+ return model;
801
+ }
802
+ return {
803
+ ...(model.pathParam === undefined
804
+ ? {}
805
+ : {
806
+ pathParam: model.pathParam,
807
+ }),
808
+ };
809
+ },
810
+ fromJson: (json: any): TestNullableRequestPathParameters => {
811
+ if (json === undefined || json === null) {
812
+ return json;
813
+ }
814
+ return {
815
+ pathParam: json['pathParam'] === null ? null : json['pathParam'],
816
+ };
817
+ },
818
+ };
819
+
820
+ public static TestNullableRequestQueryParameters = {
821
+ toJson: (model: TestNullableRequestQueryParameters): any => {
822
+ if (model === undefined || model === null) {
823
+ return model;
824
+ }
825
+ return {
826
+ ...(model.queryString === undefined
827
+ ? {}
828
+ : {
829
+ queryString: model.queryString,
830
+ }),
831
+ ...(model.queryNumber === undefined
832
+ ? {}
833
+ : {
834
+ queryNumber: model.queryNumber,
835
+ }),
836
+ ...(model.queryInteger === undefined
837
+ ? {}
838
+ : {
839
+ queryInteger: model.queryInteger,
840
+ }),
841
+ ...(model.queryBoolean === undefined
842
+ ? {}
843
+ : {
844
+ queryBoolean: model.queryBoolean,
845
+ }),
846
+ ...(model.queryArray === undefined
847
+ ? {}
848
+ : {
849
+ queryArray: model.queryArray === null ? null : model.queryArray,
850
+ }),
851
+ ...(model.queryObject === undefined
852
+ ? {}
853
+ : {
854
+ queryObject: model.queryObject,
855
+ }),
856
+ };
857
+ },
858
+ fromJson: (json: any): TestNullableRequestQueryParameters => {
859
+ if (json === undefined || json === null) {
860
+ return json;
861
+ }
862
+ return {
863
+ ...(json['queryString'] === undefined
864
+ ? {}
865
+ : {
866
+ queryString:
867
+ json['queryString'] === null ? null : json['queryString'],
868
+ }),
869
+ ...(json['queryNumber'] === undefined
870
+ ? {}
871
+ : {
872
+ queryNumber:
873
+ json['queryNumber'] === null ? null : json['queryNumber'],
874
+ }),
875
+ ...(json['queryInteger'] === undefined
876
+ ? {}
877
+ : {
878
+ queryInteger:
879
+ json['queryInteger'] === null ? null : json['queryInteger'],
880
+ }),
881
+ ...(json['queryBoolean'] === undefined
882
+ ? {}
883
+ : {
884
+ queryBoolean:
885
+ json['queryBoolean'] === null ? null : json['queryBoolean'],
886
+ }),
887
+ ...(json['queryArray'] === undefined
888
+ ? {}
889
+ : {
890
+ queryArray:
891
+ json['queryArray'] === null ? null : json['queryArray'],
892
+ }),
893
+ ...(json['queryObject'] === undefined
894
+ ? {}
895
+ : {
896
+ queryObject:
897
+ json['queryObject'] === null ? null : json['queryObject'],
898
+ }),
899
+ };
900
+ },
901
+ };
902
+ }
903
+
904
+ /**
905
+ * Client configuration for TestApi
906
+ */
907
+ export interface TestApiConfig {
908
+ /**
909
+ * Base URL for the API
910
+ */
911
+ url: string;
912
+ /**
913
+ * Custom instance of fetch. By default the global 'fetch' is used.
914
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
915
+ */
916
+ fetch?: typeof fetch;
917
+ /**
918
+ * Additional configuration
919
+ */
920
+ options?: {
921
+ /**
922
+ * By default, the client will add a Content-Type header, set to the media type defined for
923
+ * the request in the OpenAPI specification.
924
+ * Set this to false to omit this header.
925
+ */
926
+ omitContentTypeHeader?: boolean;
927
+ };
928
+ }
929
+
930
+ /**
931
+ * API Client for TestApi
932
+ */
933
+ export class TestApi {
934
+ private $config: TestApiConfig;
935
+
936
+ constructor(config: TestApiConfig) {
937
+ this.$config = config;
938
+
939
+ this.postSingleNullableArray = this.postSingleNullableArray.bind(this);
940
+ this.postSingleNullableBoolean = this.postSingleNullableBoolean.bind(this);
941
+ this.postSingleNullableNumber = this.postSingleNullableNumber.bind(this);
942
+ this.postSingleNullableObject = this.postSingleNullableObject.bind(this);
943
+ this.postSingleNullableString = this.postSingleNullableString.bind(this);
944
+ this.testNullable = this.testNullable.bind(this);
945
+ }
946
+
947
+ private $url = (
948
+ path: string,
949
+ pathParameters: { [key: string]: any },
950
+ queryParameters: { [key: string]: any },
951
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
952
+ ): string => {
953
+ const baseUrl = this.$config.url.endsWith('/')
954
+ ? this.$config.url.slice(0, -1)
955
+ : this.$config.url;
956
+ const pathWithParameters = Object.entries(pathParameters).reduce(
957
+ (withParams, [key, value]) =>
958
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
959
+ path,
960
+ );
961
+ const queryString = Object.entries(queryParameters)
962
+ .map(([key, value]) => {
963
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
964
+ return value
965
+ .map(
966
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
967
+ )
968
+ .join('&');
969
+ }
970
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
971
+ })
972
+ .join('&');
973
+ return (
974
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
975
+ );
976
+ };
977
+
978
+ private $headers = (
979
+ headerParameters: { [key: string]: any },
980
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
981
+ ): [string, string][] => {
982
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
983
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
984
+ return value.map((v) => [key, String(v)]) as [string, string][];
985
+ }
986
+ return [[key, String(value)]];
987
+ });
988
+ };
989
+
990
+ private $fetch: typeof fetch = (...args) =>
991
+ (this.$config.fetch ?? fetch)(...args);
992
+
993
+ public async postSingleNullableArray(
994
+ input?: PostSingleNullableArrayRequest,
995
+ ): Promise<string> {
996
+ const pathParameters: { [key: string]: any } = {};
997
+ const queryParameters: { [key: string]: any } = {};
998
+ const headerParameters: { [key: string]: any } = {};
999
+ if (!this.$config.options?.omitContentTypeHeader) {
1000
+ headerParameters['Content-Type'] = 'application/json';
1001
+ }
1002
+ const body =
1003
+ input === undefined
1004
+ ? undefined
1005
+ : typeof input === 'object'
1006
+ ? JSON.stringify(input === null ? null : input)
1007
+ : String(input === null ? null : input);
1008
+
1009
+ const response = await this.$fetch(
1010
+ this.$url('/single-nullable-array', pathParameters, queryParameters),
1011
+ {
1012
+ headers: this.$headers(headerParameters),
1013
+ method: 'POST',
1014
+ body,
1015
+ },
1016
+ );
1017
+
1018
+ if (response.status === 200) {
1019
+ return await response.text();
1020
+ }
1021
+ throw new Error(
1022
+ \`Unknown response status \${response.status} returned by API\`,
1023
+ );
1024
+ }
1025
+
1026
+ public async postSingleNullableBoolean(
1027
+ input?: PostSingleNullableBooleanRequest,
1028
+ ): Promise<string> {
1029
+ const pathParameters: { [key: string]: any } = {};
1030
+ const queryParameters: { [key: string]: any } = {};
1031
+ const headerParameters: { [key: string]: any } = {};
1032
+ if (!this.$config.options?.omitContentTypeHeader) {
1033
+ headerParameters['Content-Type'] = 'application/json';
1034
+ }
1035
+ const body = input === undefined ? undefined : String(input);
1036
+
1037
+ const response = await this.$fetch(
1038
+ this.$url('/single-nullable-boolean', pathParameters, queryParameters),
1039
+ {
1040
+ headers: this.$headers(headerParameters),
1041
+ method: 'POST',
1042
+ body,
1043
+ },
1044
+ );
1045
+
1046
+ if (response.status === 200) {
1047
+ return await response.text();
1048
+ }
1049
+ throw new Error(
1050
+ \`Unknown response status \${response.status} returned by API\`,
1051
+ );
1052
+ }
1053
+
1054
+ public async postSingleNullableNumber(
1055
+ input?: PostSingleNullableNumberRequest,
1056
+ ): Promise<string> {
1057
+ const pathParameters: { [key: string]: any } = {};
1058
+ const queryParameters: { [key: string]: any } = {};
1059
+ const headerParameters: { [key: string]: any } = {};
1060
+ if (!this.$config.options?.omitContentTypeHeader) {
1061
+ headerParameters['Content-Type'] = 'application/json';
1062
+ }
1063
+ const body = input === undefined ? undefined : String(input);
1064
+
1065
+ const response = await this.$fetch(
1066
+ this.$url('/single-nullable-number', pathParameters, queryParameters),
1067
+ {
1068
+ headers: this.$headers(headerParameters),
1069
+ method: 'POST',
1070
+ body,
1071
+ },
1072
+ );
1073
+
1074
+ if (response.status === 200) {
1075
+ return await response.text();
1076
+ }
1077
+ throw new Error(
1078
+ \`Unknown response status \${response.status} returned by API\`,
1079
+ );
1080
+ }
1081
+
1082
+ public async postSingleNullableObject(
1083
+ input?: PostSingleNullableObjectRequest,
1084
+ ): Promise<string> {
1085
+ const pathParameters: { [key: string]: any } = {};
1086
+ const queryParameters: { [key: string]: any } = {};
1087
+ const headerParameters: { [key: string]: any } = {};
1088
+ if (!this.$config.options?.omitContentTypeHeader) {
1089
+ headerParameters['Content-Type'] = 'application/json';
1090
+ }
1091
+ const body =
1092
+ input === undefined
1093
+ ? undefined
1094
+ : typeof input === 'object'
1095
+ ? JSON.stringify(
1096
+ $IO.PostSingleNullableObjectRequestContent.toJson(input),
1097
+ )
1098
+ : String($IO.PostSingleNullableObjectRequestContent.toJson(input));
1099
+
1100
+ const response = await this.$fetch(
1101
+ this.$url('/single-nullable-object', pathParameters, queryParameters),
1102
+ {
1103
+ headers: this.$headers(headerParameters),
1104
+ method: 'POST',
1105
+ body,
1106
+ },
1107
+ );
1108
+
1109
+ if (response.status === 200) {
1110
+ return await response.text();
1111
+ }
1112
+ throw new Error(
1113
+ \`Unknown response status \${response.status} returned by API\`,
1114
+ );
1115
+ }
1116
+
1117
+ public async postSingleNullableString(
1118
+ input?: PostSingleNullableStringRequest,
1119
+ ): Promise<string> {
1120
+ const pathParameters: { [key: string]: any } = {};
1121
+ const queryParameters: { [key: string]: any } = {};
1122
+ const headerParameters: { [key: string]: any } = {};
1123
+ if (!this.$config.options?.omitContentTypeHeader) {
1124
+ headerParameters['Content-Type'] = 'application/json';
1125
+ }
1126
+ const body = input === undefined ? undefined : String(input);
1127
+
1128
+ const response = await this.$fetch(
1129
+ this.$url('/single-nullable-string', pathParameters, queryParameters),
1130
+ {
1131
+ headers: this.$headers(headerParameters),
1132
+ method: 'POST',
1133
+ body,
1134
+ },
1135
+ );
1136
+
1137
+ if (response.status === 200) {
1138
+ return await response.text();
1139
+ }
1140
+ throw new Error(
1141
+ \`Unknown response status \${response.status} returned by API\`,
1142
+ );
1143
+ }
1144
+
1145
+ public async testNullable(
1146
+ input: TestNullableRequest,
1147
+ ): Promise<TestNullable200Response> {
1148
+ const pathParameters: { [key: string]: any } =
1149
+ $IO.TestNullableRequestPathParameters.toJson(input);
1150
+ const queryParameters: { [key: string]: any } =
1151
+ $IO.TestNullableRequestQueryParameters.toJson(input);
1152
+ const headerParameters: { [key: string]: any } = {};
1153
+ if (!this.$config.options?.omitContentTypeHeader) {
1154
+ headerParameters['Content-Type'] = 'application/json';
1155
+ }
1156
+ const collectionFormats = {
1157
+ queryString: 'multi',
1158
+ queryNumber: 'multi',
1159
+ queryInteger: 'multi',
1160
+ queryBoolean: 'multi',
1161
+ queryArray: 'multi',
1162
+ queryObject: 'multi',
1163
+ } as const;
1164
+ const body =
1165
+ input === undefined
1166
+ ? undefined
1167
+ : typeof input === 'object'
1168
+ ? JSON.stringify($IO.TestNullableRequestContent.toJson(input))
1169
+ : String($IO.TestNullableRequestContent.toJson(input));
1170
+
1171
+ const response = await this.$fetch(
1172
+ this.$url(
1173
+ '/test/{pathParam}',
1174
+ pathParameters,
1175
+ queryParameters,
1176
+ collectionFormats,
1177
+ ),
1178
+ {
1179
+ headers: this.$headers(headerParameters, collectionFormats),
1180
+ method: 'POST',
1181
+ body,
1182
+ },
1183
+ );
1184
+
1185
+ if (response.status === 200) {
1186
+ return $IO.TestNullable200Response.fromJson(await response.json());
1187
+ }
1188
+ throw new Error(
1189
+ \`Unknown response status \${response.status} returned by API\`,
1190
+ );
1191
+ }
1192
+ }
1193
+ "
1194
+ `;
1195
+
1196
+ exports[`openApiTsClientGenerator - complex types > should handle operations with complex map types 1`] = `
1197
+ "export type PostMapOfArraysOfObjectsRequestContent = {
1198
+ [key: string]: Array<PostMapOfArraysOfObjectsRequestContentValueItem>;
1199
+ };
1200
+ export type PostMapOfArraysOfObjectsRequestContentValueItem = {
1201
+ name: string;
1202
+ value: number;
1203
+ };
1204
+ export type PostMapOfMapsOfArraysOfNumbersRequestContent = {
1205
+ [key: string]: { [key: string]: Array<number> };
1206
+ };
1207
+ export type PostMapOfMapsOfNumbersRequestContent = {
1208
+ [key: string]: { [key: string]: number };
1209
+ };
1210
+ export type PostMapOfNumbersRequestContent = {
1211
+ [key: string]: number;
1212
+ };
1213
+ export type PostMapOfObjectsRequestContent = {
1214
+ [key: string]: PostMapOfObjectsRequestContentValue;
1215
+ };
1216
+ export type PostMapOfObjectsRequestContentValue = {
1217
+ name: string;
1218
+ value: number;
1219
+ };
1220
+
1221
+ export type PostArrayOfMapsOfArraysOfNumbersRequest =
1222
+ | Array<{ [key: string]: Array<number> }>
1223
+ | undefined;
1224
+ export type PostArrayOfMapsOfArraysOfNumbersError = never;
1225
+
1226
+ export type PostArrayOfMapsOfNumbersRequest =
1227
+ | Array<{ [key: string]: number }>
1228
+ | undefined;
1229
+ export type PostArrayOfMapsOfNumbersError = never;
1230
+
1231
+ export type PostMapOfArraysOfObjectsRequest =
1232
+ | PostMapOfArraysOfObjectsRequestContent
1233
+ | undefined;
1234
+ export type PostMapOfArraysOfObjectsError = never;
1235
+
1236
+ export type PostMapOfMapsOfArraysOfNumbersRequest =
1237
+ | PostMapOfMapsOfArraysOfNumbersRequestContent
1238
+ | undefined;
1239
+ export type PostMapOfMapsOfArraysOfNumbersError = never;
1240
+
1241
+ export type PostMapOfMapsOfNumbersRequest =
1242
+ | PostMapOfMapsOfNumbersRequestContent
1243
+ | undefined;
1244
+ export type PostMapOfMapsOfNumbersError = never;
1245
+
1246
+ export type PostMapOfNumbersRequest =
1247
+ | PostMapOfNumbersRequestContent
1248
+ | undefined;
1249
+ export type PostMapOfNumbersError = never;
1250
+
1251
+ export type PostMapOfObjectsRequest =
1252
+ | PostMapOfObjectsRequestContent
1253
+ | undefined;
1254
+ export type PostMapOfObjectsError = never;
1255
+ "
1256
+ `;
1257
+
1258
+ exports[`openApiTsClientGenerator - complex types > should handle operations with complex map types 2`] = `
1259
+ "import type {
1260
+ PostMapOfArraysOfObjectsRequestContent,
1261
+ PostMapOfArraysOfObjectsRequestContentValueItem,
1262
+ PostMapOfMapsOfArraysOfNumbersRequestContent,
1263
+ PostMapOfMapsOfNumbersRequestContent,
1264
+ PostMapOfNumbersRequestContent,
1265
+ PostMapOfObjectsRequestContent,
1266
+ PostMapOfObjectsRequestContentValue,
1267
+ PostArrayOfMapsOfArraysOfNumbersRequest,
1268
+ PostArrayOfMapsOfNumbersRequest,
1269
+ PostMapOfArraysOfObjectsRequest,
1270
+ PostMapOfMapsOfArraysOfNumbersRequest,
1271
+ PostMapOfMapsOfNumbersRequest,
1272
+ PostMapOfNumbersRequest,
1273
+ PostMapOfObjectsRequest,
1274
+ } from './types.gen.js';
1275
+
1276
+ /**
1277
+ * Utility for serialisation and deserialisation of API types.
1278
+ */
1279
+ export class $IO {
1280
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
1281
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
1282
+
1283
+ public static PostMapOfArraysOfObjectsRequestContent = {
1284
+ toJson: (model: PostMapOfArraysOfObjectsRequestContent): any => {
1285
+ if (model === undefined || model === null) {
1286
+ return model;
1287
+ }
1288
+ return {
1289
+ ...$IO.$mapValues(model, (item0) =>
1290
+ item0.map($IO.PostMapOfArraysOfObjectsRequestContentValueItem.toJson),
1291
+ ),
1292
+ };
1293
+ },
1294
+ fromJson: (json: any): PostMapOfArraysOfObjectsRequestContent => {
1295
+ if (json === undefined || json === null) {
1296
+ return json;
1297
+ }
1298
+ return {
1299
+ ...$IO.$mapValues(json, (item0) =>
1300
+ item0.map(
1301
+ $IO.PostMapOfArraysOfObjectsRequestContentValueItem.fromJson,
1302
+ ),
1303
+ ),
1304
+ };
1305
+ },
1306
+ };
1307
+
1308
+ public static PostMapOfArraysOfObjectsRequestContentValueItem = {
1309
+ toJson: (model: PostMapOfArraysOfObjectsRequestContentValueItem): any => {
1310
+ if (model === undefined || model === null) {
1311
+ return model;
1312
+ }
1313
+ return {
1314
+ ...(model.name === undefined
1315
+ ? {}
1316
+ : {
1317
+ name: model.name,
1318
+ }),
1319
+ ...(model.value === undefined
1320
+ ? {}
1321
+ : {
1322
+ value: model.value,
1323
+ }),
1324
+ };
1325
+ },
1326
+ fromJson: (json: any): PostMapOfArraysOfObjectsRequestContentValueItem => {
1327
+ if (json === undefined || json === null) {
1328
+ return json;
1329
+ }
1330
+ return {
1331
+ name: json['name'],
1332
+ value: json['value'],
1333
+ };
1334
+ },
1335
+ };
1336
+
1337
+ public static PostMapOfMapsOfArraysOfNumbersRequestContent = {
1338
+ toJson: (model: PostMapOfMapsOfArraysOfNumbersRequestContent): any => {
1339
+ if (model === undefined || model === null) {
1340
+ return model;
1341
+ }
1342
+ return {
1343
+ ...model,
1344
+ };
1345
+ },
1346
+ fromJson: (json: any): PostMapOfMapsOfArraysOfNumbersRequestContent => {
1347
+ if (json === undefined || json === null) {
1348
+ return json;
1349
+ }
1350
+ return {
1351
+ ...json,
1352
+ };
1353
+ },
1354
+ };
1355
+
1356
+ public static PostMapOfMapsOfNumbersRequestContent = {
1357
+ toJson: (model: PostMapOfMapsOfNumbersRequestContent): any => {
1358
+ if (model === undefined || model === null) {
1359
+ return model;
1360
+ }
1361
+ return {
1362
+ ...model,
1363
+ };
1364
+ },
1365
+ fromJson: (json: any): PostMapOfMapsOfNumbersRequestContent => {
1366
+ if (json === undefined || json === null) {
1367
+ return json;
1368
+ }
1369
+ return {
1370
+ ...json,
1371
+ };
1372
+ },
1373
+ };
1374
+
1375
+ public static PostMapOfNumbersRequestContent = {
1376
+ toJson: (model: PostMapOfNumbersRequestContent): any => {
1377
+ if (model === undefined || model === null) {
1378
+ return model;
1379
+ }
1380
+ return {
1381
+ ...model,
1382
+ };
1383
+ },
1384
+ fromJson: (json: any): PostMapOfNumbersRequestContent => {
1385
+ if (json === undefined || json === null) {
1386
+ return json;
1387
+ }
1388
+ return {
1389
+ ...json,
1390
+ };
1391
+ },
1392
+ };
1393
+
1394
+ public static PostMapOfObjectsRequestContent = {
1395
+ toJson: (model: PostMapOfObjectsRequestContent): any => {
1396
+ if (model === undefined || model === null) {
1397
+ return model;
1398
+ }
1399
+ return {
1400
+ ...$IO.$mapValues(
1401
+ model,
1402
+ $IO.PostMapOfObjectsRequestContentValue.toJson,
1403
+ ),
1404
+ };
1405
+ },
1406
+ fromJson: (json: any): PostMapOfObjectsRequestContent => {
1407
+ if (json === undefined || json === null) {
1408
+ return json;
1409
+ }
1410
+ return {
1411
+ ...$IO.$mapValues(
1412
+ json,
1413
+ $IO.PostMapOfObjectsRequestContentValue.fromJson,
1414
+ ),
1415
+ };
1416
+ },
1417
+ };
1418
+
1419
+ public static PostMapOfObjectsRequestContentValue = {
1420
+ toJson: (model: PostMapOfObjectsRequestContentValue): any => {
1421
+ if (model === undefined || model === null) {
1422
+ return model;
1423
+ }
1424
+ return {
1425
+ ...(model.name === undefined
1426
+ ? {}
1427
+ : {
1428
+ name: model.name,
1429
+ }),
1430
+ ...(model.value === undefined
1431
+ ? {}
1432
+ : {
1433
+ value: model.value,
1434
+ }),
1435
+ };
1436
+ },
1437
+ fromJson: (json: any): PostMapOfObjectsRequestContentValue => {
1438
+ if (json === undefined || json === null) {
1439
+ return json;
1440
+ }
1441
+ return {
1442
+ name: json['name'],
1443
+ value: json['value'],
1444
+ };
1445
+ },
1446
+ };
1447
+ }
1448
+
1449
+ /**
1450
+ * Client configuration for TestApi
1451
+ */
1452
+ export interface TestApiConfig {
1453
+ /**
1454
+ * Base URL for the API
1455
+ */
1456
+ url: string;
1457
+ /**
1458
+ * Custom instance of fetch. By default the global 'fetch' is used.
1459
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
1460
+ */
1461
+ fetch?: typeof fetch;
1462
+ /**
1463
+ * Additional configuration
1464
+ */
1465
+ options?: {
1466
+ /**
1467
+ * By default, the client will add a Content-Type header, set to the media type defined for
1468
+ * the request in the OpenAPI specification.
1469
+ * Set this to false to omit this header.
1470
+ */
1471
+ omitContentTypeHeader?: boolean;
1472
+ };
1473
+ }
1474
+
1475
+ /**
1476
+ * API Client for TestApi
1477
+ */
1478
+ export class TestApi {
1479
+ private $config: TestApiConfig;
1480
+
1481
+ constructor(config: TestApiConfig) {
1482
+ this.$config = config;
1483
+
1484
+ this.postArrayOfMapsOfArraysOfNumbers =
1485
+ this.postArrayOfMapsOfArraysOfNumbers.bind(this);
1486
+ this.postArrayOfMapsOfNumbers = this.postArrayOfMapsOfNumbers.bind(this);
1487
+ this.postMapOfArraysOfObjects = this.postMapOfArraysOfObjects.bind(this);
1488
+ this.postMapOfMapsOfArraysOfNumbers =
1489
+ this.postMapOfMapsOfArraysOfNumbers.bind(this);
1490
+ this.postMapOfMapsOfNumbers = this.postMapOfMapsOfNumbers.bind(this);
1491
+ this.postMapOfNumbers = this.postMapOfNumbers.bind(this);
1492
+ this.postMapOfObjects = this.postMapOfObjects.bind(this);
1493
+ }
1494
+
1495
+ private $url = (
1496
+ path: string,
1497
+ pathParameters: { [key: string]: any },
1498
+ queryParameters: { [key: string]: any },
1499
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
1500
+ ): string => {
1501
+ const baseUrl = this.$config.url.endsWith('/')
1502
+ ? this.$config.url.slice(0, -1)
1503
+ : this.$config.url;
1504
+ const pathWithParameters = Object.entries(pathParameters).reduce(
1505
+ (withParams, [key, value]) =>
1506
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
1507
+ path,
1508
+ );
1509
+ const queryString = Object.entries(queryParameters)
1510
+ .map(([key, value]) => {
1511
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
1512
+ return value
1513
+ .map(
1514
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
1515
+ )
1516
+ .join('&');
1517
+ }
1518
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
1519
+ })
1520
+ .join('&');
1521
+ return (
1522
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
1523
+ );
1524
+ };
1525
+
1526
+ private $headers = (
1527
+ headerParameters: { [key: string]: any },
1528
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
1529
+ ): [string, string][] => {
1530
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
1531
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
1532
+ return value.map((v) => [key, String(v)]) as [string, string][];
1533
+ }
1534
+ return [[key, String(value)]];
1535
+ });
1536
+ };
1537
+
1538
+ private $fetch: typeof fetch = (...args) =>
1539
+ (this.$config.fetch ?? fetch)(...args);
1540
+
1541
+ public async postArrayOfMapsOfArraysOfNumbers(
1542
+ input?: PostArrayOfMapsOfArraysOfNumbersRequest,
1543
+ ): Promise<string> {
1544
+ const pathParameters: { [key: string]: any } = {};
1545
+ const queryParameters: { [key: string]: any } = {};
1546
+ const headerParameters: { [key: string]: any } = {};
1547
+ if (!this.$config.options?.omitContentTypeHeader) {
1548
+ headerParameters['Content-Type'] = 'application/json';
1549
+ }
1550
+ const body =
1551
+ input === undefined
1552
+ ? undefined
1553
+ : typeof input === 'object'
1554
+ ? JSON.stringify(input)
1555
+ : String(input);
1556
+
1557
+ const response = await this.$fetch(
1558
+ this.$url(
1559
+ '/array-of-maps-of-arrays-of-numbers',
1560
+ pathParameters,
1561
+ queryParameters,
1562
+ ),
1563
+ {
1564
+ headers: this.$headers(headerParameters),
1565
+ method: 'POST',
1566
+ body,
1567
+ },
1568
+ );
1569
+
1570
+ if (response.status === 200) {
1571
+ return await response.text();
1572
+ }
1573
+ throw new Error(
1574
+ \`Unknown response status \${response.status} returned by API\`,
1575
+ );
1576
+ }
1577
+
1578
+ public async postArrayOfMapsOfNumbers(
1579
+ input?: PostArrayOfMapsOfNumbersRequest,
1580
+ ): Promise<string> {
1581
+ const pathParameters: { [key: string]: any } = {};
1582
+ const queryParameters: { [key: string]: any } = {};
1583
+ const headerParameters: { [key: string]: any } = {};
1584
+ if (!this.$config.options?.omitContentTypeHeader) {
1585
+ headerParameters['Content-Type'] = 'application/json';
1586
+ }
1587
+ const body =
1588
+ input === undefined
1589
+ ? undefined
1590
+ : typeof input === 'object'
1591
+ ? JSON.stringify(input)
1592
+ : String(input);
1593
+
1594
+ const response = await this.$fetch(
1595
+ this.$url('/array-of-maps-of-numbers', pathParameters, queryParameters),
1596
+ {
1597
+ headers: this.$headers(headerParameters),
1598
+ method: 'POST',
1599
+ body,
1600
+ },
1601
+ );
1602
+
1603
+ if (response.status === 200) {
1604
+ return await response.text();
1605
+ }
1606
+ throw new Error(
1607
+ \`Unknown response status \${response.status} returned by API\`,
1608
+ );
1609
+ }
1610
+
1611
+ public async postMapOfArraysOfObjects(
1612
+ input?: PostMapOfArraysOfObjectsRequest,
1613
+ ): Promise<string> {
1614
+ const pathParameters: { [key: string]: any } = {};
1615
+ const queryParameters: { [key: string]: any } = {};
1616
+ const headerParameters: { [key: string]: any } = {};
1617
+ if (!this.$config.options?.omitContentTypeHeader) {
1618
+ headerParameters['Content-Type'] = 'application/json';
1619
+ }
1620
+ const body =
1621
+ input === undefined
1622
+ ? undefined
1623
+ : typeof input === 'object'
1624
+ ? JSON.stringify(
1625
+ $IO.PostMapOfArraysOfObjectsRequestContent.toJson(input),
1626
+ )
1627
+ : String($IO.PostMapOfArraysOfObjectsRequestContent.toJson(input));
1628
+
1629
+ const response = await this.$fetch(
1630
+ this.$url('/map-of-arrays-of-objects', pathParameters, queryParameters),
1631
+ {
1632
+ headers: this.$headers(headerParameters),
1633
+ method: 'POST',
1634
+ body,
1635
+ },
1636
+ );
1637
+
1638
+ if (response.status === 200) {
1639
+ return await response.text();
1640
+ }
1641
+ throw new Error(
1642
+ \`Unknown response status \${response.status} returned by API\`,
1643
+ );
1644
+ }
1645
+
1646
+ public async postMapOfMapsOfArraysOfNumbers(
1647
+ input?: PostMapOfMapsOfArraysOfNumbersRequest,
1648
+ ): Promise<string> {
1649
+ const pathParameters: { [key: string]: any } = {};
1650
+ const queryParameters: { [key: string]: any } = {};
1651
+ const headerParameters: { [key: string]: any } = {};
1652
+ if (!this.$config.options?.omitContentTypeHeader) {
1653
+ headerParameters['Content-Type'] = 'application/json';
1654
+ }
1655
+ const body =
1656
+ input === undefined
1657
+ ? undefined
1658
+ : typeof input === 'object'
1659
+ ? JSON.stringify(
1660
+ $IO.PostMapOfMapsOfArraysOfNumbersRequestContent.toJson(input),
1661
+ )
1662
+ : String(
1663
+ $IO.PostMapOfMapsOfArraysOfNumbersRequestContent.toJson(input),
1664
+ );
1665
+
1666
+ const response = await this.$fetch(
1667
+ this.$url(
1668
+ '/map-of-maps-of-arrays-of-numbers',
1669
+ pathParameters,
1670
+ queryParameters,
1671
+ ),
1672
+ {
1673
+ headers: this.$headers(headerParameters),
1674
+ method: 'POST',
1675
+ body,
1676
+ },
1677
+ );
1678
+
1679
+ if (response.status === 200) {
1680
+ return await response.text();
1681
+ }
1682
+ throw new Error(
1683
+ \`Unknown response status \${response.status} returned by API\`,
1684
+ );
1685
+ }
1686
+
1687
+ public async postMapOfMapsOfNumbers(
1688
+ input?: PostMapOfMapsOfNumbersRequest,
1689
+ ): Promise<string> {
1690
+ const pathParameters: { [key: string]: any } = {};
1691
+ const queryParameters: { [key: string]: any } = {};
1692
+ const headerParameters: { [key: string]: any } = {};
1693
+ if (!this.$config.options?.omitContentTypeHeader) {
1694
+ headerParameters['Content-Type'] = 'application/json';
1695
+ }
1696
+ const body =
1697
+ input === undefined
1698
+ ? undefined
1699
+ : typeof input === 'object'
1700
+ ? JSON.stringify(
1701
+ $IO.PostMapOfMapsOfNumbersRequestContent.toJson(input),
1702
+ )
1703
+ : String($IO.PostMapOfMapsOfNumbersRequestContent.toJson(input));
1704
+
1705
+ const response = await this.$fetch(
1706
+ this.$url('/map-of-maps-of-numbers', pathParameters, queryParameters),
1707
+ {
1708
+ headers: this.$headers(headerParameters),
1709
+ method: 'POST',
1710
+ body,
1711
+ },
1712
+ );
1713
+
1714
+ if (response.status === 200) {
1715
+ return await response.text();
1716
+ }
1717
+ throw new Error(
1718
+ \`Unknown response status \${response.status} returned by API\`,
1719
+ );
1720
+ }
1721
+
1722
+ public async postMapOfNumbers(
1723
+ input?: PostMapOfNumbersRequest,
1724
+ ): Promise<string> {
1725
+ const pathParameters: { [key: string]: any } = {};
1726
+ const queryParameters: { [key: string]: any } = {};
1727
+ const headerParameters: { [key: string]: any } = {};
1728
+ if (!this.$config.options?.omitContentTypeHeader) {
1729
+ headerParameters['Content-Type'] = 'application/json';
1730
+ }
1731
+ const body =
1732
+ input === undefined
1733
+ ? undefined
1734
+ : typeof input === 'object'
1735
+ ? JSON.stringify($IO.PostMapOfNumbersRequestContent.toJson(input))
1736
+ : String($IO.PostMapOfNumbersRequestContent.toJson(input));
1737
+
1738
+ const response = await this.$fetch(
1739
+ this.$url('/map-of-numbers', pathParameters, queryParameters),
1740
+ {
1741
+ headers: this.$headers(headerParameters),
1742
+ method: 'POST',
1743
+ body,
1744
+ },
1745
+ );
1746
+
1747
+ if (response.status === 200) {
1748
+ return await response.text();
1749
+ }
1750
+ throw new Error(
1751
+ \`Unknown response status \${response.status} returned by API\`,
1752
+ );
1753
+ }
1754
+
1755
+ public async postMapOfObjects(
1756
+ input?: PostMapOfObjectsRequest,
1757
+ ): Promise<string> {
1758
+ const pathParameters: { [key: string]: any } = {};
1759
+ const queryParameters: { [key: string]: any } = {};
1760
+ const headerParameters: { [key: string]: any } = {};
1761
+ if (!this.$config.options?.omitContentTypeHeader) {
1762
+ headerParameters['Content-Type'] = 'application/json';
1763
+ }
1764
+ const body =
1765
+ input === undefined
1766
+ ? undefined
1767
+ : typeof input === 'object'
1768
+ ? JSON.stringify($IO.PostMapOfObjectsRequestContent.toJson(input))
1769
+ : String($IO.PostMapOfObjectsRequestContent.toJson(input));
1770
+
1771
+ const response = await this.$fetch(
1772
+ this.$url('/map-of-objects', pathParameters, queryParameters),
1773
+ {
1774
+ headers: this.$headers(headerParameters),
1775
+ method: 'POST',
1776
+ body,
1777
+ },
1778
+ );
1779
+
1780
+ if (response.status === 200) {
1781
+ return await response.text();
1782
+ }
1783
+ throw new Error(
1784
+ \`Unknown response status \${response.status} returned by API\`,
1785
+ );
1786
+ }
1787
+ }
1788
+ "
1789
+ `;
1790
+
1791
+ exports[`openApiTsClientGenerator - complex types > should handle recursive schema references 1`] = `
1792
+ "export type TreeNode = {
1793
+ id: string;
1794
+ name: string;
1795
+ children?: Array<TreeNode>;
1796
+ };
1797
+
1798
+ export type CreateTreeRequest = TreeNode | undefined;
1799
+ export type CreateTreeError = never;
1800
+ export type GetTreeError = never;
1801
+ "
1802
+ `;
1803
+
1804
+ exports[`openApiTsClientGenerator - complex types > should handle recursive schema references 2`] = `
1805
+ "import type { TreeNode, CreateTreeRequest } from './types.gen.js';
1806
+
1807
+ /**
1808
+ * Utility for serialisation and deserialisation of API types.
1809
+ */
1810
+ export class $IO {
1811
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
1812
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
1813
+
1814
+ public static TreeNode = {
1815
+ toJson: (model: TreeNode): any => {
1816
+ if (model === undefined || model === null) {
1817
+ return model;
1818
+ }
1819
+ return {
1820
+ ...(model.id === undefined
1821
+ ? {}
1822
+ : {
1823
+ id: model.id,
1824
+ }),
1825
+ ...(model.name === undefined
1826
+ ? {}
1827
+ : {
1828
+ name: model.name,
1829
+ }),
1830
+ ...(model.children === undefined
1831
+ ? {}
1832
+ : {
1833
+ children: model.children.map($IO.TreeNode.toJson),
1834
+ }),
1835
+ };
1836
+ },
1837
+ fromJson: (json: any): TreeNode => {
1838
+ if (json === undefined || json === null) {
1839
+ return json;
1840
+ }
1841
+ return {
1842
+ id: json['id'],
1843
+ name: json['name'],
1844
+ ...(json['children'] === undefined
1845
+ ? {}
1846
+ : {
1847
+ children: (json['children'] as Array<any>).map(
1848
+ $IO.TreeNode.fromJson,
1849
+ ),
1850
+ }),
1851
+ };
1852
+ },
1853
+ };
1854
+ }
1855
+
1856
+ /**
1857
+ * Client configuration for TestApi
1858
+ */
1859
+ export interface TestApiConfig {
1860
+ /**
1861
+ * Base URL for the API
1862
+ */
1863
+ url: string;
1864
+ /**
1865
+ * Custom instance of fetch. By default the global 'fetch' is used.
1866
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
1867
+ */
1868
+ fetch?: typeof fetch;
1869
+ /**
1870
+ * Additional configuration
1871
+ */
1872
+ options?: {
1873
+ /**
1874
+ * By default, the client will add a Content-Type header, set to the media type defined for
1875
+ * the request in the OpenAPI specification.
1876
+ * Set this to false to omit this header.
1877
+ */
1878
+ omitContentTypeHeader?: boolean;
1879
+ };
1880
+ }
1881
+
1882
+ /**
1883
+ * API Client for TestApi
1884
+ */
1885
+ export class TestApi {
1886
+ private $config: TestApiConfig;
1887
+
1888
+ constructor(config: TestApiConfig) {
1889
+ this.$config = config;
1890
+
1891
+ this.createTree = this.createTree.bind(this);
1892
+ this.getTree = this.getTree.bind(this);
1893
+ }
1894
+
1895
+ private $url = (
1896
+ path: string,
1897
+ pathParameters: { [key: string]: any },
1898
+ queryParameters: { [key: string]: any },
1899
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
1900
+ ): string => {
1901
+ const baseUrl = this.$config.url.endsWith('/')
1902
+ ? this.$config.url.slice(0, -1)
1903
+ : this.$config.url;
1904
+ const pathWithParameters = Object.entries(pathParameters).reduce(
1905
+ (withParams, [key, value]) =>
1906
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
1907
+ path,
1908
+ );
1909
+ const queryString = Object.entries(queryParameters)
1910
+ .map(([key, value]) => {
1911
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
1912
+ return value
1913
+ .map(
1914
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
1915
+ )
1916
+ .join('&');
1917
+ }
1918
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
1919
+ })
1920
+ .join('&');
1921
+ return (
1922
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
1923
+ );
1924
+ };
1925
+
1926
+ private $headers = (
1927
+ headerParameters: { [key: string]: any },
1928
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
1929
+ ): [string, string][] => {
1930
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
1931
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
1932
+ return value.map((v) => [key, String(v)]) as [string, string][];
1933
+ }
1934
+ return [[key, String(value)]];
1935
+ });
1936
+ };
1937
+
1938
+ private $fetch: typeof fetch = (...args) =>
1939
+ (this.$config.fetch ?? fetch)(...args);
1940
+
1941
+ public async createTree(input?: CreateTreeRequest): Promise<TreeNode> {
1942
+ const pathParameters: { [key: string]: any } = {};
1943
+ const queryParameters: { [key: string]: any } = {};
1944
+ const headerParameters: { [key: string]: any } = {};
1945
+ if (!this.$config.options?.omitContentTypeHeader) {
1946
+ headerParameters['Content-Type'] = 'application/json';
1947
+ }
1948
+ const body =
1949
+ input === undefined
1950
+ ? undefined
1951
+ : typeof input === 'object'
1952
+ ? JSON.stringify($IO.TreeNode.toJson(input))
1953
+ : String($IO.TreeNode.toJson(input));
1954
+
1955
+ const response = await this.$fetch(
1956
+ this.$url('/tree', pathParameters, queryParameters),
1957
+ {
1958
+ headers: this.$headers(headerParameters),
1959
+ method: 'POST',
1960
+ body,
1961
+ },
1962
+ );
1963
+
1964
+ if (response.status === 201) {
1965
+ return $IO.TreeNode.fromJson(await response.json());
1966
+ }
1967
+ throw new Error(
1968
+ \`Unknown response status \${response.status} returned by API\`,
1969
+ );
1970
+ }
1971
+
1972
+ public async getTree(): Promise<TreeNode> {
1973
+ const pathParameters: { [key: string]: any } = {};
1974
+ const queryParameters: { [key: string]: any } = {};
1975
+ const headerParameters: { [key: string]: any } = {};
1976
+
1977
+ const body = undefined;
1978
+
1979
+ const response = await this.$fetch(
1980
+ this.$url('/tree', pathParameters, queryParameters),
1981
+ {
1982
+ headers: this.$headers(headerParameters),
1983
+ method: 'GET',
1984
+ body,
1985
+ },
1986
+ );
1987
+
1988
+ if (response.status === 200) {
1989
+ return $IO.TreeNode.fromJson(await response.json());
1990
+ }
1991
+ throw new Error(
1992
+ \`Unknown response status \${response.status} returned by API\`,
1993
+ );
1994
+ }
1995
+ }
1996
+ "
1997
+ `;
1998
+
1999
+ exports[`openApiTsClientGenerator - complex types > should handle refs and hoisting of inline schemas 1`] = `
2000
+ "export type Error = {
2001
+ code: string;
2002
+ message: string;
2003
+ };
2004
+ export type PostTestRequestContent = {
2005
+ inline?: PostTestRequestContentInline;
2006
+ referenced?: Error;
2007
+ };
2008
+ export type PostTestRequestContentInline = {
2009
+ name?: string;
2010
+ details?: PostTestRequestContentInlineDetails;
2011
+ };
2012
+ export type PostTestRequestContentInlineDetails = {
2013
+ age?: number;
2014
+ active?: boolean;
2015
+ };
2016
+
2017
+ export type PostTestRequest = PostTestRequestContent;
2018
+ export type PostTest400Error = {
2019
+ status: 400;
2020
+ error: Error;
2021
+ };
2022
+ export type PostTestError = PostTest400Error;
2023
+ "
2024
+ `;
2025
+
2026
+ exports[`openApiTsClientGenerator - complex types > should handle refs and hoisting of inline schemas 2`] = `
2027
+ "import type {
2028
+ Error,
2029
+ PostTestRequestContent,
2030
+ PostTestRequestContentInline,
2031
+ PostTestRequestContentInlineDetails,
2032
+ PostTestRequest,
2033
+ } from './types.gen.js';
2034
+
2035
+ /**
2036
+ * Utility for serialisation and deserialisation of API types.
2037
+ */
2038
+ export class $IO {
2039
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
2040
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
2041
+
2042
+ public static Error = {
2043
+ toJson: (model: Error): any => {
2044
+ if (model === undefined || model === null) {
2045
+ return model;
2046
+ }
2047
+ return {
2048
+ ...(model.code === undefined
2049
+ ? {}
2050
+ : {
2051
+ code: model.code,
2052
+ }),
2053
+ ...(model.message === undefined
2054
+ ? {}
2055
+ : {
2056
+ message: model.message,
2057
+ }),
2058
+ };
2059
+ },
2060
+ fromJson: (json: any): Error => {
2061
+ if (json === undefined || json === null) {
2062
+ return json;
2063
+ }
2064
+ return {
2065
+ code: json['code'],
2066
+ message: json['message'],
2067
+ };
2068
+ },
2069
+ };
2070
+
2071
+ public static PostTestRequestContent = {
2072
+ toJson: (model: PostTestRequestContent): any => {
2073
+ if (model === undefined || model === null) {
2074
+ return model;
2075
+ }
2076
+ return {
2077
+ ...(model.inline === undefined
2078
+ ? {}
2079
+ : {
2080
+ inline: $IO.PostTestRequestContentInline.toJson(model.inline),
2081
+ }),
2082
+ ...(model.referenced === undefined
2083
+ ? {}
2084
+ : {
2085
+ referenced: $IO.Error.toJson(model.referenced),
2086
+ }),
2087
+ };
2088
+ },
2089
+ fromJson: (json: any): PostTestRequestContent => {
2090
+ if (json === undefined || json === null) {
2091
+ return json;
2092
+ }
2093
+ return {
2094
+ ...(json['inline'] === undefined
2095
+ ? {}
2096
+ : {
2097
+ inline: $IO.PostTestRequestContentInline.fromJson(json['inline']),
2098
+ }),
2099
+ ...(json['referenced'] === undefined
2100
+ ? {}
2101
+ : {
2102
+ referenced: $IO.Error.fromJson(json['referenced']),
2103
+ }),
2104
+ };
2105
+ },
2106
+ };
2107
+
2108
+ public static PostTestRequestContentInline = {
2109
+ toJson: (model: PostTestRequestContentInline): any => {
2110
+ if (model === undefined || model === null) {
2111
+ return model;
2112
+ }
2113
+ return {
2114
+ ...(model.name === undefined
2115
+ ? {}
2116
+ : {
2117
+ name: model.name,
2118
+ }),
2119
+ ...(model.details === undefined
2120
+ ? {}
2121
+ : {
2122
+ details: $IO.PostTestRequestContentInlineDetails.toJson(
2123
+ model.details,
2124
+ ),
2125
+ }),
2126
+ };
2127
+ },
2128
+ fromJson: (json: any): PostTestRequestContentInline => {
2129
+ if (json === undefined || json === null) {
2130
+ return json;
2131
+ }
2132
+ return {
2133
+ ...(json['name'] === undefined
2134
+ ? {}
2135
+ : {
2136
+ name: json['name'],
2137
+ }),
2138
+ ...(json['details'] === undefined
2139
+ ? {}
2140
+ : {
2141
+ details: $IO.PostTestRequestContentInlineDetails.fromJson(
2142
+ json['details'],
2143
+ ),
2144
+ }),
2145
+ };
2146
+ },
2147
+ };
2148
+
2149
+ public static PostTestRequestContentInlineDetails = {
2150
+ toJson: (model: PostTestRequestContentInlineDetails): any => {
2151
+ if (model === undefined || model === null) {
2152
+ return model;
2153
+ }
2154
+ return {
2155
+ ...(model.age === undefined
2156
+ ? {}
2157
+ : {
2158
+ age: model.age,
2159
+ }),
2160
+ ...(model.active === undefined
2161
+ ? {}
2162
+ : {
2163
+ active: model.active,
2164
+ }),
2165
+ };
2166
+ },
2167
+ fromJson: (json: any): PostTestRequestContentInlineDetails => {
2168
+ if (json === undefined || json === null) {
2169
+ return json;
2170
+ }
2171
+ return {
2172
+ ...(json['age'] === undefined
2173
+ ? {}
2174
+ : {
2175
+ age: json['age'],
2176
+ }),
2177
+ ...(json['active'] === undefined
2178
+ ? {}
2179
+ : {
2180
+ active: json['active'],
2181
+ }),
2182
+ };
2183
+ },
2184
+ };
2185
+ }
2186
+
2187
+ /**
2188
+ * Client configuration for TestApi
2189
+ */
2190
+ export interface TestApiConfig {
2191
+ /**
2192
+ * Base URL for the API
2193
+ */
2194
+ url: string;
2195
+ /**
2196
+ * Custom instance of fetch. By default the global 'fetch' is used.
2197
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
2198
+ */
2199
+ fetch?: typeof fetch;
2200
+ /**
2201
+ * Additional configuration
2202
+ */
2203
+ options?: {
2204
+ /**
2205
+ * By default, the client will add a Content-Type header, set to the media type defined for
2206
+ * the request in the OpenAPI specification.
2207
+ * Set this to false to omit this header.
2208
+ */
2209
+ omitContentTypeHeader?: boolean;
2210
+ };
2211
+ }
2212
+
2213
+ /**
2214
+ * API Client for TestApi
2215
+ */
2216
+ export class TestApi {
2217
+ private $config: TestApiConfig;
2218
+
2219
+ constructor(config: TestApiConfig) {
2220
+ this.$config = config;
2221
+
2222
+ this.postTest = this.postTest.bind(this);
2223
+ }
2224
+
2225
+ private $url = (
2226
+ path: string,
2227
+ pathParameters: { [key: string]: any },
2228
+ queryParameters: { [key: string]: any },
2229
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
2230
+ ): string => {
2231
+ const baseUrl = this.$config.url.endsWith('/')
2232
+ ? this.$config.url.slice(0, -1)
2233
+ : this.$config.url;
2234
+ const pathWithParameters = Object.entries(pathParameters).reduce(
2235
+ (withParams, [key, value]) =>
2236
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
2237
+ path,
2238
+ );
2239
+ const queryString = Object.entries(queryParameters)
2240
+ .map(([key, value]) => {
2241
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
2242
+ return value
2243
+ .map(
2244
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
2245
+ )
2246
+ .join('&');
2247
+ }
2248
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
2249
+ })
2250
+ .join('&');
2251
+ return (
2252
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
2253
+ );
2254
+ };
2255
+
2256
+ private $headers = (
2257
+ headerParameters: { [key: string]: any },
2258
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
2259
+ ): [string, string][] => {
2260
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
2261
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
2262
+ return value.map((v) => [key, String(v)]) as [string, string][];
2263
+ }
2264
+ return [[key, String(value)]];
2265
+ });
2266
+ };
2267
+
2268
+ private $fetch: typeof fetch = (...args) =>
2269
+ (this.$config.fetch ?? fetch)(...args);
2270
+
2271
+ public async postTest(input: PostTestRequest): Promise<void> {
2272
+ const pathParameters: { [key: string]: any } = {};
2273
+ const queryParameters: { [key: string]: any } = {};
2274
+ const headerParameters: { [key: string]: any } = {};
2275
+ if (!this.$config.options?.omitContentTypeHeader) {
2276
+ headerParameters['Content-Type'] = 'application/json';
2277
+ }
2278
+ const body =
2279
+ typeof input === 'object'
2280
+ ? JSON.stringify($IO.PostTestRequestContent.toJson(input))
2281
+ : String($IO.PostTestRequestContent.toJson(input));
2282
+
2283
+ const response = await this.$fetch(
2284
+ this.$url('/test', pathParameters, queryParameters),
2285
+ {
2286
+ headers: this.$headers(headerParameters),
2287
+ method: 'POST',
2288
+ body,
2289
+ },
2290
+ );
2291
+
2292
+ if (response.status === 200) {
2293
+ return undefined;
2294
+ }
2295
+ if (response.status === 400) {
2296
+ throw {
2297
+ status: response.status,
2298
+ error: $IO.Error.fromJson(await response.json()),
2299
+ };
2300
+ }
2301
+ throw new Error(
2302
+ \`Unknown response status \${response.status} returned by API\`,
2303
+ );
2304
+ }
2305
+ }
2306
+ "
2307
+ `;