@azure-tools/typespec-rust 0.28.0 → 0.30.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.d.ts.map +1 -1
- package/dist/src/codegen/clients.js +235 -112
- 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 +3 -1
- package/dist/src/codegen/codeGenerator.js.map +1 -1
- package/dist/src/codegen/context.d.ts +1 -1
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +1 -1
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/enums.js +0 -1
- package/dist/src/codegen/enums.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts +4 -0
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +23 -2
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/mod.d.ts.map +1 -1
- package/dist/src/codegen/mod.js +4 -1
- package/dist/src/codegen/mod.js.map +1 -1
- package/dist/src/codegen/models.js +23 -12
- package/dist/src/codegen/models.js.map +1 -1
- package/dist/src/codegen/unions.d.ts +8 -1
- package/dist/src/codegen/unions.d.ts.map +1 -1
- package/dist/src/codegen/unions.js +42 -13
- package/dist/src/codegen/unions.js.map +1 -1
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +2 -1
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +5 -0
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js +1 -0
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/crate.d.ts +1 -1
- package/dist/src/codemodel/crate.d.ts.map +1 -1
- package/dist/src/codemodel/crate.js +1 -1
- package/dist/src/codemodel/crate.js.map +1 -1
- package/dist/src/codemodel/types.d.ts +24 -28
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +11 -13
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +18 -15
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +2 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +5 -13
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +89 -90
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/src/tcgcadapter/naming.d.ts +2 -1
- package/dist/src/tcgcadapter/naming.d.ts.map +1 -1
- package/dist/src/tcgcadapter/naming.js +3 -2
- package/dist/src/tcgcadapter/naming.js.map +1 -1
- package/package.json +27 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"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"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// cspell: ignore addl responseheader subclients lropaging
|
|
6
6
|
import * as codegen from '@azure-tools/codegen';
|
|
7
7
|
import { values } from '@azure-tools/linq';
|
|
8
|
-
import
|
|
8
|
+
import * as tsp from '@typespec/compiler';
|
|
9
9
|
import * as helpers from './helpers.js';
|
|
10
10
|
import * as naming from './naming.js';
|
|
11
11
|
import * as shared from '../shared/shared.js';
|
|
@@ -21,7 +21,7 @@ export class AdapterError extends Error {
|
|
|
21
21
|
constructor(code, message, target) {
|
|
22
22
|
super(message);
|
|
23
23
|
this.code = code;
|
|
24
|
-
this.target = target !== null && target !== void 0 ? target : NoTarget;
|
|
24
|
+
this.target = target !== null && target !== void 0 ? target : tsp.NoTarget;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
@@ -99,8 +99,12 @@ export class Adapter {
|
|
|
99
99
|
}
|
|
100
100
|
/** converts all tcgc types to their Rust type equivalent */
|
|
101
101
|
adaptTypes() {
|
|
102
|
+
var _a;
|
|
102
103
|
for (const sdkUnion of this.ctx.sdkPackage.unions.filter(u => u.kind === 'union')) {
|
|
103
|
-
|
|
104
|
+
if (!sdkUnion.discriminatedOptions) {
|
|
105
|
+
throw new AdapterError('UnsupportedTsp', 'non-discriminated unions are not supported', (_a = sdkUnion.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
106
|
+
}
|
|
107
|
+
const rustUnion = this.getDiscriminatedUnion(sdkUnion);
|
|
104
108
|
this.crate.unions.push(rustUnion);
|
|
105
109
|
}
|
|
106
110
|
for (const sdkEnum of this.ctx.sdkPackage.enums) {
|
|
@@ -112,6 +116,7 @@ export class Adapter {
|
|
|
112
116
|
const rustEnum = this.getEnum(sdkEnum);
|
|
113
117
|
this.crate.enums.push(rustEnum);
|
|
114
118
|
}
|
|
119
|
+
const processedTypes = new Set();
|
|
115
120
|
for (const model of this.ctx.sdkPackage.models) {
|
|
116
121
|
if ((model.usage & tcgc.UsageFlags.Input) === 0 && (model.usage & tcgc.UsageFlags.Output) === 0 && (model.usage & tcgc.UsageFlags.Spread) === 0) {
|
|
117
122
|
// skip types without input and output usage. this will include core
|
|
@@ -119,6 +124,14 @@ export class Adapter {
|
|
|
119
124
|
// we keep the models for spread params as we internally use them.
|
|
120
125
|
continue;
|
|
121
126
|
}
|
|
127
|
+
// TODO: workaround for https://github.com/Azure/typespec-azure/issues/3614
|
|
128
|
+
if (processedTypes.has(model.name)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
processedTypes.add(model.name);
|
|
133
|
+
}
|
|
134
|
+
// END workaround
|
|
122
135
|
const rustModel = this.getModel(model);
|
|
123
136
|
this.crate.models.push(rustModel);
|
|
124
137
|
}
|
|
@@ -159,7 +172,7 @@ export class Adapter {
|
|
|
159
172
|
default:
|
|
160
173
|
throw new AdapterError('UnsupportedTsp', `unsupported enum underlying type ${sdkEnum.valueType.kind}`, (_a = sdkEnum.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
161
174
|
}
|
|
162
|
-
rustEnum = new rust.Enum(enumName, sdkEnum.access
|
|
175
|
+
rustEnum = new rust.Enum(enumName, adaptAccessFlags(sdkEnum.access), !sdkEnum.isFixed, enumType);
|
|
163
176
|
rustEnum.docs = this.adaptDocs(sdkEnum.summary, sdkEnum.doc);
|
|
164
177
|
this.types.set(enumName, rustEnum);
|
|
165
178
|
const rustEnumNameToSdkEnumName = new Map();
|
|
@@ -208,7 +221,9 @@ export class Adapter {
|
|
|
208
221
|
if (modelName.length === 0) {
|
|
209
222
|
throw new AdapterError('InternalError', 'unnamed model', (_a = model.__raw) === null || _a === void 0 ? void 0 : _a.node); // TODO: this might no longer be an issue
|
|
210
223
|
}
|
|
211
|
-
|
|
224
|
+
// remove any non-word characters from the name.
|
|
225
|
+
// the most common case is something like Foo.Bar.Baz
|
|
226
|
+
modelName = codegen.capitalize(modelName).replace(/\W/g, '');
|
|
212
227
|
let rustModel = this.types.get(modelName);
|
|
213
228
|
if (rustModel) {
|
|
214
229
|
return rustModel;
|
|
@@ -285,70 +300,14 @@ export class Adapter {
|
|
|
285
300
|
stack.pop();
|
|
286
301
|
return rustModel;
|
|
287
302
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Gets properties of a TypeSpec union
|
|
290
|
-
*
|
|
291
|
-
* @param union tcgc union to convert
|
|
292
|
-
* @returns TypeSpec union properties
|
|
293
|
-
*/
|
|
294
|
-
// TODO: Rewrite getting information from __raw?.node after https://github.com/microsoft/typespec/issues/8455 is implemented
|
|
295
|
-
getUnionProperties(union) {
|
|
296
|
-
var _a;
|
|
297
|
-
const result = {
|
|
298
|
-
discriminatorValues: new Map(),
|
|
299
|
-
discriminatorPropertyName: 'kind',
|
|
300
|
-
envelopePropertyName: 'value'
|
|
301
|
-
};
|
|
302
|
-
/*
|
|
303
|
-
eslint-disable
|
|
304
|
-
@typescript-eslint/no-explicit-any,
|
|
305
|
-
@typescript-eslint/no-unnecessary-type-assertion,
|
|
306
|
-
@typescript-eslint/no-unsafe-argument,
|
|
307
|
-
@typescript-eslint/no-unsafe-assignment,
|
|
308
|
-
@typescript-eslint/no-unsafe-member-access
|
|
309
|
-
*/
|
|
310
|
-
const tspRawNode = (_a = union.__raw) === null || _a === void 0 ? void 0 : _a.node;
|
|
311
|
-
if (tspRawNode) {
|
|
312
|
-
for (const unionMember of Array.from(tspRawNode.symbol.members)) {
|
|
313
|
-
const discriminatorValue = unionMember[0];
|
|
314
|
-
const discriminatorTypeName = unionMember[1].node.value.target.sv;
|
|
315
|
-
result.discriminatorValues.set(discriminatorTypeName, discriminatorValue);
|
|
316
|
-
}
|
|
317
|
-
for (const decorator of tspRawNode.decorators) {
|
|
318
|
-
if (decorator.target.sv === 'discriminated') {
|
|
319
|
-
const argument = decorator.arguments[0];
|
|
320
|
-
if (argument) {
|
|
321
|
-
for (const property of argument.properties) {
|
|
322
|
-
const propertyName = property.id.sv;
|
|
323
|
-
const propertyValue = property.value.value;
|
|
324
|
-
if (propertyName === 'envelope') {
|
|
325
|
-
if (propertyValue === 'none') {
|
|
326
|
-
result.envelopePropertyName = '';
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
else if (propertyName === 'discriminatorPropertyName') {
|
|
330
|
-
result.discriminatorPropertyName = propertyValue;
|
|
331
|
-
}
|
|
332
|
-
else if (propertyName === 'envelopePropertyName') {
|
|
333
|
-
result.envelopePropertyName = propertyValue;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
/* eslint-enable */
|
|
341
|
-
return result;
|
|
342
|
-
}
|
|
343
303
|
/**
|
|
344
304
|
* converts a tcgc union to a Rust union
|
|
345
305
|
*
|
|
346
306
|
* @param union the tcgc union to convert
|
|
347
|
-
* @param stack is a stack of model type names used to detect recursive type definitions
|
|
348
307
|
* @returns a Rust union
|
|
349
308
|
*/
|
|
350
|
-
|
|
351
|
-
var _a, _b, _c;
|
|
309
|
+
getDiscriminatedUnion(union) {
|
|
310
|
+
var _a, _b, _c, _d;
|
|
352
311
|
if (union.name.length === 0) {
|
|
353
312
|
throw new AdapterError('InternalError', 'unnamed union', (_a = union.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
354
313
|
}
|
|
@@ -357,31 +316,45 @@ export class Adapter {
|
|
|
357
316
|
if (rustUnion) {
|
|
358
317
|
return rustUnion;
|
|
359
318
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
319
|
+
if (!union.discriminatedOptions) {
|
|
320
|
+
// we should have verified this earlier.
|
|
321
|
+
// having this check means the compiler won't bark
|
|
322
|
+
// at us when accessing union.discriminatedOptions
|
|
323
|
+
throw new AdapterError('InternalError', 'getDiscriminatedUnion called for non-discriminated union', (_b = union.__raw) === null || _b === void 0 ? void 0 : _b.node);
|
|
364
324
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
rustUnion = new rust.Union(unionName, union.access === 'public', tspUnionProperties.discriminatorPropertyName, tspUnionProperties.envelopePropertyName);
|
|
325
|
+
rustUnion = new rust.DiscriminatedUnion(unionName, adaptAccessFlags(union.access), union.discriminatedOptions.discriminatorPropertyName);
|
|
326
|
+
rustUnion.envelopeName = union.discriminatedOptions.envelopePropertyName;
|
|
368
327
|
rustUnion.docs = this.adaptDocs(union.summary, union.doc);
|
|
369
328
|
this.types.set(unionName, rustUnion);
|
|
329
|
+
// TODO: remove when https://github.com/microsoft/typespec/issues/8455 is complete
|
|
330
|
+
const discriminatorValues = new Map();
|
|
331
|
+
const rawUnion = union.__raw;
|
|
332
|
+
if (rawUnion) {
|
|
333
|
+
for (const [variantKey, variant] of rawUnion.variants) {
|
|
334
|
+
const discriminatorValue = typeof variantKey === 'string' ? variantKey : variantKey.toString();
|
|
335
|
+
if (variant.type.kind === 'Model') {
|
|
336
|
+
discriminatorValues.set(variant.type.name, discriminatorValue);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
throw new AdapterError('InternalError', `unexpected kind ${variant.type.kind} for discriminated union member`, rawUnion);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
// END WORKAROUND
|
|
370
344
|
for (const unionMember of union.variantTypes) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
throw new AdapterError('UnsupportedTsp', `non-model union member`, (_b = unionMember.__raw) === null || _b === void 0 ? void 0 : _b.node);
|
|
345
|
+
if (unionMember.kind !== 'model') {
|
|
346
|
+
throw new AdapterError('UnsupportedTsp', `non-model union member kind ${unionMember.kind}`, (_c = unionMember.__raw) === null || _c === void 0 ? void 0 : _c.node);
|
|
374
347
|
}
|
|
375
|
-
|
|
348
|
+
// TODO: use unionMember.discriminatorValue
|
|
349
|
+
const discriminatorValue = discriminatorValues.get(unionMember.name);
|
|
376
350
|
if (!discriminatorValue) {
|
|
377
|
-
throw new AdapterError('InternalError', `
|
|
351
|
+
throw new AdapterError('InternalError', `didn't find discriminant value for type ${unionMember.name}`, (_d = unionMember.__raw) === null || _d === void 0 ? void 0 : _d.node);
|
|
378
352
|
}
|
|
379
|
-
const
|
|
380
|
-
const rustUnionMember = new rust.
|
|
353
|
+
const unionMemberType = this.getModel(unionMember);
|
|
354
|
+
const rustUnionMember = new rust.DiscriminatedUnionMember(unionMemberType, discriminatorValue);
|
|
381
355
|
rustUnionMember.docs = this.adaptDocs(unionMember.summary, unionMember.doc);
|
|
382
356
|
rustUnion.members.push(rustUnionMember);
|
|
383
357
|
}
|
|
384
|
-
stack.pop();
|
|
385
358
|
return rustUnion;
|
|
386
359
|
}
|
|
387
360
|
getSerializedPropertyName(property) {
|
|
@@ -446,14 +419,20 @@ export class Adapter {
|
|
|
446
419
|
* @returns the adapted Rust type
|
|
447
420
|
*/
|
|
448
421
|
getType(type, stack) {
|
|
449
|
-
var _a, _b;
|
|
422
|
+
var _a, _b, _c;
|
|
450
423
|
const getDateTimeEncoding = (encoding) => {
|
|
424
|
+
var _a;
|
|
451
425
|
switch (encoding) {
|
|
426
|
+
case 'rfc3339-fixed-width':
|
|
427
|
+
this.crate.addDependency(new rust.CrateDependency('time'));
|
|
428
|
+
return encoding;
|
|
452
429
|
case 'rfc3339':
|
|
453
430
|
case 'rfc7231':
|
|
454
431
|
return encoding;
|
|
455
432
|
case 'unixTimestamp':
|
|
456
433
|
return 'unix_time';
|
|
434
|
+
default:
|
|
435
|
+
throw new AdapterError('UnsupportedTsp', `unhandled date-time encoding ${encoding}`, (_a = type.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
457
436
|
}
|
|
458
437
|
};
|
|
459
438
|
switch (type.kind) {
|
|
@@ -578,10 +557,13 @@ export class Adapter {
|
|
|
578
557
|
return timeType;
|
|
579
558
|
}
|
|
580
559
|
case 'union': {
|
|
581
|
-
|
|
560
|
+
if (!type.discriminatedOptions) {
|
|
561
|
+
throw new AdapterError('UnsupportedTsp', 'non-discriminated unions are not supported', (_b = type.__raw) === null || _b === void 0 ? void 0 : _b.node);
|
|
562
|
+
}
|
|
563
|
+
return this.getDiscriminatedUnion(type);
|
|
582
564
|
}
|
|
583
565
|
default:
|
|
584
|
-
throw new AdapterError('UnsupportedTsp', `unhandled tcgc type ${type.kind}`, (
|
|
566
|
+
throw new AdapterError('UnsupportedTsp', `unhandled tcgc type ${type.kind}`, (_c = type.__raw) === null || _c === void 0 ? void 0 : _c.node);
|
|
585
567
|
}
|
|
586
568
|
}
|
|
587
569
|
/** returns a Box type */
|
|
@@ -846,6 +828,7 @@ export class Adapter {
|
|
|
846
828
|
clientOptionsField.defaultValue = 'ClientOptions::default()';
|
|
847
829
|
clientOptionsStruct.fields.push(clientOptionsField);
|
|
848
830
|
rustClient.constructable = new rust.ClientConstruction(new rust.ClientOptions(clientOptionsStruct));
|
|
831
|
+
rustClient.constructable.suppressed = this.options['omit-constructors'];
|
|
849
832
|
clientOptionsStruct.docs.summary = `Options used when creating a ${this.asDocLink(rustClient.name, rustClient.name)}`;
|
|
850
833
|
// NOTE: per tcgc convention, if there is no param of kind credential
|
|
851
834
|
// it means that the client doesn't require any kind of authentication.
|
|
@@ -883,7 +866,7 @@ export class Adapter {
|
|
|
883
866
|
code: 'UnsupportedAuthenticationScheme',
|
|
884
867
|
severity: 'warning',
|
|
885
868
|
message: `authentication scheme ${cred.type} is not supported`,
|
|
886
|
-
target: (_b = (_a = param.__raw) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : NoTarget,
|
|
869
|
+
target: (_b = (_a = param.__raw) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : tsp.NoTarget,
|
|
887
870
|
});
|
|
888
871
|
return AuthTypes.WithAuth;
|
|
889
872
|
}
|
|
@@ -1012,7 +995,7 @@ export class Adapter {
|
|
|
1012
995
|
code: 'LroPagingNotSupported',
|
|
1013
996
|
severity: 'warning',
|
|
1014
997
|
message: `skip emitting Paging LRO ${method.name}`,
|
|
1015
|
-
target: (_d = (_c = method.__raw) === null || _c === void 0 ? void 0 : _c.node) !== null && _d !== void 0 ? _d : NoTarget,
|
|
998
|
+
target: (_d = (_c = method.__raw) === null || _c === void 0 ? void 0 : _c.node) !== null && _d !== void 0 ? _d : tsp.NoTarget,
|
|
1016
999
|
});
|
|
1017
1000
|
continue;
|
|
1018
1001
|
}
|
|
@@ -1076,6 +1059,9 @@ export class Adapter {
|
|
|
1076
1059
|
// client-side default value makes the param optional
|
|
1077
1060
|
if (param.optional || param.clientDefaultValue) {
|
|
1078
1061
|
optional = true;
|
|
1062
|
+
if (!param.clientDefaultValue) {
|
|
1063
|
+
paramType = this.getOptionType(this.typeToWireType(paramType));
|
|
1064
|
+
}
|
|
1079
1065
|
const paramField = new rust.StructField(paramName, 'pub', paramType);
|
|
1080
1066
|
paramField.docs = this.adaptDocs(param.summary, param.doc);
|
|
1081
1067
|
constructable.options.type.fields.push(paramField);
|
|
@@ -1148,7 +1134,7 @@ export class Adapter {
|
|
|
1148
1134
|
code: 'PagingMethodRename',
|
|
1149
1135
|
severity: 'warning',
|
|
1150
1136
|
message: `renamed paging method from ${method.name} to ${srcMethodName}`,
|
|
1151
|
-
target: (_b = (_a = method.__raw) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : NoTarget,
|
|
1137
|
+
target: (_b = (_a = method.__raw) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : tsp.NoTarget,
|
|
1152
1138
|
});
|
|
1153
1139
|
}
|
|
1154
1140
|
const languageIndependentName = method.crossLanguageDefinitionId;
|
|
@@ -1180,7 +1166,7 @@ export class Adapter {
|
|
|
1180
1166
|
const methodOptionsField = new rust.StructField('method_options', 'pub', clientMethodOptions);
|
|
1181
1167
|
methodOptionsField.docs.summary = 'Allows customization of the method call.';
|
|
1182
1168
|
methodOptionsStruct.fields.push(methodOptionsField);
|
|
1183
|
-
const pub = method.access
|
|
1169
|
+
const pub = adaptAccessFlags(method.access);
|
|
1184
1170
|
const methodOptions = new rust.MethodOptions(methodOptionsStruct);
|
|
1185
1171
|
const httpMethod = method.operation.verb;
|
|
1186
1172
|
let rustMethod;
|
|
@@ -1523,14 +1509,15 @@ export class Adapter {
|
|
|
1523
1509
|
// adapt the response headers and add them to the trait
|
|
1524
1510
|
for (const header of responseHeaders) {
|
|
1525
1511
|
let responseHeader;
|
|
1512
|
+
const lowerCasedHeader = header.serializedName.toLowerCase();
|
|
1526
1513
|
if (header.type.kind === 'dict') {
|
|
1527
1514
|
if (header.serializedName !== 'x-ms-meta' && header.serializedName !== 'x-ms-or') {
|
|
1528
1515
|
throw new AdapterError('InternalError', `unexpected response header collection ${header.serializedName}`, header.__raw.node);
|
|
1529
1516
|
}
|
|
1530
|
-
responseHeader = new rust.ResponseHeaderHashMap(snakeCaseName(header.name),
|
|
1517
|
+
responseHeader = new rust.ResponseHeaderHashMap(snakeCaseName(header.name), lowerCasedHeader);
|
|
1531
1518
|
}
|
|
1532
1519
|
else {
|
|
1533
|
-
responseHeader = new rust.ResponseHeaderScalar(snakeCaseName(header.name), fixETagName(
|
|
1520
|
+
responseHeader = new rust.ResponseHeaderScalar(snakeCaseName(header.name), fixETagName(lowerCasedHeader), this.typeToWireType(this.getType(header.type)));
|
|
1534
1521
|
}
|
|
1535
1522
|
responseHeader.docs = this.adaptDocs(header.summary, header.doc);
|
|
1536
1523
|
responseHeadersMap.set(header, responseHeader);
|
|
@@ -1759,7 +1746,7 @@ export class Adapter {
|
|
|
1759
1746
|
}
|
|
1760
1747
|
return param.name;
|
|
1761
1748
|
};
|
|
1762
|
-
const paramName = naming.getEscapedReservedName(snakeCaseName(getCorrespondingClientParamName(param)), 'param');
|
|
1749
|
+
const paramName = naming.getEscapedReservedName(snakeCaseName(getCorrespondingClientParamName(param)), 'param', reservedParams);
|
|
1763
1750
|
let paramType = this.getType(param.type);
|
|
1764
1751
|
// for required header/path/query method string params, we might emit them as borrowed types
|
|
1765
1752
|
if (!param.optional && !param.onClient && (param.kind === 'header' || param.kind === 'path' || param.kind === 'query')) {
|
|
@@ -1964,6 +1951,7 @@ export class Adapter {
|
|
|
1964
1951
|
switch (type.kind) {
|
|
1965
1952
|
case 'bytes':
|
|
1966
1953
|
case 'decimal':
|
|
1954
|
+
case 'discriminatedUnion':
|
|
1967
1955
|
case 'encodedBytes':
|
|
1968
1956
|
case 'enum':
|
|
1969
1957
|
case 'enumValue':
|
|
@@ -1979,8 +1967,6 @@ export class Adapter {
|
|
|
1979
1967
|
case 'slice':
|
|
1980
1968
|
case 'str':
|
|
1981
1969
|
case 'String':
|
|
1982
|
-
case 'union':
|
|
1983
|
-
case 'unionMember':
|
|
1984
1970
|
case 'Url':
|
|
1985
1971
|
case 'Vec':
|
|
1986
1972
|
return type;
|
|
@@ -2224,4 +2210,17 @@ function hasClientNameDecorator(decorators) {
|
|
|
2224
2210
|
function isHttpStatusCodeRange(statusCode) {
|
|
2225
2211
|
return statusCode.start !== undefined;
|
|
2226
2212
|
}
|
|
2213
|
+
/**
|
|
2214
|
+
* converts tcgc's access flags (which aren't really flags) to visibility
|
|
2215
|
+
* @param access the access flag to convert
|
|
2216
|
+
* @returns the flag converted to visibility
|
|
2217
|
+
*/
|
|
2218
|
+
function adaptAccessFlags(access) {
|
|
2219
|
+
return access === 'public' ? 'pub' : 'pubCrate';
|
|
2220
|
+
}
|
|
2221
|
+
/** contains reserved param names */
|
|
2222
|
+
const reservedParams = new Set([
|
|
2223
|
+
// reserved per SDK guidelines
|
|
2224
|
+
'options',
|
|
2225
|
+
]);
|
|
2227
2226
|
//# sourceMappingURL=adapter.js.map
|