@aws/nx-plugin 0.28.2 → 0.28.4

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