@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,1138 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`openApiTsClientGenerator - requests > should generate valid TypeScript for parameters and responses 1`] = `
4
+ "export type GetTest200Response = {
5
+ result?: string;
6
+ };
7
+ export type GetTest400Response = {
8
+ error?: string;
9
+ };
10
+ export type GetTestRequestHeaderParameters = {
11
+ xApiKey: string;
12
+ };
13
+ export type GetTestRequestPathParameters = {
14
+ id: string;
15
+ };
16
+ export type GetTestRequestQueryParameters = {
17
+ filter?: string;
18
+ tags?: Array<string>;
19
+ };
20
+
21
+ export type GetTestRequest = GetTestRequestPathParameters &
22
+ GetTestRequestHeaderParameters &
23
+ GetTestRequestQueryParameters;
24
+ export type GetTest400Error = {
25
+ status: 400;
26
+ error: GetTest400Response;
27
+ };
28
+ export type GetTest404Error = {
29
+ status: 404;
30
+ error: void;
31
+ };
32
+ export type GetTestError = GetTest400Error | GetTest404Error;
33
+ "
34
+ `;
35
+
36
+ exports[`openApiTsClientGenerator - requests > should generate valid TypeScript for parameters and responses 2`] = `
37
+ "import type {
38
+ GetTest200Response,
39
+ GetTest400Response,
40
+ GetTestRequestHeaderParameters,
41
+ GetTestRequestPathParameters,
42
+ GetTestRequestQueryParameters,
43
+ GetTestRequest,
44
+ } from './types.gen.js';
45
+
46
+ /**
47
+ * Utility for serialisation and deserialisation of API types.
48
+ */
49
+ export class $IO {
50
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
51
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
52
+
53
+ public static GetTest200Response = {
54
+ toJson: (model: GetTest200Response): any => {
55
+ if (model === undefined || model === null) {
56
+ return model;
57
+ }
58
+ return {
59
+ ...(model.result === undefined
60
+ ? {}
61
+ : {
62
+ result: model.result,
63
+ }),
64
+ };
65
+ },
66
+ fromJson: (json: any): GetTest200Response => {
67
+ if (json === undefined || json === null) {
68
+ return json;
69
+ }
70
+ return {
71
+ ...(json['result'] === undefined
72
+ ? {}
73
+ : {
74
+ result: json['result'],
75
+ }),
76
+ };
77
+ },
78
+ };
79
+
80
+ public static GetTest400Response = {
81
+ toJson: (model: GetTest400Response): any => {
82
+ if (model === undefined || model === null) {
83
+ return model;
84
+ }
85
+ return {
86
+ ...(model.error === undefined
87
+ ? {}
88
+ : {
89
+ error: model.error,
90
+ }),
91
+ };
92
+ },
93
+ fromJson: (json: any): GetTest400Response => {
94
+ if (json === undefined || json === null) {
95
+ return json;
96
+ }
97
+ return {
98
+ ...(json['error'] === undefined
99
+ ? {}
100
+ : {
101
+ error: json['error'],
102
+ }),
103
+ };
104
+ },
105
+ };
106
+
107
+ public static GetTestRequestHeaderParameters = {
108
+ toJson: (model: GetTestRequestHeaderParameters): any => {
109
+ if (model === undefined || model === null) {
110
+ return model;
111
+ }
112
+ return {
113
+ ...(model.xApiKey === undefined
114
+ ? {}
115
+ : {
116
+ 'x-api-key': model.xApiKey,
117
+ }),
118
+ };
119
+ },
120
+ fromJson: (json: any): GetTestRequestHeaderParameters => {
121
+ if (json === undefined || json === null) {
122
+ return json;
123
+ }
124
+ return {
125
+ xApiKey: json['x-api-key'],
126
+ };
127
+ },
128
+ };
129
+
130
+ public static GetTestRequestPathParameters = {
131
+ toJson: (model: GetTestRequestPathParameters): any => {
132
+ if (model === undefined || model === null) {
133
+ return model;
134
+ }
135
+ return {
136
+ ...(model.id === undefined
137
+ ? {}
138
+ : {
139
+ id: model.id,
140
+ }),
141
+ };
142
+ },
143
+ fromJson: (json: any): GetTestRequestPathParameters => {
144
+ if (json === undefined || json === null) {
145
+ return json;
146
+ }
147
+ return {
148
+ id: json['id'],
149
+ };
150
+ },
151
+ };
152
+
153
+ public static GetTestRequestQueryParameters = {
154
+ toJson: (model: GetTestRequestQueryParameters): any => {
155
+ if (model === undefined || model === null) {
156
+ return model;
157
+ }
158
+ return {
159
+ ...(model.filter === undefined
160
+ ? {}
161
+ : {
162
+ filter: model.filter,
163
+ }),
164
+ ...(model.tags === undefined
165
+ ? {}
166
+ : {
167
+ tags: model.tags,
168
+ }),
169
+ };
170
+ },
171
+ fromJson: (json: any): GetTestRequestQueryParameters => {
172
+ if (json === undefined || json === null) {
173
+ return json;
174
+ }
175
+ return {
176
+ ...(json['filter'] === undefined
177
+ ? {}
178
+ : {
179
+ filter: json['filter'],
180
+ }),
181
+ ...(json['tags'] === undefined
182
+ ? {}
183
+ : {
184
+ tags: json['tags'],
185
+ }),
186
+ };
187
+ },
188
+ };
189
+ }
190
+
191
+ /**
192
+ * Client configuration for TestApi
193
+ */
194
+ export interface TestApiConfig {
195
+ /**
196
+ * Base URL for the API
197
+ */
198
+ url: string;
199
+ /**
200
+ * Custom instance of fetch. By default the global 'fetch' is used.
201
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
202
+ */
203
+ fetch?: typeof fetch;
204
+ /**
205
+ * Additional configuration
206
+ */
207
+ options?: {
208
+ /**
209
+ * By default, the client will add a Content-Type header, set to the media type defined for
210
+ * the request in the OpenAPI specification.
211
+ * Set this to false to omit this header.
212
+ */
213
+ omitContentTypeHeader?: boolean;
214
+ };
215
+ }
216
+
217
+ /**
218
+ * API Client for TestApi
219
+ */
220
+ export class TestApi {
221
+ private $config: TestApiConfig;
222
+
223
+ constructor(config: TestApiConfig) {
224
+ this.$config = config;
225
+
226
+ this.getTest = this.getTest.bind(this);
227
+ }
228
+
229
+ private $url = (
230
+ path: string,
231
+ pathParameters: { [key: string]: any },
232
+ queryParameters: { [key: string]: any },
233
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
234
+ ): string => {
235
+ const baseUrl = this.$config.url.endsWith('/')
236
+ ? this.$config.url.slice(0, -1)
237
+ : this.$config.url;
238
+ const pathWithParameters = Object.entries(pathParameters).reduce(
239
+ (withParams, [key, value]) =>
240
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
241
+ path,
242
+ );
243
+ const queryString = Object.entries(queryParameters)
244
+ .map(([key, value]) => {
245
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
246
+ return value
247
+ .map(
248
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
249
+ )
250
+ .join('&');
251
+ }
252
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
253
+ })
254
+ .join('&');
255
+ return (
256
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
257
+ );
258
+ };
259
+
260
+ private $headers = (
261
+ headerParameters: { [key: string]: any },
262
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
263
+ ): [string, string][] => {
264
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
265
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
266
+ return value.map((v) => [key, String(v)]) as [string, string][];
267
+ }
268
+ return [[key, String(value)]];
269
+ });
270
+ };
271
+
272
+ private $fetch: typeof fetch = (...args) =>
273
+ (this.$config.fetch ?? fetch)(...args);
274
+
275
+ public async getTest(input: GetTestRequest): Promise<GetTest200Response> {
276
+ const pathParameters: { [key: string]: any } =
277
+ $IO.GetTestRequestPathParameters.toJson(input);
278
+ const queryParameters: { [key: string]: any } =
279
+ $IO.GetTestRequestQueryParameters.toJson(input);
280
+ const headerParameters: { [key: string]: any } =
281
+ $IO.GetTestRequestHeaderParameters.toJson(input);
282
+ const collectionFormats = {
283
+ 'x-api-key': 'csv',
284
+ filter: 'multi',
285
+ tags: 'multi',
286
+ } as const;
287
+
288
+ const body = undefined;
289
+
290
+ const response = await this.$fetch(
291
+ this.$url(
292
+ '/test/{id}',
293
+ pathParameters,
294
+ queryParameters,
295
+ collectionFormats,
296
+ ),
297
+ {
298
+ headers: this.$headers(headerParameters, collectionFormats),
299
+ method: 'GET',
300
+ body,
301
+ },
302
+ );
303
+
304
+ if (response.status === 200) {
305
+ return $IO.GetTest200Response.fromJson(await response.json());
306
+ }
307
+ if (response.status === 400) {
308
+ throw {
309
+ status: response.status,
310
+ error: $IO.GetTest400Response.fromJson(await response.json()),
311
+ };
312
+ }
313
+ if (response.status === 404) {
314
+ throw {
315
+ status: response.status,
316
+ };
317
+ }
318
+ throw new Error(
319
+ \`Unknown response status \${response.status} returned by API\`,
320
+ );
321
+ }
322
+ }
323
+ "
324
+ `;
325
+
326
+ exports[`openApiTsClientGenerator - requests > should handle operations with simple request bodies and query parameters 1`] = `
327
+ "export type PostBooleanWithQueryRequestBodyParameters = {
328
+ body?: boolean;
329
+ };
330
+ export type PostBooleanWithQueryRequestQueryParameters = {
331
+ filter?: string;
332
+ };
333
+ export type PostNumberWithQueryRequestBodyParameters = {
334
+ body?: number;
335
+ };
336
+ export type PostNumberWithQueryRequestQueryParameters = {
337
+ filter?: string;
338
+ };
339
+ export type PostStringWithQueryRequestBodyParameters = {
340
+ body?: string;
341
+ };
342
+ export type PostStringWithQueryRequestQueryParameters = {
343
+ filter?: string;
344
+ };
345
+
346
+ export type PostBooleanRequest = boolean | undefined;
347
+ export type PostBooleanError = never;
348
+
349
+ export type PostBooleanWithQueryRequest =
350
+ PostBooleanWithQueryRequestQueryParameters &
351
+ PostBooleanWithQueryRequestBodyParameters;
352
+ export type PostBooleanWithQueryError = never;
353
+
354
+ export type PostNumberRequest = number | undefined;
355
+ export type PostNumberError = never;
356
+
357
+ export type PostNumberWithQueryRequest =
358
+ PostNumberWithQueryRequestQueryParameters &
359
+ PostNumberWithQueryRequestBodyParameters;
360
+ export type PostNumberWithQueryError = never;
361
+
362
+ export type PostStringRequest = string | undefined;
363
+ export type PostStringError = never;
364
+
365
+ export type PostStringWithQueryRequest =
366
+ PostStringWithQueryRequestQueryParameters &
367
+ PostStringWithQueryRequestBodyParameters;
368
+ export type PostStringWithQueryError = never;
369
+ "
370
+ `;
371
+
372
+ exports[`openApiTsClientGenerator - requests > should handle operations with simple request bodies and query parameters 2`] = `
373
+ "import type {
374
+ PostBooleanWithQueryRequestBodyParameters,
375
+ PostBooleanWithQueryRequestQueryParameters,
376
+ PostNumberWithQueryRequestBodyParameters,
377
+ PostNumberWithQueryRequestQueryParameters,
378
+ PostStringWithQueryRequestBodyParameters,
379
+ PostStringWithQueryRequestQueryParameters,
380
+ PostBooleanRequest,
381
+ PostBooleanWithQueryRequest,
382
+ PostNumberRequest,
383
+ PostNumberWithQueryRequest,
384
+ PostStringRequest,
385
+ PostStringWithQueryRequest,
386
+ } from './types.gen.js';
387
+
388
+ /**
389
+ * Utility for serialisation and deserialisation of API types.
390
+ */
391
+ export class $IO {
392
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
393
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
394
+
395
+ public static PostBooleanWithQueryRequestBodyParameters = {
396
+ toJson: (model: PostBooleanWithQueryRequestBodyParameters): any => {
397
+ if (model === undefined || model === null) {
398
+ return model;
399
+ }
400
+ return {
401
+ ...(model.body === undefined
402
+ ? {}
403
+ : {
404
+ body: model.body,
405
+ }),
406
+ };
407
+ },
408
+ fromJson: (json: any): PostBooleanWithQueryRequestBodyParameters => {
409
+ if (json === undefined || json === null) {
410
+ return json;
411
+ }
412
+ return {
413
+ ...(json['body'] === undefined
414
+ ? {}
415
+ : {
416
+ body: json['body'],
417
+ }),
418
+ };
419
+ },
420
+ };
421
+
422
+ public static PostBooleanWithQueryRequestQueryParameters = {
423
+ toJson: (model: PostBooleanWithQueryRequestQueryParameters): any => {
424
+ if (model === undefined || model === null) {
425
+ return model;
426
+ }
427
+ return {
428
+ ...(model.filter === undefined
429
+ ? {}
430
+ : {
431
+ filter: model.filter,
432
+ }),
433
+ };
434
+ },
435
+ fromJson: (json: any): PostBooleanWithQueryRequestQueryParameters => {
436
+ if (json === undefined || json === null) {
437
+ return json;
438
+ }
439
+ return {
440
+ ...(json['filter'] === undefined
441
+ ? {}
442
+ : {
443
+ filter: json['filter'],
444
+ }),
445
+ };
446
+ },
447
+ };
448
+
449
+ public static PostNumberWithQueryRequestBodyParameters = {
450
+ toJson: (model: PostNumberWithQueryRequestBodyParameters): any => {
451
+ if (model === undefined || model === null) {
452
+ return model;
453
+ }
454
+ return {
455
+ ...(model.body === undefined
456
+ ? {}
457
+ : {
458
+ body: model.body,
459
+ }),
460
+ };
461
+ },
462
+ fromJson: (json: any): PostNumberWithQueryRequestBodyParameters => {
463
+ if (json === undefined || json === null) {
464
+ return json;
465
+ }
466
+ return {
467
+ ...(json['body'] === undefined
468
+ ? {}
469
+ : {
470
+ body: json['body'],
471
+ }),
472
+ };
473
+ },
474
+ };
475
+
476
+ public static PostNumberWithQueryRequestQueryParameters = {
477
+ toJson: (model: PostNumberWithQueryRequestQueryParameters): any => {
478
+ if (model === undefined || model === null) {
479
+ return model;
480
+ }
481
+ return {
482
+ ...(model.filter === undefined
483
+ ? {}
484
+ : {
485
+ filter: model.filter,
486
+ }),
487
+ };
488
+ },
489
+ fromJson: (json: any): PostNumberWithQueryRequestQueryParameters => {
490
+ if (json === undefined || json === null) {
491
+ return json;
492
+ }
493
+ return {
494
+ ...(json['filter'] === undefined
495
+ ? {}
496
+ : {
497
+ filter: json['filter'],
498
+ }),
499
+ };
500
+ },
501
+ };
502
+
503
+ public static PostStringWithQueryRequestBodyParameters = {
504
+ toJson: (model: PostStringWithQueryRequestBodyParameters): any => {
505
+ if (model === undefined || model === null) {
506
+ return model;
507
+ }
508
+ return {
509
+ ...(model.body === undefined
510
+ ? {}
511
+ : {
512
+ body: model.body,
513
+ }),
514
+ };
515
+ },
516
+ fromJson: (json: any): PostStringWithQueryRequestBodyParameters => {
517
+ if (json === undefined || json === null) {
518
+ return json;
519
+ }
520
+ return {
521
+ ...(json['body'] === undefined
522
+ ? {}
523
+ : {
524
+ body: json['body'],
525
+ }),
526
+ };
527
+ },
528
+ };
529
+
530
+ public static PostStringWithQueryRequestQueryParameters = {
531
+ toJson: (model: PostStringWithQueryRequestQueryParameters): any => {
532
+ if (model === undefined || model === null) {
533
+ return model;
534
+ }
535
+ return {
536
+ ...(model.filter === undefined
537
+ ? {}
538
+ : {
539
+ filter: model.filter,
540
+ }),
541
+ };
542
+ },
543
+ fromJson: (json: any): PostStringWithQueryRequestQueryParameters => {
544
+ if (json === undefined || json === null) {
545
+ return json;
546
+ }
547
+ return {
548
+ ...(json['filter'] === undefined
549
+ ? {}
550
+ : {
551
+ filter: json['filter'],
552
+ }),
553
+ };
554
+ },
555
+ };
556
+ }
557
+
558
+ /**
559
+ * Client configuration for TestApi
560
+ */
561
+ export interface TestApiConfig {
562
+ /**
563
+ * Base URL for the API
564
+ */
565
+ url: string;
566
+ /**
567
+ * Custom instance of fetch. By default the global 'fetch' is used.
568
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
569
+ */
570
+ fetch?: typeof fetch;
571
+ /**
572
+ * Additional configuration
573
+ */
574
+ options?: {
575
+ /**
576
+ * By default, the client will add a Content-Type header, set to the media type defined for
577
+ * the request in the OpenAPI specification.
578
+ * Set this to false to omit this header.
579
+ */
580
+ omitContentTypeHeader?: boolean;
581
+ };
582
+ }
583
+
584
+ /**
585
+ * API Client for TestApi
586
+ */
587
+ export class TestApi {
588
+ private $config: TestApiConfig;
589
+
590
+ constructor(config: TestApiConfig) {
591
+ this.$config = config;
592
+
593
+ this.postBoolean = this.postBoolean.bind(this);
594
+ this.postBooleanWithQuery = this.postBooleanWithQuery.bind(this);
595
+ this.postNumber = this.postNumber.bind(this);
596
+ this.postNumberWithQuery = this.postNumberWithQuery.bind(this);
597
+ this.postString = this.postString.bind(this);
598
+ this.postStringWithQuery = this.postStringWithQuery.bind(this);
599
+ }
600
+
601
+ private $url = (
602
+ path: string,
603
+ pathParameters: { [key: string]: any },
604
+ queryParameters: { [key: string]: any },
605
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
606
+ ): string => {
607
+ const baseUrl = this.$config.url.endsWith('/')
608
+ ? this.$config.url.slice(0, -1)
609
+ : this.$config.url;
610
+ const pathWithParameters = Object.entries(pathParameters).reduce(
611
+ (withParams, [key, value]) =>
612
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
613
+ path,
614
+ );
615
+ const queryString = Object.entries(queryParameters)
616
+ .map(([key, value]) => {
617
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
618
+ return value
619
+ .map(
620
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
621
+ )
622
+ .join('&');
623
+ }
624
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
625
+ })
626
+ .join('&');
627
+ return (
628
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
629
+ );
630
+ };
631
+
632
+ private $headers = (
633
+ headerParameters: { [key: string]: any },
634
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
635
+ ): [string, string][] => {
636
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
637
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
638
+ return value.map((v) => [key, String(v)]) as [string, string][];
639
+ }
640
+ return [[key, String(value)]];
641
+ });
642
+ };
643
+
644
+ private $fetch: typeof fetch = (...args) =>
645
+ (this.$config.fetch ?? fetch)(...args);
646
+
647
+ public async postBoolean(input?: PostBooleanRequest): Promise<string> {
648
+ const pathParameters: { [key: string]: any } = {};
649
+ const queryParameters: { [key: string]: any } = {};
650
+ const headerParameters: { [key: string]: any } = {};
651
+ if (!this.$config.options?.omitContentTypeHeader) {
652
+ headerParameters['Content-Type'] = 'application/json';
653
+ }
654
+ const body = input === undefined ? undefined : String(input);
655
+
656
+ const response = await this.$fetch(
657
+ this.$url('/boolean', pathParameters, queryParameters),
658
+ {
659
+ headers: this.$headers(headerParameters),
660
+ method: 'POST',
661
+ body,
662
+ },
663
+ );
664
+
665
+ if (response.status === 200) {
666
+ return await response.text();
667
+ }
668
+ throw new Error(
669
+ \`Unknown response status \${response.status} returned by API\`,
670
+ );
671
+ }
672
+
673
+ public async postBooleanWithQuery(
674
+ input: PostBooleanWithQueryRequest,
675
+ ): Promise<string> {
676
+ const pathParameters: { [key: string]: any } = {};
677
+ const queryParameters: { [key: string]: any } =
678
+ $IO.PostBooleanWithQueryRequestQueryParameters.toJson(input);
679
+ const headerParameters: { [key: string]: any } = {};
680
+ if (!this.$config.options?.omitContentTypeHeader) {
681
+ headerParameters['Content-Type'] = 'application/json';
682
+ }
683
+ const collectionFormats = {
684
+ filter: 'multi',
685
+ } as const;
686
+ const body = input === undefined ? undefined : String(input.body);
687
+
688
+ const response = await this.$fetch(
689
+ this.$url(
690
+ '/boolean-with-query',
691
+ pathParameters,
692
+ queryParameters,
693
+ collectionFormats,
694
+ ),
695
+ {
696
+ headers: this.$headers(headerParameters, collectionFormats),
697
+ method: 'POST',
698
+ body,
699
+ },
700
+ );
701
+
702
+ if (response.status === 200) {
703
+ return await response.text();
704
+ }
705
+ throw new Error(
706
+ \`Unknown response status \${response.status} returned by API\`,
707
+ );
708
+ }
709
+
710
+ public async postNumber(input?: PostNumberRequest): Promise<string> {
711
+ const pathParameters: { [key: string]: any } = {};
712
+ const queryParameters: { [key: string]: any } = {};
713
+ const headerParameters: { [key: string]: any } = {};
714
+ if (!this.$config.options?.omitContentTypeHeader) {
715
+ headerParameters['Content-Type'] = 'application/json';
716
+ }
717
+ const body = input === undefined ? undefined : String(input);
718
+
719
+ const response = await this.$fetch(
720
+ this.$url('/number', pathParameters, queryParameters),
721
+ {
722
+ headers: this.$headers(headerParameters),
723
+ method: 'POST',
724
+ body,
725
+ },
726
+ );
727
+
728
+ if (response.status === 200) {
729
+ return await response.text();
730
+ }
731
+ throw new Error(
732
+ \`Unknown response status \${response.status} returned by API\`,
733
+ );
734
+ }
735
+
736
+ public async postNumberWithQuery(
737
+ input: PostNumberWithQueryRequest,
738
+ ): Promise<string> {
739
+ const pathParameters: { [key: string]: any } = {};
740
+ const queryParameters: { [key: string]: any } =
741
+ $IO.PostNumberWithQueryRequestQueryParameters.toJson(input);
742
+ const headerParameters: { [key: string]: any } = {};
743
+ if (!this.$config.options?.omitContentTypeHeader) {
744
+ headerParameters['Content-Type'] = 'application/json';
745
+ }
746
+ const collectionFormats = {
747
+ filter: 'multi',
748
+ } as const;
749
+ const body = input === undefined ? undefined : String(input.body);
750
+
751
+ const response = await this.$fetch(
752
+ this.$url(
753
+ '/number-with-query',
754
+ pathParameters,
755
+ queryParameters,
756
+ collectionFormats,
757
+ ),
758
+ {
759
+ headers: this.$headers(headerParameters, collectionFormats),
760
+ method: 'POST',
761
+ body,
762
+ },
763
+ );
764
+
765
+ if (response.status === 200) {
766
+ return await response.text();
767
+ }
768
+ throw new Error(
769
+ \`Unknown response status \${response.status} returned by API\`,
770
+ );
771
+ }
772
+
773
+ public async postString(input?: PostStringRequest): Promise<string> {
774
+ const pathParameters: { [key: string]: any } = {};
775
+ const queryParameters: { [key: string]: any } = {};
776
+ const headerParameters: { [key: string]: any } = {};
777
+ if (!this.$config.options?.omitContentTypeHeader) {
778
+ headerParameters['Content-Type'] = 'application/json';
779
+ }
780
+ const body = input === undefined ? undefined : String(input);
781
+
782
+ const response = await this.$fetch(
783
+ this.$url('/string', pathParameters, queryParameters),
784
+ {
785
+ headers: this.$headers(headerParameters),
786
+ method: 'POST',
787
+ body,
788
+ },
789
+ );
790
+
791
+ if (response.status === 200) {
792
+ return await response.text();
793
+ }
794
+ throw new Error(
795
+ \`Unknown response status \${response.status} returned by API\`,
796
+ );
797
+ }
798
+
799
+ public async postStringWithQuery(
800
+ input: PostStringWithQueryRequest,
801
+ ): Promise<string> {
802
+ const pathParameters: { [key: string]: any } = {};
803
+ const queryParameters: { [key: string]: any } =
804
+ $IO.PostStringWithQueryRequestQueryParameters.toJson(input);
805
+ const headerParameters: { [key: string]: any } = {};
806
+ if (!this.$config.options?.omitContentTypeHeader) {
807
+ headerParameters['Content-Type'] = 'application/json';
808
+ }
809
+ const collectionFormats = {
810
+ filter: 'multi',
811
+ } as const;
812
+ const body = input === undefined ? undefined : String(input.body);
813
+
814
+ const response = await this.$fetch(
815
+ this.$url(
816
+ '/string-with-query',
817
+ pathParameters,
818
+ queryParameters,
819
+ collectionFormats,
820
+ ),
821
+ {
822
+ headers: this.$headers(headerParameters, collectionFormats),
823
+ method: 'POST',
824
+ body,
825
+ },
826
+ );
827
+
828
+ if (response.status === 200) {
829
+ return await response.text();
830
+ }
831
+ throw new Error(
832
+ \`Unknown response status \${response.status} returned by API\`,
833
+ );
834
+ }
835
+ }
836
+ "
837
+ `;
838
+
839
+ exports[`openApiTsClientGenerator - requests > should handle request body property matching query parameter name 1`] = `
840
+ "export type PostTest200Response = {
841
+ result?: string;
842
+ };
843
+ export type PostTestRequestBodyParameters = {
844
+ body?: PostTestRequestContent;
845
+ };
846
+ export type PostTestRequestContent = {
847
+ filter: PostTestRequestContentFilter;
848
+ data: string;
849
+ };
850
+ export type PostTestRequestContentFilter = {
851
+ value?: string;
852
+ };
853
+ export type PostTestRequestQueryParameters = {
854
+ filter?: string;
855
+ };
856
+
857
+ export type PostTestRequest = PostTestRequestQueryParameters &
858
+ PostTestRequestBodyParameters;
859
+ export type PostTestError = never;
860
+ "
861
+ `;
862
+
863
+ exports[`openApiTsClientGenerator - requests > should handle request body property matching query parameter name 2`] = `
864
+ "import type {
865
+ PostTest200Response,
866
+ PostTestRequestBodyParameters,
867
+ PostTestRequestContent,
868
+ PostTestRequestContentFilter,
869
+ PostTestRequestQueryParameters,
870
+ PostTestRequest,
871
+ } from './types.gen.js';
872
+
873
+ /**
874
+ * Utility for serialisation and deserialisation of API types.
875
+ */
876
+ export class $IO {
877
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
878
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
879
+
880
+ public static PostTest200Response = {
881
+ toJson: (model: PostTest200Response): any => {
882
+ if (model === undefined || model === null) {
883
+ return model;
884
+ }
885
+ return {
886
+ ...(model.result === undefined
887
+ ? {}
888
+ : {
889
+ result: model.result,
890
+ }),
891
+ };
892
+ },
893
+ fromJson: (json: any): PostTest200Response => {
894
+ if (json === undefined || json === null) {
895
+ return json;
896
+ }
897
+ return {
898
+ ...(json['result'] === undefined
899
+ ? {}
900
+ : {
901
+ result: json['result'],
902
+ }),
903
+ };
904
+ },
905
+ };
906
+
907
+ public static PostTestRequestBodyParameters = {
908
+ toJson: (model: PostTestRequestBodyParameters): any => {
909
+ if (model === undefined || model === null) {
910
+ return model;
911
+ }
912
+ return {
913
+ ...(model.body === undefined
914
+ ? {}
915
+ : {
916
+ body: $IO.PostTestRequestContent.toJson(model.body),
917
+ }),
918
+ };
919
+ },
920
+ fromJson: (json: any): PostTestRequestBodyParameters => {
921
+ if (json === undefined || json === null) {
922
+ return json;
923
+ }
924
+ return {
925
+ ...(json['body'] === undefined
926
+ ? {}
927
+ : {
928
+ body: $IO.PostTestRequestContent.fromJson(json['body']),
929
+ }),
930
+ };
931
+ },
932
+ };
933
+
934
+ public static PostTestRequestContent = {
935
+ toJson: (model: PostTestRequestContent): any => {
936
+ if (model === undefined || model === null) {
937
+ return model;
938
+ }
939
+ return {
940
+ ...(model.filter === undefined
941
+ ? {}
942
+ : {
943
+ filter: $IO.PostTestRequestContentFilter.toJson(model.filter),
944
+ }),
945
+ ...(model.data === undefined
946
+ ? {}
947
+ : {
948
+ data: model.data,
949
+ }),
950
+ };
951
+ },
952
+ fromJson: (json: any): PostTestRequestContent => {
953
+ if (json === undefined || json === null) {
954
+ return json;
955
+ }
956
+ return {
957
+ filter: $IO.PostTestRequestContentFilter.fromJson(json['filter']),
958
+ data: json['data'],
959
+ };
960
+ },
961
+ };
962
+
963
+ public static PostTestRequestContentFilter = {
964
+ toJson: (model: PostTestRequestContentFilter): any => {
965
+ if (model === undefined || model === null) {
966
+ return model;
967
+ }
968
+ return {
969
+ ...(model.value === undefined
970
+ ? {}
971
+ : {
972
+ value: model.value,
973
+ }),
974
+ };
975
+ },
976
+ fromJson: (json: any): PostTestRequestContentFilter => {
977
+ if (json === undefined || json === null) {
978
+ return json;
979
+ }
980
+ return {
981
+ ...(json['value'] === undefined
982
+ ? {}
983
+ : {
984
+ value: json['value'],
985
+ }),
986
+ };
987
+ },
988
+ };
989
+
990
+ public static PostTestRequestQueryParameters = {
991
+ toJson: (model: PostTestRequestQueryParameters): any => {
992
+ if (model === undefined || model === null) {
993
+ return model;
994
+ }
995
+ return {
996
+ ...(model.filter === undefined
997
+ ? {}
998
+ : {
999
+ filter: model.filter,
1000
+ }),
1001
+ };
1002
+ },
1003
+ fromJson: (json: any): PostTestRequestQueryParameters => {
1004
+ if (json === undefined || json === null) {
1005
+ return json;
1006
+ }
1007
+ return {
1008
+ ...(json['filter'] === undefined
1009
+ ? {}
1010
+ : {
1011
+ filter: json['filter'],
1012
+ }),
1013
+ };
1014
+ },
1015
+ };
1016
+ }
1017
+
1018
+ /**
1019
+ * Client configuration for TestApi
1020
+ */
1021
+ export interface TestApiConfig {
1022
+ /**
1023
+ * Base URL for the API
1024
+ */
1025
+ url: string;
1026
+ /**
1027
+ * Custom instance of fetch. By default the global 'fetch' is used.
1028
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
1029
+ */
1030
+ fetch?: typeof fetch;
1031
+ /**
1032
+ * Additional configuration
1033
+ */
1034
+ options?: {
1035
+ /**
1036
+ * By default, the client will add a Content-Type header, set to the media type defined for
1037
+ * the request in the OpenAPI specification.
1038
+ * Set this to false to omit this header.
1039
+ */
1040
+ omitContentTypeHeader?: boolean;
1041
+ };
1042
+ }
1043
+
1044
+ /**
1045
+ * API Client for TestApi
1046
+ */
1047
+ export class TestApi {
1048
+ private $config: TestApiConfig;
1049
+
1050
+ constructor(config: TestApiConfig) {
1051
+ this.$config = config;
1052
+
1053
+ this.postTest = this.postTest.bind(this);
1054
+ }
1055
+
1056
+ private $url = (
1057
+ path: string,
1058
+ pathParameters: { [key: string]: any },
1059
+ queryParameters: { [key: string]: any },
1060
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
1061
+ ): string => {
1062
+ const baseUrl = this.$config.url.endsWith('/')
1063
+ ? this.$config.url.slice(0, -1)
1064
+ : this.$config.url;
1065
+ const pathWithParameters = Object.entries(pathParameters).reduce(
1066
+ (withParams, [key, value]) =>
1067
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
1068
+ path,
1069
+ );
1070
+ const queryString = Object.entries(queryParameters)
1071
+ .map(([key, value]) => {
1072
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
1073
+ return value
1074
+ .map(
1075
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
1076
+ )
1077
+ .join('&');
1078
+ }
1079
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
1080
+ })
1081
+ .join('&');
1082
+ return (
1083
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
1084
+ );
1085
+ };
1086
+
1087
+ private $headers = (
1088
+ headerParameters: { [key: string]: any },
1089
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
1090
+ ): [string, string][] => {
1091
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
1092
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
1093
+ return value.map((v) => [key, String(v)]) as [string, string][];
1094
+ }
1095
+ return [[key, String(value)]];
1096
+ });
1097
+ };
1098
+
1099
+ private $fetch: typeof fetch = (...args) =>
1100
+ (this.$config.fetch ?? fetch)(...args);
1101
+
1102
+ public async postTest(input: PostTestRequest): Promise<PostTest200Response> {
1103
+ const pathParameters: { [key: string]: any } = {};
1104
+ const queryParameters: { [key: string]: any } =
1105
+ $IO.PostTestRequestQueryParameters.toJson(input);
1106
+ const headerParameters: { [key: string]: any } = {};
1107
+ if (!this.$config.options?.omitContentTypeHeader) {
1108
+ headerParameters['Content-Type'] = 'application/json';
1109
+ }
1110
+ const collectionFormats = {
1111
+ filter: 'multi',
1112
+ } as const;
1113
+ const body =
1114
+ input === undefined
1115
+ ? undefined
1116
+ : typeof input === 'object'
1117
+ ? JSON.stringify($IO.PostTestRequestBodyParameters.toJson(input).body)
1118
+ : String($IO.PostTestRequestBodyParameters.toJson(input).body);
1119
+
1120
+ const response = await this.$fetch(
1121
+ this.$url('/test', pathParameters, queryParameters, collectionFormats),
1122
+ {
1123
+ headers: this.$headers(headerParameters, collectionFormats),
1124
+ method: 'POST',
1125
+ body,
1126
+ },
1127
+ );
1128
+
1129
+ if (response.status === 200) {
1130
+ return $IO.PostTest200Response.fromJson(await response.json());
1131
+ }
1132
+ throw new Error(
1133
+ \`Unknown response status \${response.status} returned by API\`,
1134
+ );
1135
+ }
1136
+ }
1137
+ "
1138
+ `;