@aws/nx-plugin 0.39.2 → 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.
- package/package.json +1 -1
- package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +10 -10
- package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +0 -6
- package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +529 -0
- package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +618 -0
- package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +2157 -0
- package/src/open-api/ts-client/__snapshots__/generator.streaming.spec.ts.snap +1 -1
- package/src/open-api/ts-client/files/client.gen.ts.template +10 -10
- package/src/open-api/ts-client/files/types.gen.ts.template +3 -3
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +1 -1
- package/src/open-api/utils/codegen-data/languages.d.ts +1 -0
- package/src/open-api/utils/codegen-data/languages.js +38 -4
- package/src/open-api/utils/codegen-data/languages.js.map +1 -1
- package/src/open-api/utils/codegen-data.js +5 -0
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/open-api/utils/normalise.js +24 -6
- package/src/open-api/utils/normalise.js.map +1 -1
package/package.json
CHANGED
|
@@ -1985,13 +1985,13 @@ export class TestApi {
|
|
|
1985
1985
|
`;
|
|
1986
1986
|
|
|
1987
1987
|
exports[`openApiTsClientGenerator - complex types > should handle refs and hoisting of inline schemas 1`] = `
|
|
1988
|
-
"export type
|
|
1988
|
+
"export type _Error = {
|
|
1989
1989
|
code: string;
|
|
1990
1990
|
message: string;
|
|
1991
1991
|
};
|
|
1992
1992
|
export type PostTestRequestContent = {
|
|
1993
1993
|
inline?: PostTestRequestContentInline;
|
|
1994
|
-
referenced?:
|
|
1994
|
+
referenced?: _Error;
|
|
1995
1995
|
};
|
|
1996
1996
|
export type PostTestRequestContentInline = {
|
|
1997
1997
|
name?: string;
|
|
@@ -2005,7 +2005,7 @@ export type PostTestRequestContentInlineDetails = {
|
|
|
2005
2005
|
export type PostTestRequest = PostTestRequestContent;
|
|
2006
2006
|
export type PostTest400Error = {
|
|
2007
2007
|
status: 400;
|
|
2008
|
-
error:
|
|
2008
|
+
error: _Error;
|
|
2009
2009
|
};
|
|
2010
2010
|
export type PostTestError = PostTest400Error;
|
|
2011
2011
|
"
|
|
@@ -2013,7 +2013,7 @@ export type PostTestError = PostTest400Error;
|
|
|
2013
2013
|
|
|
2014
2014
|
exports[`openApiTsClientGenerator - complex types > should handle refs and hoisting of inline schemas 2`] = `
|
|
2015
2015
|
"import type {
|
|
2016
|
-
|
|
2016
|
+
_Error,
|
|
2017
2017
|
PostTestRequestContent,
|
|
2018
2018
|
PostTestRequestContentInline,
|
|
2019
2019
|
PostTestRequestContentInlineDetails,
|
|
@@ -2027,8 +2027,8 @@ export class $IO {
|
|
|
2027
2027
|
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
2028
2028
|
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
2029
2029
|
|
|
2030
|
-
public static
|
|
2031
|
-
toJson: (model:
|
|
2030
|
+
public static _Error = {
|
|
2031
|
+
toJson: (model: _Error): any => {
|
|
2032
2032
|
if (model === undefined || model === null) {
|
|
2033
2033
|
return model;
|
|
2034
2034
|
}
|
|
@@ -2045,7 +2045,7 @@ export class $IO {
|
|
|
2045
2045
|
}),
|
|
2046
2046
|
};
|
|
2047
2047
|
},
|
|
2048
|
-
fromJson: (json: any):
|
|
2048
|
+
fromJson: (json: any): _Error => {
|
|
2049
2049
|
if (json === undefined || json === null) {
|
|
2050
2050
|
return json;
|
|
2051
2051
|
}
|
|
@@ -2070,7 +2070,7 @@ export class $IO {
|
|
|
2070
2070
|
...(model.referenced === undefined
|
|
2071
2071
|
? {}
|
|
2072
2072
|
: {
|
|
2073
|
-
referenced: $IO.
|
|
2073
|
+
referenced: $IO._Error.toJson(model.referenced),
|
|
2074
2074
|
}),
|
|
2075
2075
|
};
|
|
2076
2076
|
},
|
|
@@ -2087,7 +2087,7 @@ export class $IO {
|
|
|
2087
2087
|
...(json['referenced'] === undefined
|
|
2088
2088
|
? {}
|
|
2089
2089
|
: {
|
|
2090
|
-
referenced: $IO.
|
|
2090
|
+
referenced: $IO._Error.fromJson(json['referenced']),
|
|
2091
2091
|
}),
|
|
2092
2092
|
};
|
|
2093
2093
|
},
|
|
@@ -2283,7 +2283,7 @@ export class TestApi {
|
|
|
2283
2283
|
if (response.status === 400) {
|
|
2284
2284
|
throw {
|
|
2285
2285
|
status: response.status,
|
|
2286
|
-
error: $IO.
|
|
2286
|
+
error: $IO._Error.fromJson(await response.json()),
|
|
2287
2287
|
};
|
|
2288
2288
|
}
|
|
2289
2289
|
throw new Error(
|
|
@@ -671,9 +671,6 @@ export class $IO {
|
|
|
671
671
|
if (model === undefined || model === null) {
|
|
672
672
|
return model;
|
|
673
673
|
}
|
|
674
|
-
if (typeof model === 'string') {
|
|
675
|
-
return model;
|
|
676
|
-
}
|
|
677
674
|
return model;
|
|
678
675
|
},
|
|
679
676
|
fromJson: (json: any): TestAnyOfEnumRequestContentAnyType => {
|
|
@@ -1389,9 +1386,6 @@ export class $IO {
|
|
|
1389
1386
|
if (typeof model === 'string') {
|
|
1390
1387
|
return model;
|
|
1391
1388
|
}
|
|
1392
|
-
if (typeof model === 'string') {
|
|
1393
|
-
return model;
|
|
1394
|
-
}
|
|
1395
1389
|
return model;
|
|
1396
1390
|
},
|
|
1397
1391
|
fromJson: (json: any): TestCompositesRequestContent => {
|
|
@@ -1,5 +1,534 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
+
exports[`openApiTsClientGenerator - duplicate types > should handle duplicated model names 1`] = `
|
|
4
|
+
"export type Clash = {
|
|
5
|
+
anotherProperty: string;
|
|
6
|
+
};
|
|
7
|
+
export type Clash1 = {
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
export type MyModel = Clash1 | string;
|
|
11
|
+
|
|
12
|
+
export type OperationRequest = MyModel;
|
|
13
|
+
export type OperationError = never;
|
|
14
|
+
"
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`openApiTsClientGenerator - duplicate types > should handle duplicated model names 2`] = `
|
|
18
|
+
"import type { Clash, Clash1, MyModel, OperationRequest } from './types.gen.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Utility for serialisation and deserialisation of API types.
|
|
22
|
+
*/
|
|
23
|
+
export class $IO {
|
|
24
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
25
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
26
|
+
|
|
27
|
+
public static Clash = {
|
|
28
|
+
toJson: (model: Clash): any => {
|
|
29
|
+
if (model === undefined || model === null) {
|
|
30
|
+
return model;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
...(model.anotherProperty === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: {
|
|
36
|
+
anotherProperty: model.anotherProperty,
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
fromJson: (json: any): Clash => {
|
|
41
|
+
if (json === undefined || json === null) {
|
|
42
|
+
return json;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
anotherProperty: json['anotherProperty'],
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
public static Clash1 = {
|
|
51
|
+
toJson: (model: Clash1): any => {
|
|
52
|
+
if (model === undefined || model === null) {
|
|
53
|
+
return model;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
...(model.message === undefined
|
|
57
|
+
? {}
|
|
58
|
+
: {
|
|
59
|
+
message: model.message,
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
fromJson: (json: any): Clash1 => {
|
|
64
|
+
if (json === undefined || json === null) {
|
|
65
|
+
return json;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
message: json['message'],
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
public static MyModel = {
|
|
74
|
+
toJson: (model: MyModel): any => {
|
|
75
|
+
if (model === undefined || model === null) {
|
|
76
|
+
return model;
|
|
77
|
+
}
|
|
78
|
+
if (typeof model === 'string') {
|
|
79
|
+
return model;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
...$IO.Clash1.toJson(model as Clash1),
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
fromJson: (json: any): MyModel => {
|
|
86
|
+
if (json === undefined || json === null) {
|
|
87
|
+
return json;
|
|
88
|
+
}
|
|
89
|
+
if (typeof json === 'string') {
|
|
90
|
+
return json;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...$IO.Clash1.fromJson(json),
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Client configuration for TestApi
|
|
101
|
+
*/
|
|
102
|
+
export interface TestApiConfig {
|
|
103
|
+
/**
|
|
104
|
+
* Base URL for the API
|
|
105
|
+
*/
|
|
106
|
+
url: string;
|
|
107
|
+
/**
|
|
108
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
109
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
110
|
+
*/
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
/**
|
|
113
|
+
* Additional configuration
|
|
114
|
+
*/
|
|
115
|
+
options?: {
|
|
116
|
+
/**
|
|
117
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
118
|
+
* the request in the OpenAPI specification.
|
|
119
|
+
* Set this to false to omit this header.
|
|
120
|
+
*/
|
|
121
|
+
omitContentTypeHeader?: boolean;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* API Client for TestApi
|
|
127
|
+
*/
|
|
128
|
+
export class TestApi {
|
|
129
|
+
private $config: TestApiConfig;
|
|
130
|
+
|
|
131
|
+
constructor(config: TestApiConfig) {
|
|
132
|
+
this.$config = config;
|
|
133
|
+
|
|
134
|
+
this.operation = this.operation.bind(this);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private $url = (
|
|
138
|
+
path: string,
|
|
139
|
+
pathParameters: { [key: string]: any },
|
|
140
|
+
queryParameters: { [key: string]: any },
|
|
141
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
142
|
+
): string => {
|
|
143
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
144
|
+
? this.$config.url.slice(0, -1)
|
|
145
|
+
: this.$config.url;
|
|
146
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
147
|
+
(withParams, [key, value]) =>
|
|
148
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
149
|
+
path,
|
|
150
|
+
);
|
|
151
|
+
const queryString = Object.entries(queryParameters)
|
|
152
|
+
.map(([key, value]) => {
|
|
153
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
154
|
+
return value
|
|
155
|
+
.map(
|
|
156
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
157
|
+
)
|
|
158
|
+
.join('&');
|
|
159
|
+
}
|
|
160
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
161
|
+
})
|
|
162
|
+
.join('&');
|
|
163
|
+
return (
|
|
164
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
private $headers = (
|
|
169
|
+
headerParameters: { [key: string]: any },
|
|
170
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
171
|
+
): [string, string][] => {
|
|
172
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
173
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
174
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
175
|
+
}
|
|
176
|
+
return [[key, String(value)]];
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
private $fetch: typeof fetch = (...args) =>
|
|
181
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
182
|
+
|
|
183
|
+
public async operation(input: OperationRequest): Promise<Clash> {
|
|
184
|
+
const pathParameters: { [key: string]: any } = {};
|
|
185
|
+
const queryParameters: { [key: string]: any } = {};
|
|
186
|
+
const headerParameters: { [key: string]: any } = {};
|
|
187
|
+
if (!this.$config.options?.omitContentTypeHeader) {
|
|
188
|
+
headerParameters['Content-Type'] = 'application/json';
|
|
189
|
+
}
|
|
190
|
+
const body =
|
|
191
|
+
typeof input === 'object'
|
|
192
|
+
? JSON.stringify($IO.MyModel.toJson(input))
|
|
193
|
+
: String($IO.MyModel.toJson(input));
|
|
194
|
+
|
|
195
|
+
const response = await this.$fetch(
|
|
196
|
+
this.$url('/operation', pathParameters, queryParameters),
|
|
197
|
+
{
|
|
198
|
+
headers: this.$headers(headerParameters),
|
|
199
|
+
method: 'POST',
|
|
200
|
+
body,
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (response.status === 200) {
|
|
205
|
+
return $IO.Clash.fromJson(await response.json());
|
|
206
|
+
}
|
|
207
|
+
throw new Error(
|
|
208
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
"
|
|
213
|
+
`;
|
|
214
|
+
|
|
215
|
+
exports[`openApiTsClientGenerator - duplicate types > should handle many duplicated model names 1`] = `
|
|
216
|
+
"export type AnotherModel = Clash3 | Clash4;
|
|
217
|
+
export type Clash = {
|
|
218
|
+
prop3: string;
|
|
219
|
+
};
|
|
220
|
+
export type Clash1 = {
|
|
221
|
+
prop1: string;
|
|
222
|
+
};
|
|
223
|
+
export type Clash2 = {
|
|
224
|
+
prop2: string;
|
|
225
|
+
};
|
|
226
|
+
export type Clash3 = {
|
|
227
|
+
prop4: string;
|
|
228
|
+
};
|
|
229
|
+
export type Clash4 = {
|
|
230
|
+
prop5: string;
|
|
231
|
+
};
|
|
232
|
+
export type MyModel = Clash1 | Clash2;
|
|
233
|
+
|
|
234
|
+
export type OperationRequest = MyModel;
|
|
235
|
+
export type OperationError = never;
|
|
236
|
+
"
|
|
237
|
+
`;
|
|
238
|
+
|
|
239
|
+
exports[`openApiTsClientGenerator - duplicate types > should handle many duplicated model names 2`] = `
|
|
240
|
+
"import type {
|
|
241
|
+
AnotherModel,
|
|
242
|
+
Clash,
|
|
243
|
+
Clash1,
|
|
244
|
+
Clash2,
|
|
245
|
+
Clash3,
|
|
246
|
+
Clash4,
|
|
247
|
+
MyModel,
|
|
248
|
+
OperationRequest,
|
|
249
|
+
} from './types.gen.js';
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Utility for serialisation and deserialisation of API types.
|
|
253
|
+
*/
|
|
254
|
+
export class $IO {
|
|
255
|
+
protected static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
256
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
257
|
+
|
|
258
|
+
public static AnotherModel = {
|
|
259
|
+
toJson: (model: AnotherModel): any => {
|
|
260
|
+
if (model === undefined || model === null) {
|
|
261
|
+
return model;
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
...$IO.Clash3.toJson(model as Clash3),
|
|
265
|
+
...$IO.Clash4.toJson(model as Clash4),
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
fromJson: (json: any): AnotherModel => {
|
|
269
|
+
if (json === undefined || json === null) {
|
|
270
|
+
return json;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
...$IO.Clash3.fromJson(json),
|
|
274
|
+
...$IO.Clash4.fromJson(json),
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
public static Clash = {
|
|
280
|
+
toJson: (model: Clash): any => {
|
|
281
|
+
if (model === undefined || model === null) {
|
|
282
|
+
return model;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
...(model.prop3 === undefined
|
|
286
|
+
? {}
|
|
287
|
+
: {
|
|
288
|
+
prop3: model.prop3,
|
|
289
|
+
}),
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
fromJson: (json: any): Clash => {
|
|
293
|
+
if (json === undefined || json === null) {
|
|
294
|
+
return json;
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
prop3: json['prop3'],
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
public static Clash1 = {
|
|
303
|
+
toJson: (model: Clash1): any => {
|
|
304
|
+
if (model === undefined || model === null) {
|
|
305
|
+
return model;
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
...(model.prop1 === undefined
|
|
309
|
+
? {}
|
|
310
|
+
: {
|
|
311
|
+
prop1: model.prop1,
|
|
312
|
+
}),
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
fromJson: (json: any): Clash1 => {
|
|
316
|
+
if (json === undefined || json === null) {
|
|
317
|
+
return json;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
prop1: json['prop1'],
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
public static Clash2 = {
|
|
326
|
+
toJson: (model: Clash2): any => {
|
|
327
|
+
if (model === undefined || model === null) {
|
|
328
|
+
return model;
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
...(model.prop2 === undefined
|
|
332
|
+
? {}
|
|
333
|
+
: {
|
|
334
|
+
prop2: model.prop2,
|
|
335
|
+
}),
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
fromJson: (json: any): Clash2 => {
|
|
339
|
+
if (json === undefined || json === null) {
|
|
340
|
+
return json;
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
prop2: json['prop2'],
|
|
344
|
+
};
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
public static Clash3 = {
|
|
349
|
+
toJson: (model: Clash3): any => {
|
|
350
|
+
if (model === undefined || model === null) {
|
|
351
|
+
return model;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
...(model.prop4 === undefined
|
|
355
|
+
? {}
|
|
356
|
+
: {
|
|
357
|
+
prop4: model.prop4,
|
|
358
|
+
}),
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
fromJson: (json: any): Clash3 => {
|
|
362
|
+
if (json === undefined || json === null) {
|
|
363
|
+
return json;
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
prop4: json['prop4'],
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
public static Clash4 = {
|
|
372
|
+
toJson: (model: Clash4): any => {
|
|
373
|
+
if (model === undefined || model === null) {
|
|
374
|
+
return model;
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
...(model.prop5 === undefined
|
|
378
|
+
? {}
|
|
379
|
+
: {
|
|
380
|
+
prop5: model.prop5,
|
|
381
|
+
}),
|
|
382
|
+
};
|
|
383
|
+
},
|
|
384
|
+
fromJson: (json: any): Clash4 => {
|
|
385
|
+
if (json === undefined || json === null) {
|
|
386
|
+
return json;
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
prop5: json['prop5'],
|
|
390
|
+
};
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
public static MyModel = {
|
|
395
|
+
toJson: (model: MyModel): any => {
|
|
396
|
+
if (model === undefined || model === null) {
|
|
397
|
+
return model;
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
...$IO.Clash1.toJson(model as Clash1),
|
|
401
|
+
...$IO.Clash2.toJson(model as Clash2),
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
fromJson: (json: any): MyModel => {
|
|
405
|
+
if (json === undefined || json === null) {
|
|
406
|
+
return json;
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
...$IO.Clash1.fromJson(json),
|
|
410
|
+
...$IO.Clash2.fromJson(json),
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Client configuration for TestApi
|
|
418
|
+
*/
|
|
419
|
+
export interface TestApiConfig {
|
|
420
|
+
/**
|
|
421
|
+
* Base URL for the API
|
|
422
|
+
*/
|
|
423
|
+
url: string;
|
|
424
|
+
/**
|
|
425
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
426
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
427
|
+
*/
|
|
428
|
+
fetch?: typeof fetch;
|
|
429
|
+
/**
|
|
430
|
+
* Additional configuration
|
|
431
|
+
*/
|
|
432
|
+
options?: {
|
|
433
|
+
/**
|
|
434
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
435
|
+
* the request in the OpenAPI specification.
|
|
436
|
+
* Set this to false to omit this header.
|
|
437
|
+
*/
|
|
438
|
+
omitContentTypeHeader?: boolean;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* API Client for TestApi
|
|
444
|
+
*/
|
|
445
|
+
export class TestApi {
|
|
446
|
+
private $config: TestApiConfig;
|
|
447
|
+
|
|
448
|
+
constructor(config: TestApiConfig) {
|
|
449
|
+
this.$config = config;
|
|
450
|
+
|
|
451
|
+
this.operation = this.operation.bind(this);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private $url = (
|
|
455
|
+
path: string,
|
|
456
|
+
pathParameters: { [key: string]: any },
|
|
457
|
+
queryParameters: { [key: string]: any },
|
|
458
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
459
|
+
): string => {
|
|
460
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
461
|
+
? this.$config.url.slice(0, -1)
|
|
462
|
+
: this.$config.url;
|
|
463
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
464
|
+
(withParams, [key, value]) =>
|
|
465
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
466
|
+
path,
|
|
467
|
+
);
|
|
468
|
+
const queryString = Object.entries(queryParameters)
|
|
469
|
+
.map(([key, value]) => {
|
|
470
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
471
|
+
return value
|
|
472
|
+
.map(
|
|
473
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
474
|
+
)
|
|
475
|
+
.join('&');
|
|
476
|
+
}
|
|
477
|
+
return \`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(',') : String(value))}\`;
|
|
478
|
+
})
|
|
479
|
+
.join('&');
|
|
480
|
+
return (
|
|
481
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
482
|
+
);
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
private $headers = (
|
|
486
|
+
headerParameters: { [key: string]: any },
|
|
487
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' },
|
|
488
|
+
): [string, string][] => {
|
|
489
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
490
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
491
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
492
|
+
}
|
|
493
|
+
return [[key, String(value)]];
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
private $fetch: typeof fetch = (...args) =>
|
|
498
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
499
|
+
|
|
500
|
+
public async operation(input: OperationRequest): Promise<Clash> {
|
|
501
|
+
const pathParameters: { [key: string]: any } = {};
|
|
502
|
+
const queryParameters: { [key: string]: any } = {};
|
|
503
|
+
const headerParameters: { [key: string]: any } = {};
|
|
504
|
+
if (!this.$config.options?.omitContentTypeHeader) {
|
|
505
|
+
headerParameters['Content-Type'] = 'application/json';
|
|
506
|
+
}
|
|
507
|
+
const body =
|
|
508
|
+
typeof input === 'object'
|
|
509
|
+
? JSON.stringify($IO.MyModel.toJson(input))
|
|
510
|
+
: String($IO.MyModel.toJson(input));
|
|
511
|
+
|
|
512
|
+
const response = await this.$fetch(
|
|
513
|
+
this.$url('/operation', pathParameters, queryParameters),
|
|
514
|
+
{
|
|
515
|
+
headers: this.$headers(headerParameters),
|
|
516
|
+
method: 'POST',
|
|
517
|
+
body,
|
|
518
|
+
},
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
if (response.status === 200) {
|
|
522
|
+
return $IO.Clash.fromJson(await response.json());
|
|
523
|
+
}
|
|
524
|
+
throw new Error(
|
|
525
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
"
|
|
530
|
+
`;
|
|
531
|
+
|
|
3
532
|
exports[`openApiTsClientGenerator - duplicate types > should handle multiple operation ID conflicts 1`] = `
|
|
4
533
|
"export type OrderRequest = {
|
|
5
534
|
item: string;
|