@azure-tools/typespec-rust 0.14.1 → 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/dist/src/codegen/clients.js +45 -15
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/codeGenerator.d.ts.map +1 -1
- package/dist/src/codegen/codeGenerator.js +14 -24
- package/dist/src/codegen/codeGenerator.js.map +1 -1
- package/dist/src/codegen/context.d.ts +14 -13
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +53 -30
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/enums.d.ts.map +1 -1
- package/dist/src/codegen/enums.js +2 -2
- package/dist/src/codegen/enums.js.map +1 -1
- package/dist/src/codegen/headerTraits.js +3 -3
- package/dist/src/codegen/headerTraits.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts +9 -0
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +23 -5
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/models.d.ts +2 -0
- package/dist/src/codegen/models.d.ts.map +1 -1
- package/dist/src/codegen/models.js +157 -38
- package/dist/src/codegen/models.js.map +1 -1
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +7 -1
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +3 -1
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/types.d.ts +53 -20
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +39 -12
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +171 -81
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/src/tcgcadapter/helpers.d.ts +12 -2
- package/dist/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/src/tcgcadapter/helpers.js +28 -2
- package/dist/src/tcgcadapter/helpers.js.map +1 -1
- package/package.json +17 -17
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { CrateDependency } from './crate.js';
|
|
6
|
+
/** ModelFieldFlags contains bit flags describing field usage */
|
|
7
|
+
export var ModelFieldFlags;
|
|
8
|
+
(function (ModelFieldFlags) {
|
|
9
|
+
ModelFieldFlags[ModelFieldFlags["Unspecified"] = 0] = "Unspecified";
|
|
10
|
+
/** field contains the page of items in a paged response */
|
|
11
|
+
ModelFieldFlags[ModelFieldFlags["PageItems"] = 1] = "PageItems";
|
|
12
|
+
})(ModelFieldFlags || (ModelFieldFlags = {}));
|
|
6
13
|
/** ModelFlags contains bit flags describing model usage */
|
|
7
14
|
export var ModelFlags;
|
|
8
15
|
(function (ModelFlags) {
|
|
@@ -19,14 +26,14 @@ export class QualifiedType {
|
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
class External extends QualifiedType {
|
|
22
|
-
constructor(crate, name, path) {
|
|
29
|
+
constructor(crate, name, path, features = new Array) {
|
|
23
30
|
super(name, path);
|
|
24
31
|
let crateName = this.path;
|
|
25
32
|
const pathSep = crateName.indexOf('::');
|
|
26
33
|
if (pathSep > 0) {
|
|
27
34
|
crateName = crateName.substring(0, pathSep);
|
|
28
35
|
}
|
|
29
|
-
crate.addDependency(new CrateDependency(crateName));
|
|
36
|
+
crate.addDependency(new CrateDependency(crateName, features));
|
|
30
37
|
}
|
|
31
38
|
}
|
|
32
39
|
class StructBase {
|
|
@@ -67,9 +74,10 @@ export class Bytes extends External {
|
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
76
|
export class Decimal extends External {
|
|
70
|
-
constructor(crate) {
|
|
71
|
-
super(crate, 'Decimal', 'rust_decimal');
|
|
77
|
+
constructor(crate, stringEncoding) {
|
|
78
|
+
super(crate, 'Decimal', 'rust_decimal', !stringEncoding ? ['serde-with-float'] : undefined);
|
|
72
79
|
this.kind = 'decimal';
|
|
80
|
+
this.stringEncoding = stringEncoding;
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
export class EncodedBytes {
|
|
@@ -136,8 +144,9 @@ export class Lifetime {
|
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
export class Literal {
|
|
139
|
-
constructor(value) {
|
|
147
|
+
constructor(valueKind, value) {
|
|
140
148
|
this.kind = 'literal';
|
|
149
|
+
this.valueKind = valueKind;
|
|
141
150
|
this.value = value;
|
|
142
151
|
}
|
|
143
152
|
}
|
|
@@ -156,9 +165,11 @@ export class Model extends StructBase {
|
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
167
|
export class ModelField extends StructFieldBase {
|
|
159
|
-
constructor(name, serde, visibility, type) {
|
|
168
|
+
constructor(name, serde, visibility, type, optional) {
|
|
160
169
|
super(name, visibility, type);
|
|
161
170
|
this.kind = 'modelField';
|
|
171
|
+
this.flags = ModelFieldFlags.Unspecified;
|
|
172
|
+
this.optional = optional;
|
|
162
173
|
this.serde = serde;
|
|
163
174
|
}
|
|
164
175
|
}
|
|
@@ -176,6 +187,13 @@ export class Option {
|
|
|
176
187
|
this.type = type;
|
|
177
188
|
}
|
|
178
189
|
}
|
|
190
|
+
export class PageIterator extends External {
|
|
191
|
+
constructor(crate, type) {
|
|
192
|
+
super(crate, 'PageIterator', 'azure_core::http');
|
|
193
|
+
this.kind = 'pageIterator';
|
|
194
|
+
this.type = type;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
179
197
|
export class Pager extends External {
|
|
180
198
|
constructor(crate, type) {
|
|
181
199
|
super(crate, 'Pager', 'azure_core::http');
|
|
@@ -190,6 +208,12 @@ export class Payload {
|
|
|
190
208
|
this.format = format;
|
|
191
209
|
}
|
|
192
210
|
}
|
|
211
|
+
export class RawResponse extends External {
|
|
212
|
+
constructor(crate) {
|
|
213
|
+
super(crate, 'RawResponse', 'azure_core::http');
|
|
214
|
+
this.kind = 'rawResponse';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
193
217
|
export class Ref {
|
|
194
218
|
constructor(type) {
|
|
195
219
|
this.kind = 'ref';
|
|
@@ -210,11 +234,6 @@ export class Response extends External {
|
|
|
210
234
|
this.content = content;
|
|
211
235
|
}
|
|
212
236
|
}
|
|
213
|
-
export class ResponseBody {
|
|
214
|
-
constructor() {
|
|
215
|
-
this.kind = 'responseBody';
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
237
|
export class Result extends External {
|
|
219
238
|
constructor(crate, type) {
|
|
220
239
|
super(crate, 'Result', 'azure_core');
|
|
@@ -222,10 +241,18 @@ export class Result extends External {
|
|
|
222
241
|
this.type = type;
|
|
223
242
|
}
|
|
224
243
|
}
|
|
244
|
+
export class SafeInt extends External {
|
|
245
|
+
constructor(crate, stringEncoding) {
|
|
246
|
+
super(crate, 'Number', 'serde_json');
|
|
247
|
+
this.kind = 'safeint';
|
|
248
|
+
this.stringEncoding = stringEncoding;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
225
251
|
export class Scalar {
|
|
226
|
-
constructor(type) {
|
|
252
|
+
constructor(type, stringEncoding) {
|
|
227
253
|
this.kind = 'scalar';
|
|
228
254
|
this.type = type;
|
|
255
|
+
this.stringEncoding = stringEncoding;
|
|
229
256
|
}
|
|
230
257
|
}
|
|
231
258
|
export class Slice {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/codemodel/types.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAS,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/codemodel/types.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAS,eAAe,EAAE,MAAM,YAAY,CAAC;AA+MpD,gEAAgE;AAChE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OjB;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IA6O5B;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAmBjC;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IA4C5B;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAwB3B;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAiRnB;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;;;;;OAQG;IACH,OAAO,CAAC,yBAAyB;IAuEjC;;;;;;;OAOG;IACH,OAAO,CAAC,2BAA2B;IA+EnC;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAsH5B;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAqC5B;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IA2BtB;;;;;;;OAOG;IACH,OAAO,CAAC,0BAA0B;IA+BlC;;;;;OAKG;IACH,OAAO,CAAC,eAAe;CAaxB"}
|
|
@@ -69,6 +69,10 @@ export class Adapter {
|
|
|
69
69
|
let done = false;
|
|
70
70
|
for (const method of client.methods) {
|
|
71
71
|
if (method.kind === 'pageable') {
|
|
72
|
+
if (method.returns.type.kind === 'pager') {
|
|
73
|
+
this.crate.addDependency(new rust.CrateDependency('async-trait')); // required for azure_core::http::Page trait
|
|
74
|
+
}
|
|
75
|
+
// TODO: why is this here?
|
|
72
76
|
this.crate.addDependency(new rust.CrateDependency('futures'));
|
|
73
77
|
done = true;
|
|
74
78
|
break;
|
|
@@ -135,7 +139,7 @@ export class Adapter {
|
|
|
135
139
|
rustEnum.docs = this.adaptDocs(sdkEnum.summary, sdkEnum.doc);
|
|
136
140
|
this.types.set(enumName, rustEnum);
|
|
137
141
|
for (const value of sdkEnum.values) {
|
|
138
|
-
const rustEnumValue = new rust.EnumValue(helpers.fixUpEnumValueName(value
|
|
142
|
+
const rustEnumValue = new rust.EnumValue(helpers.fixUpEnumValueName(value), rustEnum, value.value);
|
|
139
143
|
rustEnumValue.docs = this.adaptDocs(value.summary, value.doc);
|
|
140
144
|
rustEnum.values.push(rustEnumValue);
|
|
141
145
|
}
|
|
@@ -153,7 +157,7 @@ export class Adapter {
|
|
|
153
157
|
const enumType = this.getEnum(sdkEnumValue.enumType);
|
|
154
158
|
// find the specified enum value
|
|
155
159
|
for (const value of enumType.values) {
|
|
156
|
-
if (value.name === helpers.fixUpEnumValueName(sdkEnumValue
|
|
160
|
+
if (value.name === helpers.fixUpEnumValueName(sdkEnumValue)) {
|
|
157
161
|
return value;
|
|
158
162
|
}
|
|
159
163
|
}
|
|
@@ -253,8 +257,20 @@ export class Adapter {
|
|
|
253
257
|
if (modelVisibility === 'pub' || property.optional) {
|
|
254
258
|
fieldType = new rust.Option(fieldType.kind === 'box' ? fieldType : this.typeToWireType(fieldType));
|
|
255
259
|
}
|
|
256
|
-
const modelField = new rust.ModelField(naming.getEscapedReservedName(snakeCaseName(property.name), 'prop'), property.serializedName, modelVisibility, fieldType);
|
|
260
|
+
const modelField = new rust.ModelField(naming.getEscapedReservedName(snakeCaseName(property.name), 'prop'), property.serializedName, modelVisibility, fieldType, property.optional);
|
|
257
261
|
modelField.docs = this.adaptDocs(property.summary, property.doc);
|
|
262
|
+
// if this is a literal, add a doc comment explaining its behavior
|
|
263
|
+
const unwrappedType = helpers.unwrapOption(fieldType);
|
|
264
|
+
if (unwrappedType.kind === 'literal') {
|
|
265
|
+
const literalDoc = `${modelField.optional ? 'When Some, field' : 'Field'} has constant value ${unwrappedType.value}. Any specified value will be ignored.`;
|
|
266
|
+
if (!modelField.docs.description) {
|
|
267
|
+
modelField.docs.description = '';
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
modelField.docs.description += '\n\n';
|
|
271
|
+
}
|
|
272
|
+
modelField.docs.description += literalDoc;
|
|
273
|
+
}
|
|
258
274
|
const xmlName = getXMLName(property.decorators);
|
|
259
275
|
if (xmlName) {
|
|
260
276
|
// use the XML name when specified
|
|
@@ -285,46 +301,6 @@ export class Adapter {
|
|
|
285
301
|
return 'unix_time';
|
|
286
302
|
}
|
|
287
303
|
};
|
|
288
|
-
const getScalar = (kind) => {
|
|
289
|
-
let scalarType;
|
|
290
|
-
switch (kind) {
|
|
291
|
-
case 'boolean':
|
|
292
|
-
scalarType = 'bool';
|
|
293
|
-
break;
|
|
294
|
-
case 'float':
|
|
295
|
-
case 'float32':
|
|
296
|
-
scalarType = 'f32';
|
|
297
|
-
break;
|
|
298
|
-
case 'float64':
|
|
299
|
-
scalarType = 'f64';
|
|
300
|
-
break;
|
|
301
|
-
case 'int16':
|
|
302
|
-
scalarType = 'i16';
|
|
303
|
-
break;
|
|
304
|
-
case 'int32':
|
|
305
|
-
scalarType = 'i32';
|
|
306
|
-
break;
|
|
307
|
-
case 'int64':
|
|
308
|
-
scalarType = 'i64';
|
|
309
|
-
break;
|
|
310
|
-
case 'int8':
|
|
311
|
-
scalarType = 'i8';
|
|
312
|
-
break;
|
|
313
|
-
case 'uint16':
|
|
314
|
-
scalarType = 'u16';
|
|
315
|
-
break;
|
|
316
|
-
case 'uint32':
|
|
317
|
-
scalarType = 'u32';
|
|
318
|
-
break;
|
|
319
|
-
case 'uint64':
|
|
320
|
-
scalarType = 'u64';
|
|
321
|
-
break;
|
|
322
|
-
case 'uint8':
|
|
323
|
-
scalarType = 'u8';
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
return this.getScalar(scalarType);
|
|
327
|
-
};
|
|
328
304
|
switch (type.kind) {
|
|
329
305
|
case 'array':
|
|
330
306
|
return this.getVec(this.typeToWireType(this.getType(type.valueType, stack)));
|
|
@@ -339,10 +315,10 @@ export class Adapter {
|
|
|
339
315
|
return this.getLiteral(type);
|
|
340
316
|
case 'decimal':
|
|
341
317
|
case 'decimal128': {
|
|
342
|
-
const keyName = 'decimal';
|
|
318
|
+
const keyName = 'decimal' + (type.encode ? `-${type.encode}` : '');
|
|
343
319
|
let decimalType = this.types.get(keyName);
|
|
344
320
|
if (!decimalType) {
|
|
345
|
-
decimalType = new rust.Decimal(this.crate);
|
|
321
|
+
decimalType = new rust.Decimal(this.crate, type.encode === 'string');
|
|
346
322
|
this.types.set(keyName, decimalType);
|
|
347
323
|
}
|
|
348
324
|
return decimalType;
|
|
@@ -356,7 +332,7 @@ export class Adapter {
|
|
|
356
332
|
case 'float64':
|
|
357
333
|
case 'int32':
|
|
358
334
|
case 'int64':
|
|
359
|
-
return getScalar(type.wireType.kind);
|
|
335
|
+
return this.getScalar(type.wireType.kind, type.wireType.encode);
|
|
360
336
|
case 'string':
|
|
361
337
|
return this.getStringType();
|
|
362
338
|
default:
|
|
@@ -373,7 +349,7 @@ export class Adapter {
|
|
|
373
349
|
case 'uint32':
|
|
374
350
|
case 'uint64':
|
|
375
351
|
case 'uint8':
|
|
376
|
-
return getScalar(type.kind);
|
|
352
|
+
return this.getScalar(type.kind, type.encode);
|
|
377
353
|
case 'enum':
|
|
378
354
|
return this.getEnum(type);
|
|
379
355
|
case 'enumvalue':
|
|
@@ -381,6 +357,8 @@ export class Adapter {
|
|
|
381
357
|
case 'model':
|
|
382
358
|
return this.getModel(type, stack);
|
|
383
359
|
case 'endpoint':
|
|
360
|
+
case 'plainDate':
|
|
361
|
+
case 'plainTime':
|
|
384
362
|
case 'string':
|
|
385
363
|
case 'url': {
|
|
386
364
|
if (type.kind === 'string' && type.crossLanguageDefinitionId === 'Azure.Core.eTag') {
|
|
@@ -409,6 +387,15 @@ export class Adapter {
|
|
|
409
387
|
this.types.set(keyName, timeType);
|
|
410
388
|
return timeType;
|
|
411
389
|
}
|
|
390
|
+
case 'safeint': {
|
|
391
|
+
const keyName = type.kind + (type.encode ? `-${type.encode}` : '');
|
|
392
|
+
let safeint = this.types.get(keyName);
|
|
393
|
+
if (!safeint) {
|
|
394
|
+
safeint = new rust.SafeInt(this.crate, type.encode === 'string');
|
|
395
|
+
this.types.set(keyName, safeint);
|
|
396
|
+
}
|
|
397
|
+
return safeint;
|
|
398
|
+
}
|
|
412
399
|
case 'unknown': {
|
|
413
400
|
const keyName = 'jsonValue';
|
|
414
401
|
let anyType = this.types.get(keyName);
|
|
@@ -467,11 +454,49 @@ export class Adapter {
|
|
|
467
454
|
return refType;
|
|
468
455
|
}
|
|
469
456
|
/** returns a scalar for the specified scalar type */
|
|
470
|
-
getScalar(type) {
|
|
471
|
-
let
|
|
457
|
+
getScalar(type, encode) {
|
|
458
|
+
let scalarType;
|
|
459
|
+
switch (type) {
|
|
460
|
+
case 'boolean':
|
|
461
|
+
scalarType = 'bool';
|
|
462
|
+
break;
|
|
463
|
+
case 'float':
|
|
464
|
+
case 'float32':
|
|
465
|
+
scalarType = 'f32';
|
|
466
|
+
break;
|
|
467
|
+
case 'float64':
|
|
468
|
+
scalarType = 'f64';
|
|
469
|
+
break;
|
|
470
|
+
case 'int16':
|
|
471
|
+
scalarType = 'i16';
|
|
472
|
+
break;
|
|
473
|
+
case 'int32':
|
|
474
|
+
scalarType = 'i32';
|
|
475
|
+
break;
|
|
476
|
+
case 'int64':
|
|
477
|
+
scalarType = 'i64';
|
|
478
|
+
break;
|
|
479
|
+
case 'int8':
|
|
480
|
+
scalarType = 'i8';
|
|
481
|
+
break;
|
|
482
|
+
case 'uint16':
|
|
483
|
+
scalarType = 'u16';
|
|
484
|
+
break;
|
|
485
|
+
case 'uint32':
|
|
486
|
+
scalarType = 'u32';
|
|
487
|
+
break;
|
|
488
|
+
case 'uint64':
|
|
489
|
+
scalarType = 'u64';
|
|
490
|
+
break;
|
|
491
|
+
case 'uint8':
|
|
492
|
+
scalarType = 'u8';
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
const keyName = scalarType + (encode ? `-${encode}` : '');
|
|
496
|
+
let scalar = this.types.get(keyName);
|
|
472
497
|
if (!scalar) {
|
|
473
|
-
scalar = new rust.Scalar(
|
|
474
|
-
this.types.set(
|
|
498
|
+
scalar = new rust.Scalar(scalarType, encode === 'string');
|
|
499
|
+
this.types.set(keyName, scalar);
|
|
475
500
|
}
|
|
476
501
|
return scalar;
|
|
477
502
|
}
|
|
@@ -536,12 +561,37 @@ export class Adapter {
|
|
|
536
561
|
* @returns a Rust literal
|
|
537
562
|
*/
|
|
538
563
|
getLiteral(constType) {
|
|
539
|
-
|
|
564
|
+
var _a;
|
|
565
|
+
let valueKind;
|
|
566
|
+
let keyKind;
|
|
567
|
+
switch (constType.valueType.kind) {
|
|
568
|
+
case 'boolean':
|
|
569
|
+
case 'float32':
|
|
570
|
+
case 'float64':
|
|
571
|
+
case 'int16':
|
|
572
|
+
case 'int32':
|
|
573
|
+
case 'int64':
|
|
574
|
+
case 'int8':
|
|
575
|
+
case 'uint16':
|
|
576
|
+
case 'uint32':
|
|
577
|
+
case 'uint64':
|
|
578
|
+
case 'uint8':
|
|
579
|
+
valueKind = this.getScalar(constType.valueType.kind, constType.valueType.encode);
|
|
580
|
+
keyKind = valueKind.type;
|
|
581
|
+
break;
|
|
582
|
+
case 'string':
|
|
583
|
+
valueKind = this.getStringType();
|
|
584
|
+
keyKind = valueKind.kind;
|
|
585
|
+
break;
|
|
586
|
+
default:
|
|
587
|
+
throw new AdapterError('UnsupportedTsp', `unhandled constant value kind ${constType.valueType.kind}`, (_a = constType.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
588
|
+
}
|
|
589
|
+
const literalKey = `literal-${keyKind}-${constType.value}`;
|
|
540
590
|
let literalType = this.types.get(literalKey);
|
|
541
591
|
if (literalType) {
|
|
542
592
|
return literalType;
|
|
543
593
|
}
|
|
544
|
-
literalType = new rust.Literal(constType.value);
|
|
594
|
+
literalType = new rust.Literal(valueKind, constType.value);
|
|
545
595
|
this.types.set(literalKey, literalType);
|
|
546
596
|
return literalType;
|
|
547
597
|
}
|
|
@@ -754,23 +804,22 @@ export class Adapter {
|
|
|
754
804
|
}
|
|
755
805
|
}
|
|
756
806
|
else if (parent) {
|
|
757
|
-
// this is a sub-client. it will share the fields of the parent.
|
|
807
|
+
// this is a sub-client. it will share some/all the fields of the parent.
|
|
758
808
|
// NOTE: we must propagate parant params before a potential recursive call
|
|
759
809
|
// to create a child client that will need to inherit our client params.
|
|
760
|
-
// also note that we need to make a copy of the fields array so that
|
|
761
|
-
// adding client-unique fields don't inadvertently get shared.
|
|
762
|
-
rustClient.fields = new Array(...parent.fields);
|
|
763
|
-
// adapt any unique fields on this client
|
|
764
810
|
for (const prop of client.clientInitialization.parameters) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
811
|
+
const name = snakeCaseName(prop.name);
|
|
812
|
+
const parentField = parent.fields.find((v) => v.name === name);
|
|
813
|
+
if (parentField) {
|
|
814
|
+
rustClient.fields.push(parentField);
|
|
768
815
|
continue;
|
|
769
816
|
}
|
|
770
|
-
|
|
771
|
-
|
|
817
|
+
else if (prop.kind !== 'method') {
|
|
818
|
+
// we don't need to care about non-method properties (e.g. credential)
|
|
819
|
+
// as these are handled in the parent client.
|
|
772
820
|
continue;
|
|
773
821
|
}
|
|
822
|
+
// unique field for this client
|
|
774
823
|
rustClient.fields.push(new rust.StructField(name, 'pubCrate', this.getType(prop.type)));
|
|
775
824
|
}
|
|
776
825
|
}
|
|
@@ -831,13 +880,17 @@ export class Adapter {
|
|
|
831
880
|
* @returns the Rust client parameter
|
|
832
881
|
*/
|
|
833
882
|
adaptClientParameter(param, constructable) {
|
|
834
|
-
var _a;
|
|
835
883
|
let paramType;
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
884
|
+
// the second clause is a workaround for https://github.com/Azure/typespec-azure/issues/2745
|
|
885
|
+
if (param.isApiVersionParam || (param.type.kind === 'enum' && (param.type.usage & tcgc.UsageFlags.ApiVersionEnum) === tcgc.UsageFlags.ApiVersionEnum)) {
|
|
886
|
+
if (param.clientDefaultValue) {
|
|
887
|
+
// this is optional so it goes into the client options type as a String
|
|
888
|
+
paramType = this.getStringType();
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
// this is a required param so its type is a &str
|
|
892
|
+
paramType = this.getRefType(this.getStringSlice());
|
|
839
893
|
}
|
|
840
|
-
paramType = this.getStringType();
|
|
841
894
|
}
|
|
842
895
|
else {
|
|
843
896
|
paramType = this.getType(param.type);
|
|
@@ -996,7 +1049,10 @@ export class Adapter {
|
|
|
996
1049
|
}
|
|
997
1050
|
adaptedParam.docs = this.adaptDocs(param.summary, param.doc);
|
|
998
1051
|
rustMethod.params.push(adaptedParam);
|
|
999
|
-
|
|
1052
|
+
// we specially handle an optional content-type header to ensure it's omitted
|
|
1053
|
+
// from the options bag type. this shows up when the request body is optional.
|
|
1054
|
+
// we can't generalize this to optional literal headers though.
|
|
1055
|
+
if (adaptedParam.optional && (adaptedParam.kind !== 'header' || adaptedParam.header.toLowerCase() !== 'content-type')) {
|
|
1000
1056
|
let fieldType;
|
|
1001
1057
|
if (adaptedParam.kind === 'partialBody') {
|
|
1002
1058
|
// for partial body params, adaptedParam.type is the model type that's
|
|
@@ -1068,7 +1124,6 @@ export class Adapter {
|
|
|
1068
1124
|
responseHeaders.push(header);
|
|
1069
1125
|
}
|
|
1070
1126
|
}
|
|
1071
|
-
let returnType;
|
|
1072
1127
|
if (method.kind === 'paging') {
|
|
1073
1128
|
// for paged methods, tcgc models method.response.type as an Array<T>.
|
|
1074
1129
|
// however, we want the synthesized paged response envelope type instead.
|
|
@@ -1108,6 +1163,7 @@ export class Adapter {
|
|
|
1108
1163
|
// check if this has already been unwrapped (e.g. type is shared across operations)
|
|
1109
1164
|
if (field.type.kind === 'option') {
|
|
1110
1165
|
typeToUnwrap.fields[i].type = typeToUnwrap.fields[i].type.type;
|
|
1166
|
+
typeToUnwrap.fields[i].flags |= rust.ModelFieldFlags.PageItems;
|
|
1111
1167
|
}
|
|
1112
1168
|
// move to the next segment
|
|
1113
1169
|
if (field.type.kind === 'model') {
|
|
@@ -1121,27 +1177,33 @@ export class Adapter {
|
|
|
1121
1177
|
if (unwrappedCount !== method.pagingMetadata.pageItemsSegments.length) {
|
|
1122
1178
|
throw new AdapterError('InternalError', `failed to unwrap paged items for method ${method.name}`, (_j = method.__raw) === null || _j === void 0 ? void 0 : _j.node);
|
|
1123
1179
|
}
|
|
1124
|
-
|
|
1180
|
+
// if the response contains more than the Vec<T> and next_link then use a PageIterator
|
|
1181
|
+
if (synthesizedModel.fields.length > 2) {
|
|
1182
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.PageIterator(this.crate, new rust.Response(this.crate, new rust.Payload(synthesizedModel, format))));
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.Pager(this.crate, new rust.Payload(synthesizedModel, format)));
|
|
1186
|
+
}
|
|
1125
1187
|
}
|
|
1126
1188
|
else if (method.response.type && !(method.response.type.kind === 'bytes' && method.response.type.encode === 'bytes')) {
|
|
1127
|
-
|
|
1189
|
+
const payloadResponse = new rust.Response(this.crate, new rust.Payload(this.typeToWireType(this.getType(method.response.type)), getBodyFormat()));
|
|
1190
|
+
rustMethod.returns = new rust.Result(this.crate, payloadResponse);
|
|
1128
1191
|
}
|
|
1129
1192
|
else if (responseHeaders.length > 0) {
|
|
1130
1193
|
// for methods that don't return a modeled type but return headers,
|
|
1131
1194
|
// we need to return a marker type
|
|
1132
1195
|
const markerType = new rust.MarkerType(`${rustClient.name}${codegen.pascalCase(method.name)}Result`);
|
|
1133
1196
|
markerType.docs.summary = `Contains results for ${this.asDocLink(`${rustClient.name}::${methodName}()`, `crate::generated::clients::${rustClient.name}::${methodName}()`)}`;
|
|
1134
|
-
returnType = new rust.Response(this.crate, markerType);
|
|
1135
1197
|
this.crate.models.push(markerType);
|
|
1198
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.Response(this.crate, markerType));
|
|
1136
1199
|
}
|
|
1137
1200
|
else if (method.response.type && method.response.type.kind === 'bytes' && method.response.type.encode === 'bytes') {
|
|
1138
1201
|
// bytes encoding indicates a streaming binary response
|
|
1139
|
-
|
|
1202
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.RawResponse(this.crate));
|
|
1140
1203
|
}
|
|
1141
1204
|
else {
|
|
1142
|
-
|
|
1205
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.Response(this.crate, this.getUnitType()));
|
|
1143
1206
|
}
|
|
1144
|
-
rustMethod.returns = new rust.Result(this.crate, returnType);
|
|
1145
1207
|
const responseHeadersMap = this.adaptResposeHeaders(responseHeaders);
|
|
1146
1208
|
rustMethod.responseHeaders = this.adaptResponseHeadersTrait(rustClient, rustMethod, Array.from(responseHeadersMap.values()));
|
|
1147
1209
|
if (method.kind === 'paging') {
|
|
@@ -1218,6 +1280,9 @@ export class Adapter {
|
|
|
1218
1280
|
// response header traits are only ever for marker types and payloads
|
|
1219
1281
|
let implFor;
|
|
1220
1282
|
switch (method.returns.type.kind) {
|
|
1283
|
+
case 'pageIterator':
|
|
1284
|
+
implFor = method.returns.type.type.content;
|
|
1285
|
+
break;
|
|
1221
1286
|
case 'pager':
|
|
1222
1287
|
implFor = method.returns.type.type;
|
|
1223
1288
|
break;
|
|
@@ -1228,7 +1293,7 @@ export class Adapter {
|
|
|
1228
1293
|
implFor = method.returns.type.content;
|
|
1229
1294
|
break;
|
|
1230
1295
|
default:
|
|
1231
|
-
// this is
|
|
1296
|
+
// this is RawResponse which should have been previously skipped
|
|
1232
1297
|
throw new AdapterError('InternalError', `unexpected method return kind ${method.returns.type.kind}`);
|
|
1233
1298
|
}
|
|
1234
1299
|
let traitName;
|
|
@@ -1340,7 +1405,6 @@ export class Adapter {
|
|
|
1340
1405
|
*/
|
|
1341
1406
|
adaptMethodParameter(param) {
|
|
1342
1407
|
var _a, _b, _c, _d, _e;
|
|
1343
|
-
const paramLoc = param.onClient ? 'client' : 'method';
|
|
1344
1408
|
/**
|
|
1345
1409
|
* used to create keys for this.clientMethodParams
|
|
1346
1410
|
* @param param the param for which to create a key
|
|
@@ -1351,6 +1415,7 @@ export class Adapter {
|
|
|
1351
1415
|
// in different places across methods (path/query)
|
|
1352
1416
|
return `${param.name}-${param.kind}`;
|
|
1353
1417
|
};
|
|
1418
|
+
const paramLoc = param.onClient ? 'client' : 'method';
|
|
1354
1419
|
// if this is a client method param, check if we've already adapted it
|
|
1355
1420
|
if (paramLoc === 'client') {
|
|
1356
1421
|
const clientMethodParam = this.clientMethodParams.get(getClientParamsKey(param));
|
|
@@ -1358,7 +1423,17 @@ export class Adapter {
|
|
|
1358
1423
|
return clientMethodParam;
|
|
1359
1424
|
}
|
|
1360
1425
|
}
|
|
1361
|
-
|
|
1426
|
+
/** returns the corresponding client param field name for a client parameter */
|
|
1427
|
+
const getCorrespondingClientParamName = function (param) {
|
|
1428
|
+
if (param.onClient && param.correspondingMethodParams.length === 1) {
|
|
1429
|
+
// we get here if the param was aliased via the @paramAlias decorator.
|
|
1430
|
+
// this gives us the name of the client param's backing field which has
|
|
1431
|
+
// the aliased name.
|
|
1432
|
+
return param.correspondingMethodParams[0].name;
|
|
1433
|
+
}
|
|
1434
|
+
return param.name;
|
|
1435
|
+
};
|
|
1436
|
+
const paramName = naming.getEscapedReservedName(snakeCaseName(getCorrespondingClientParamName(param)), 'param');
|
|
1362
1437
|
let paramType = this.getType(param.type);
|
|
1363
1438
|
// for required header/path/query method string params, we might emit them as borrowed types
|
|
1364
1439
|
if (!param.optional && !param.onClient && (param.kind === 'header' || param.kind === 'path' || param.kind === 'query')) {
|
|
@@ -1507,6 +1582,7 @@ export class Adapter {
|
|
|
1507
1582
|
case 'model':
|
|
1508
1583
|
case 'offsetDateTime':
|
|
1509
1584
|
case 'ref':
|
|
1585
|
+
case 'safeint':
|
|
1510
1586
|
case 'scalar':
|
|
1511
1587
|
case 'slice':
|
|
1512
1588
|
case 'str':
|
|
@@ -1594,6 +1670,17 @@ function isRefSlice(type) {
|
|
|
1594
1670
|
function fixETagName(name) {
|
|
1595
1671
|
return name.match(/^etag$/i) ? 'etag' : name;
|
|
1596
1672
|
}
|
|
1673
|
+
/**
|
|
1674
|
+
* removes any illegal characters from the provided name.
|
|
1675
|
+
* note that characters _ and - are preserved so that the
|
|
1676
|
+
* proper snake-casing can be performed.
|
|
1677
|
+
*
|
|
1678
|
+
* @param name the name to transform
|
|
1679
|
+
* @returns the transformed name or the original value
|
|
1680
|
+
*/
|
|
1681
|
+
function removeIllegalChars(name) {
|
|
1682
|
+
return name.replace(/[!@#$%^&*()+=]/g, '');
|
|
1683
|
+
}
|
|
1597
1684
|
/**
|
|
1598
1685
|
* snake-cases the provided name
|
|
1599
1686
|
*
|
|
@@ -1601,7 +1688,7 @@ function fixETagName(name) {
|
|
|
1601
1688
|
* @returns name in snake-case format
|
|
1602
1689
|
*/
|
|
1603
1690
|
function snakeCaseName(name) {
|
|
1604
|
-
return codegen.deconstruct(fixETagName(name)).join('_');
|
|
1691
|
+
return codegen.deconstruct(fixETagName(removeIllegalChars(name))).join('_');
|
|
1605
1692
|
}
|
|
1606
1693
|
/**
|
|
1607
1694
|
* recursively creates a map key from the specified type.
|
|
@@ -1634,8 +1721,11 @@ function recursiveKeyName(root, type) {
|
|
|
1634
1721
|
return `${root}-${type.kind}-${type.name}`;
|
|
1635
1722
|
case 'ref':
|
|
1636
1723
|
return recursiveKeyName(`${root}-${type.kind}`, type.type);
|
|
1724
|
+
case 'safeint':
|
|
1725
|
+
case 'decimal':
|
|
1726
|
+
return `${root}-${type.kind}${type.stringEncoding ? '-string' : ''}`;
|
|
1637
1727
|
case 'scalar':
|
|
1638
|
-
return `${root}-${type.kind}-${type.type}`;
|
|
1728
|
+
return `${root}-${type.kind}-${type.type}${type.stringEncoding ? '-string' : ''}`;
|
|
1639
1729
|
case 'slice':
|
|
1640
1730
|
return recursiveKeyName(`${root}-${type.kind}`, type.type);
|
|
1641
1731
|
default:
|