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