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