@aws/nx-plugin 0.39.1 → 0.39.3

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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +10 -10
  3. package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +0 -6
  4. package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +529 -0
  5. package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +618 -0
  6. package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +2157 -0
  7. package/src/open-api/ts-client/__snapshots__/generator.streaming.spec.ts.snap +1 -1
  8. package/src/open-api/ts-client/files/client.gen.ts.template +10 -10
  9. package/src/open-api/ts-client/files/types.gen.ts.template +3 -3
  10. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +1 -1
  11. package/src/open-api/utils/codegen-data/languages.d.ts +1 -0
  12. package/src/open-api/utils/codegen-data/languages.js +38 -4
  13. package/src/open-api/utils/codegen-data/languages.js.map +1 -1
  14. package/src/open-api/utils/codegen-data.js +5 -0
  15. package/src/open-api/utils/codegen-data.js.map +1 -1
  16. package/src/open-api/utils/normalise.js +24 -6
  17. package/src/open-api/utils/normalise.js.map +1 -1
  18. package/src/py/fast-api/react/generator.js +1 -0
  19. package/src/py/fast-api/react/generator.js.map +1 -1
  20. package/src/trpc/react/__snapshots__/generator.spec.ts.snap +20 -17
  21. package/src/trpc/react/files/src/components/__apiNameClassName__ClientProvider.tsx.template +3 -5
  22. package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +2 -2
  23. package/src/trpc/react/generator.js +1 -0
  24. package/src/trpc/react/generator.js.map +1 -1
  25. package/src/utils/files/website/components/tanstack-query/QueryClientProvider.tsx.template +16 -3
  26. package/src/utils/versions.d.ts +2 -1
  27. package/src/utils/versions.js +1 -0
  28. package/src/utils/versions.js.map +1 -1
@@ -0,0 +1,618 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`openApiTsClientGenerator - FastAPI > should generate valid TypeScript for FastAPI echo endpoint with validation errors 1`] = `
4
+ "export type EchoOutput = {
5
+ message: string;
6
+ };
7
+ export type EchoRequestQueryParameters = {
8
+ message: string;
9
+ };
10
+ export type HTTPValidationError = {
11
+ detail?: Array<ValidationError>;
12
+ };
13
+ export type InternalServerErrorDetails = {
14
+ detail: string;
15
+ };
16
+ export type LocationItem = string | number;
17
+ export type ValidationError = {
18
+ loc: Array<LocationItem>;
19
+ msg: string;
20
+ type: string;
21
+ };
22
+
23
+ export type EchoRequest = EchoRequestQueryParameters;
24
+ export type Echo422Error = {
25
+ status: 422;
26
+ error: HTTPValidationError;
27
+ };
28
+ export type Echo500Error = {
29
+ status: 500;
30
+ error: InternalServerErrorDetails;
31
+ };
32
+ export type EchoError = Echo422Error | Echo500Error;
33
+ "
34
+ `;
35
+
36
+ exports[`openApiTsClientGenerator - FastAPI > should generate valid TypeScript for FastAPI echo endpoint with validation errors 2`] = `
37
+ "import type {
38
+ EchoOutput,
39
+ EchoRequestQueryParameters,
40
+ HTTPValidationError,
41
+ InternalServerErrorDetails,
42
+ LocationItem,
43
+ ValidationError,
44
+ EchoRequest,
45
+ } from './types.gen.js';
46
+
47
+ /**
48
+ * Utility for serialisation and deserialisation of API types.
49
+ */
50
+ export class $IO {
51
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
52
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
53
+
54
+ public static EchoOutput = {
55
+ toJson: (model: EchoOutput): any => {
56
+ if (model === undefined || model === null) {
57
+ return model;
58
+ }
59
+ return {
60
+ ...(model.message === undefined
61
+ ? {}
62
+ : {
63
+ message: model.message,
64
+ }),
65
+ };
66
+ },
67
+ fromJson: (json: any): EchoOutput => {
68
+ if (json === undefined || json === null) {
69
+ return json;
70
+ }
71
+ return {
72
+ message: json['message'],
73
+ };
74
+ },
75
+ };
76
+
77
+ public static EchoRequestQueryParameters = {
78
+ toJson: (model: EchoRequestQueryParameters): any => {
79
+ if (model === undefined || model === null) {
80
+ return model;
81
+ }
82
+ return {
83
+ ...(model.message === undefined
84
+ ? {}
85
+ : {
86
+ message: model.message,
87
+ }),
88
+ };
89
+ },
90
+ fromJson: (json: any): EchoRequestQueryParameters => {
91
+ if (json === undefined || json === null) {
92
+ return json;
93
+ }
94
+ return {
95
+ message: json['message'],
96
+ };
97
+ },
98
+ };
99
+
100
+ public static HTTPValidationError = {
101
+ toJson: (model: HTTPValidationError): any => {
102
+ if (model === undefined || model === null) {
103
+ return model;
104
+ }
105
+ return {
106
+ ...(model.detail === undefined
107
+ ? {}
108
+ : {
109
+ detail: model.detail.map($IO.ValidationError.toJson),
110
+ }),
111
+ };
112
+ },
113
+ fromJson: (json: any): HTTPValidationError => {
114
+ if (json === undefined || json === null) {
115
+ return json;
116
+ }
117
+ return {
118
+ ...(json['detail'] === undefined
119
+ ? {}
120
+ : {
121
+ detail: (json['detail'] as Array<any>).map(
122
+ $IO.ValidationError.fromJson,
123
+ ),
124
+ }),
125
+ };
126
+ },
127
+ };
128
+
129
+ public static InternalServerErrorDetails = {
130
+ toJson: (model: InternalServerErrorDetails): any => {
131
+ if (model === undefined || model === null) {
132
+ return model;
133
+ }
134
+ return {
135
+ ...(model.detail === undefined
136
+ ? {}
137
+ : {
138
+ detail: model.detail,
139
+ }),
140
+ };
141
+ },
142
+ fromJson: (json: any): InternalServerErrorDetails => {
143
+ if (json === undefined || json === null) {
144
+ return json;
145
+ }
146
+ return {
147
+ detail: json['detail'],
148
+ };
149
+ },
150
+ };
151
+
152
+ public static LocationItem = {
153
+ toJson: (model: LocationItem): any => {
154
+ if (model === undefined || model === null) {
155
+ return model;
156
+ }
157
+ if (typeof model === 'string') {
158
+ return model;
159
+ }
160
+ if (typeof model === 'number') {
161
+ return model;
162
+ }
163
+ return model;
164
+ },
165
+ fromJson: (json: any): LocationItem => {
166
+ if (json === undefined || json === null) {
167
+ return json;
168
+ }
169
+ if (typeof json === 'string') {
170
+ return json;
171
+ }
172
+ if (typeof json === 'number') {
173
+ return json;
174
+ }
175
+ return json;
176
+ },
177
+ };
178
+
179
+ public static ValidationError = {
180
+ toJson: (model: ValidationError): any => {
181
+ if (model === undefined || model === null) {
182
+ return model;
183
+ }
184
+ return {
185
+ ...(model.loc === undefined
186
+ ? {}
187
+ : {
188
+ loc: model.loc.map((item0) => item0),
189
+ }),
190
+ ...(model.msg === undefined
191
+ ? {}
192
+ : {
193
+ msg: model.msg,
194
+ }),
195
+ ...(model.type === undefined
196
+ ? {}
197
+ : {
198
+ type: model.type,
199
+ }),
200
+ };
201
+ },
202
+ fromJson: (json: any): ValidationError => {
203
+ if (json === undefined || json === null) {
204
+ return json;
205
+ }
206
+ return {
207
+ loc: (json['loc'] as Array<any>).map((item0) => item0),
208
+ msg: json['msg'],
209
+ type: json['type'],
210
+ };
211
+ },
212
+ };
213
+ }
214
+
215
+ /**
216
+ * Client configuration for TestApi
217
+ */
218
+ export interface TestApiConfig {
219
+ /**
220
+ * Base URL for the API
221
+ */
222
+ url: string;
223
+ /**
224
+ * Custom instance of fetch. By default the global 'fetch' is used.
225
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
226
+ */
227
+ fetch?: typeof fetch;
228
+ /**
229
+ * Additional configuration
230
+ */
231
+ options?: {
232
+ /**
233
+ * By default, the client will add a Content-Type header, set to the media type defined for
234
+ * the request in the OpenAPI specification.
235
+ * Set this to false to omit this header.
236
+ */
237
+ omitContentTypeHeader?: boolean;
238
+ };
239
+ }
240
+
241
+ /**
242
+ * API Client for TestApi
243
+ */
244
+ export class TestApi {
245
+ private $config: TestApiConfig;
246
+
247
+ constructor(config: TestApiConfig) {
248
+ this.$config = config;
249
+
250
+ this.echo = this.echo.bind(this);
251
+ }
252
+
253
+ private $url = (
254
+ path: string,
255
+ pathParameters: { [key: string]: any },
256
+ queryParameters: { [key: string]: any },
257
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
258
+ ): string => {
259
+ const baseUrl = this.$config.url.endsWith('/')
260
+ ? this.$config.url.slice(0, -1)
261
+ : this.$config.url;
262
+ const pathWithParameters = Object.entries(pathParameters).reduce(
263
+ (withParams, [key, value]) =>
264
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
265
+ path,
266
+ );
267
+ const queryString = Object.entries(queryParameters)
268
+ .map(([key, value]) => {
269
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
270
+ return value
271
+ .map(
272
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
273
+ )
274
+ .join('&');
275
+ }
276
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
277
+ })
278
+ .join('&');
279
+ return (
280
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
281
+ );
282
+ };
283
+
284
+ private $headers = (
285
+ headerParameters: { [key: string]: any },
286
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
287
+ ): [string, string][] => {
288
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
289
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
290
+ return value.map((v) => [key, String(v)]) as [string, string][];
291
+ }
292
+ return [[key, String(value)]];
293
+ });
294
+ };
295
+
296
+ private $fetch: typeof fetch = (...args) =>
297
+ (this.$config.fetch ?? fetch)(...args);
298
+
299
+ public async echo(input: EchoRequest): Promise<EchoOutput> {
300
+ const pathParameters: { [key: string]: any } = {};
301
+ const queryParameters: { [key: string]: any } =
302
+ $IO.EchoRequestQueryParameters.toJson(input);
303
+ const headerParameters: { [key: string]: any } = {};
304
+ const collectionFormats = {
305
+ message: 'multi',
306
+ } as const;
307
+
308
+ const body = undefined;
309
+
310
+ const response = await this.$fetch(
311
+ this.$url('/echo', pathParameters, queryParameters, collectionFormats),
312
+ {
313
+ headers: this.$headers(headerParameters, collectionFormats),
314
+ method: 'GET',
315
+ body,
316
+ },
317
+ );
318
+
319
+ if (response.status === 200) {
320
+ return $IO.EchoOutput.fromJson(await response.json());
321
+ }
322
+ if (response.status === 422) {
323
+ throw {
324
+ status: response.status,
325
+ error: $IO.HTTPValidationError.fromJson(await response.json()),
326
+ };
327
+ }
328
+ if (response.status === 500) {
329
+ throw {
330
+ status: response.status,
331
+ error: $IO.InternalServerErrorDetails.fromJson(await response.json()),
332
+ };
333
+ }
334
+ throw new Error(
335
+ \`Unknown response status \${response.status} returned by API\`,
336
+ );
337
+ }
338
+ }
339
+ "
340
+ `;
341
+
342
+ exports[`openApiTsClientGenerator - FastAPI > should handle FastAPI validation error schemas with anyOf types 1`] = `
343
+ "export type LocationItem = string | number;
344
+ export type TestValidation422Response = {
345
+ detail?: Array<ValidationError>;
346
+ };
347
+ export type TestValidationRequestContent = {
348
+ value: number;
349
+ };
350
+ export type ValidationError = {
351
+ loc: Array<LocationItem>;
352
+ msg: string;
353
+ type: string;
354
+ };
355
+
356
+ export type TestValidationRequest = TestValidationRequestContent | undefined;
357
+ export type TestValidation422Error = {
358
+ status: 422;
359
+ error: TestValidation422Response;
360
+ };
361
+ export type TestValidationError = TestValidation422Error;
362
+ "
363
+ `;
364
+
365
+ exports[`openApiTsClientGenerator - FastAPI > should handle FastAPI validation error schemas with anyOf types 2`] = `
366
+ "import type {
367
+ LocationItem,
368
+ TestValidation422Response,
369
+ TestValidationRequestContent,
370
+ ValidationError,
371
+ TestValidationRequest,
372
+ } from './types.gen.js';
373
+
374
+ /**
375
+ * Utility for serialisation and deserialisation of API types.
376
+ */
377
+ export class $IO {
378
+ protected static $mapValues = (data: any, fn: (item: any) => any) =>
379
+ Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
380
+
381
+ public static LocationItem = {
382
+ toJson: (model: LocationItem): any => {
383
+ if (model === undefined || model === null) {
384
+ return model;
385
+ }
386
+ if (typeof model === 'string') {
387
+ return model;
388
+ }
389
+ if (typeof model === 'number') {
390
+ return model;
391
+ }
392
+ return model;
393
+ },
394
+ fromJson: (json: any): LocationItem => {
395
+ if (json === undefined || json === null) {
396
+ return json;
397
+ }
398
+ if (typeof json === 'string') {
399
+ return json;
400
+ }
401
+ if (typeof json === 'number') {
402
+ return json;
403
+ }
404
+ return json;
405
+ },
406
+ };
407
+
408
+ public static TestValidation422Response = {
409
+ toJson: (model: TestValidation422Response): any => {
410
+ if (model === undefined || model === null) {
411
+ return model;
412
+ }
413
+ return {
414
+ ...(model.detail === undefined
415
+ ? {}
416
+ : {
417
+ detail: model.detail.map($IO.ValidationError.toJson),
418
+ }),
419
+ };
420
+ },
421
+ fromJson: (json: any): TestValidation422Response => {
422
+ if (json === undefined || json === null) {
423
+ return json;
424
+ }
425
+ return {
426
+ ...(json['detail'] === undefined
427
+ ? {}
428
+ : {
429
+ detail: (json['detail'] as Array<any>).map(
430
+ $IO.ValidationError.fromJson,
431
+ ),
432
+ }),
433
+ };
434
+ },
435
+ };
436
+
437
+ public static TestValidationRequestContent = {
438
+ toJson: (model: TestValidationRequestContent): any => {
439
+ if (model === undefined || model === null) {
440
+ return model;
441
+ }
442
+ return {
443
+ ...(model.value === undefined
444
+ ? {}
445
+ : {
446
+ value: model.value,
447
+ }),
448
+ };
449
+ },
450
+ fromJson: (json: any): TestValidationRequestContent => {
451
+ if (json === undefined || json === null) {
452
+ return json;
453
+ }
454
+ return {
455
+ value: json['value'],
456
+ };
457
+ },
458
+ };
459
+
460
+ public static ValidationError = {
461
+ toJson: (model: ValidationError): any => {
462
+ if (model === undefined || model === null) {
463
+ return model;
464
+ }
465
+ return {
466
+ ...(model.loc === undefined
467
+ ? {}
468
+ : {
469
+ loc: model.loc.map((item0) => item0),
470
+ }),
471
+ ...(model.msg === undefined
472
+ ? {}
473
+ : {
474
+ msg: model.msg,
475
+ }),
476
+ ...(model.type === undefined
477
+ ? {}
478
+ : {
479
+ type: model.type,
480
+ }),
481
+ };
482
+ },
483
+ fromJson: (json: any): ValidationError => {
484
+ if (json === undefined || json === null) {
485
+ return json;
486
+ }
487
+ return {
488
+ loc: (json['loc'] as Array<any>).map((item0) => item0),
489
+ msg: json['msg'],
490
+ type: json['type'],
491
+ };
492
+ },
493
+ };
494
+ }
495
+
496
+ /**
497
+ * Client configuration for TestApi
498
+ */
499
+ export interface TestApiConfig {
500
+ /**
501
+ * Base URL for the API
502
+ */
503
+ url: string;
504
+ /**
505
+ * Custom instance of fetch. By default the global 'fetch' is used.
506
+ * You can override this to add custom middleware for use cases such as adding authentication headers.
507
+ */
508
+ fetch?: typeof fetch;
509
+ /**
510
+ * Additional configuration
511
+ */
512
+ options?: {
513
+ /**
514
+ * By default, the client will add a Content-Type header, set to the media type defined for
515
+ * the request in the OpenAPI specification.
516
+ * Set this to false to omit this header.
517
+ */
518
+ omitContentTypeHeader?: boolean;
519
+ };
520
+ }
521
+
522
+ /**
523
+ * API Client for TestApi
524
+ */
525
+ export class TestApi {
526
+ private $config: TestApiConfig;
527
+
528
+ constructor(config: TestApiConfig) {
529
+ this.$config = config;
530
+
531
+ this.testValidation = this.testValidation.bind(this);
532
+ }
533
+
534
+ private $url = (
535
+ path: string,
536
+ pathParameters: { [key: string]: any },
537
+ queryParameters: { [key: string]: any },
538
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
539
+ ): string => {
540
+ const baseUrl = this.$config.url.endsWith('/')
541
+ ? this.$config.url.slice(0, -1)
542
+ : this.$config.url;
543
+ const pathWithParameters = Object.entries(pathParameters).reduce(
544
+ (withParams, [key, value]) =>
545
+ withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
546
+ path,
547
+ );
548
+ const queryString = Object.entries(queryParameters)
549
+ .map(([key, value]) => {
550
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
551
+ return value
552
+ .map(
553
+ (v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
554
+ )
555
+ .join('&');
556
+ }
557
+ return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
558
+ })
559
+ .join('&');
560
+ return (
561
+ baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
562
+ );
563
+ };
564
+
565
+ private $headers = (
566
+ headerParameters: { [key: string]: any },
567
+ collectionFormats?: { [key: string]: 'multi' | 'csv' },
568
+ ): [string, string][] => {
569
+ return Object.entries(headerParameters).flatMap(([key, value]) => {
570
+ if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
571
+ return value.map((v) => [key, String(v)]) as [string, string][];
572
+ }
573
+ return [[key, String(value)]];
574
+ });
575
+ };
576
+
577
+ private $fetch: typeof fetch = (...args) =>
578
+ (this.$config.fetch ?? fetch)(...args);
579
+
580
+ public async testValidation(input?: TestValidationRequest): Promise<string> {
581
+ const pathParameters: { [key: string]: any } = {};
582
+ const queryParameters: { [key: string]: any } = {};
583
+ const headerParameters: { [key: string]: any } = {};
584
+ if (!this.$config.options?.omitContentTypeHeader) {
585
+ headerParameters['Content-Type'] = 'application/json';
586
+ }
587
+ const body =
588
+ input === undefined
589
+ ? undefined
590
+ : typeof input === 'object'
591
+ ? JSON.stringify($IO.TestValidationRequestContent.toJson(input))
592
+ : String($IO.TestValidationRequestContent.toJson(input));
593
+
594
+ const response = await this.$fetch(
595
+ this.$url('/test', pathParameters, queryParameters),
596
+ {
597
+ headers: this.$headers(headerParameters),
598
+ method: 'POST',
599
+ body,
600
+ },
601
+ );
602
+
603
+ if (response.status === 200) {
604
+ return await response.text();
605
+ }
606
+ if (response.status === 422) {
607
+ throw {
608
+ status: response.status,
609
+ error: $IO.TestValidation422Response.fromJson(await response.json()),
610
+ };
611
+ }
612
+ throw new Error(
613
+ \`Unknown response status \${response.status} returned by API\`,
614
+ );
615
+ }
616
+ }
617
+ "
618
+ `;