@azure-tools/typespec-rust 0.15.0 → 0.17.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 +132 -46
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/context.d.ts +2 -2
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +11 -12
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/headerTraits.js +7 -7
- package/dist/src/codegen/headerTraits.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts +29 -9
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +62 -26
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/models.js +11 -16
- package/dist/src/codegen/models.js.map +1 -1
- package/dist/src/codegen/use.d.ts +3 -1
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +7 -10
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +100 -27
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js +37 -7
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/types.d.ts +18 -14
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +3 -2
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +10 -3
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +151 -74
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAyB,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAIpG,OAAO,EA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IAUhB,yCAAyC;IACzC,OAAO,CAAC,cAAc;IAUtB,mCAAmC;IACnC,OAAO,CAAC,aAAa;IAWrB,iCAAiC;IACjC,OAAO,CAAC,WAAW;IAWnB,0BAA0B;IAC1B,OAAO,CAAC,MAAM;IAWd;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAoClB,4EAA4E;IAC5E,OAAO,CAAC,YAAY;IASpB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;IAOjB;;;;;;;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;IAqSnB;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;;;;;OAQG;IACH,OAAO,CAAC,yBAAyB;IAgEjC;;;;;;;OAOG;IACH,OAAO,CAAC,2BAA2B;IA+EnC;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAqK5B;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAqC5B;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IA2BtB;;;;;;;OAOG;IACH,OAAO,CAAC,0BAA0B;IA0BlC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;CAa5B"}
|
|
@@ -957,7 +957,7 @@ export class Adapter {
|
|
|
957
957
|
* @param rustClient the client to which the method belongs
|
|
958
958
|
*/
|
|
959
959
|
adaptMethod(method, rustClient) {
|
|
960
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
960
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
961
961
|
let srcMethodName = method.name;
|
|
962
962
|
if (method.kind === 'paging' && !srcMethodName.match(/^list/i)) {
|
|
963
963
|
const chunks = codegen.deconstruct(srcMethodName);
|
|
@@ -1039,12 +1039,12 @@ export class Adapter {
|
|
|
1039
1039
|
// if the method param's type DOES match the op param's type and the op param has multiple corresponding method params, it's a spread param
|
|
1040
1040
|
// - e.g. op param is an intersection of multiple model types, and each model type is exposed as a discrete param
|
|
1041
1041
|
if (opParam.kind === 'body' && opParam.type.kind === 'model' && (opParam.type.kind !== param.type.kind || opParam.correspondingMethodParams.length > 1)) {
|
|
1042
|
-
adaptedParam = this.adaptMethodSpreadParameter(param, this.
|
|
1042
|
+
adaptedParam = this.adaptMethodSpreadParameter(param, this.adaptPayloadFormat(opParam.defaultContentType), opParam.type);
|
|
1043
1043
|
}
|
|
1044
1044
|
else {
|
|
1045
1045
|
adaptedParam = this.adaptMethodParameter(opParam);
|
|
1046
1046
|
}
|
|
1047
|
-
if (adaptedParam.kind === '
|
|
1047
|
+
if (adaptedParam.kind === 'headerScalar' || adaptedParam.kind === 'queryScalar') {
|
|
1048
1048
|
paramsMap.set(param, adaptedParam);
|
|
1049
1049
|
}
|
|
1050
1050
|
adaptedParam.docs = this.adaptDocs(param.summary, param.doc);
|
|
@@ -1052,7 +1052,7 @@ export class Adapter {
|
|
|
1052
1052
|
// we specially handle an optional content-type header to ensure it's omitted
|
|
1053
1053
|
// from the options bag type. this shows up when the request body is optional.
|
|
1054
1054
|
// we can't generalize this to optional literal headers though.
|
|
1055
|
-
if (adaptedParam.optional && (adaptedParam.kind !== '
|
|
1055
|
+
if (adaptedParam.optional && (adaptedParam.kind !== 'headerScalar' || adaptedParam.header.toLowerCase() !== 'content-type')) {
|
|
1056
1056
|
let fieldType;
|
|
1057
1057
|
if (adaptedParam.kind === 'partialBody') {
|
|
1058
1058
|
// for partial body params, adaptedParam.type is the model type that's
|
|
@@ -1082,9 +1082,8 @@ export class Adapter {
|
|
|
1082
1082
|
rustMethod.params.push(adaptedParam);
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
var _a, _b;
|
|
1085
|
+
const getResponseFormat = () => {
|
|
1086
|
+
var _a;
|
|
1088
1087
|
// fetch the body format from the HTTP responses.
|
|
1089
1088
|
// they should all have the same type so no need to match responses to type.
|
|
1090
1089
|
let defaultContentType;
|
|
@@ -1100,9 +1099,9 @@ export class Adapter {
|
|
|
1100
1099
|
defaultContentType = httpResp.defaultContentType;
|
|
1101
1100
|
}
|
|
1102
1101
|
if (!defaultContentType) {
|
|
1103
|
-
|
|
1102
|
+
return 'NoFormat';
|
|
1104
1103
|
}
|
|
1105
|
-
return this.
|
|
1104
|
+
return this.adaptResponseFormat(defaultContentType);
|
|
1106
1105
|
};
|
|
1107
1106
|
// add any response headers
|
|
1108
1107
|
const responseHeaders = new Array();
|
|
@@ -1121,27 +1120,40 @@ export class Adapter {
|
|
|
1121
1120
|
// response headers if they need it.
|
|
1122
1121
|
continue;
|
|
1123
1122
|
}
|
|
1123
|
+
else if (header.access === 'internal') {
|
|
1124
|
+
// if a header has been marked as internal then skip it.
|
|
1125
|
+
// this happens if the tsp includes the header for documentation
|
|
1126
|
+
// purposes but the desire is to omit it from the generated code.
|
|
1127
|
+
// we skip them instead of making them pub(crate) to avoid the
|
|
1128
|
+
// case where all headers are internal, which would result in a
|
|
1129
|
+
// marker type where all its trait methods aren't public, making
|
|
1130
|
+
// it effectively useless.
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1124
1133
|
responseHeaders.push(header);
|
|
1125
1134
|
}
|
|
1126
1135
|
}
|
|
1136
|
+
const responseFormat = getResponseFormat();
|
|
1127
1137
|
if (method.kind === 'paging') {
|
|
1138
|
+
if (responseFormat === 'NoFormat') {
|
|
1139
|
+
throw new AdapterError('InternalError', `paged method ${method.name} unexpected response format ${responseFormat}`, (_f = method.__raw) === null || _f === void 0 ? void 0 : _f.node);
|
|
1140
|
+
}
|
|
1128
1141
|
// for paged methods, tcgc models method.response.type as an Array<T>.
|
|
1129
1142
|
// however, we want the synthesized paged response envelope type instead.
|
|
1130
1143
|
const synthesizedType = method.operation.responses[0].type;
|
|
1131
1144
|
if (!synthesizedType) {
|
|
1132
|
-
throw new AdapterError('InternalError', `paged method ${method.name} has no synthesized response type`, (
|
|
1145
|
+
throw new AdapterError('InternalError', `paged method ${method.name} has no synthesized response type`, (_g = method.__raw) === null || _g === void 0 ? void 0 : _g.node);
|
|
1133
1146
|
}
|
|
1134
1147
|
else if (synthesizedType.kind !== 'model') {
|
|
1135
|
-
throw new AdapterError('UnsupportedTsp', `paged method ${method.name} synthesized response type has unexpected kind ${synthesizedType.kind}`, (
|
|
1148
|
+
throw new AdapterError('UnsupportedTsp', `paged method ${method.name} synthesized response type has unexpected kind ${synthesizedType.kind}`, (_h = method.__raw) === null || _h === void 0 ? void 0 : _h.node);
|
|
1136
1149
|
}
|
|
1137
|
-
const format = getBodyFormat();
|
|
1138
1150
|
const synthesizedModel = this.getModel(synthesizedType, new Array());
|
|
1139
1151
|
if (!this.crate.models.includes(synthesizedModel)) {
|
|
1140
1152
|
this.crate.models.push(synthesizedModel);
|
|
1141
1153
|
}
|
|
1142
1154
|
// for the pager response type, remove the Option<T> around the Vec<T> for the page items
|
|
1143
1155
|
if (!method.pagingMetadata.pageItemsSegments) {
|
|
1144
|
-
throw new AdapterError('InternalError', `paged method ${method.name} has no pageItemsSegments`, (
|
|
1156
|
+
throw new AdapterError('InternalError', `paged method ${method.name} has no pageItemsSegments`, (_j = method.__raw) === null || _j === void 0 ? void 0 : _j.node);
|
|
1145
1157
|
}
|
|
1146
1158
|
// unwrap all of the segments for the paged response
|
|
1147
1159
|
let unwrappedCount = 0;
|
|
@@ -1149,11 +1161,17 @@ export class Adapter {
|
|
|
1149
1161
|
for (const pageItemsSegment of method.pagingMetadata.pageItemsSegments) {
|
|
1150
1162
|
const segment = pageItemsSegment;
|
|
1151
1163
|
let serde;
|
|
1152
|
-
switch (
|
|
1153
|
-
case '
|
|
1164
|
+
switch (responseFormat) {
|
|
1165
|
+
case 'JsonFormat':
|
|
1166
|
+
if (!segment.serializationOptions.json) {
|
|
1167
|
+
throw new AdapterError('InternalError', `paged method ${method.name} is missing JSON serialization data`, (_k = method.__raw) === null || _k === void 0 ? void 0 : _k.node);
|
|
1168
|
+
}
|
|
1154
1169
|
serde = segment.serializationOptions.json.name;
|
|
1155
1170
|
break;
|
|
1156
|
-
case '
|
|
1171
|
+
case 'XmlFormat':
|
|
1172
|
+
if (!segment.serializationOptions.xml) {
|
|
1173
|
+
throw new AdapterError('InternalError', `paged method ${method.name} is missing XML serialization data`, (_l = method.__raw) === null || _l === void 0 ? void 0 : _l.node);
|
|
1174
|
+
}
|
|
1157
1175
|
serde = segment.serializationOptions.xml.name;
|
|
1158
1176
|
break;
|
|
1159
1177
|
}
|
|
@@ -1175,19 +1193,19 @@ export class Adapter {
|
|
|
1175
1193
|
}
|
|
1176
1194
|
}
|
|
1177
1195
|
if (unwrappedCount !== method.pagingMetadata.pageItemsSegments.length) {
|
|
1178
|
-
throw new AdapterError('InternalError', `failed to unwrap paged items for method ${method.name}`, (
|
|
1196
|
+
throw new AdapterError('InternalError', `failed to unwrap paged items for method ${method.name}`, (_m = method.__raw) === null || _m === void 0 ? void 0 : _m.node);
|
|
1179
1197
|
}
|
|
1180
1198
|
// if the response contains more than the Vec<T> and next_link then use a PageIterator
|
|
1181
1199
|
if (synthesizedModel.fields.length > 2) {
|
|
1182
|
-
rustMethod.returns = new rust.Result(this.crate, new rust.PageIterator(this.crate, new rust.Response(this.crate,
|
|
1200
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.PageIterator(this.crate, new rust.Response(this.crate, synthesizedModel, responseFormat)));
|
|
1183
1201
|
}
|
|
1184
1202
|
else {
|
|
1185
|
-
rustMethod.returns = new rust.Result(this.crate, new rust.Pager(this.crate, new rust.
|
|
1203
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.Pager(this.crate, new rust.Response(this.crate, synthesizedModel, responseFormat)));
|
|
1186
1204
|
}
|
|
1187
1205
|
}
|
|
1188
1206
|
else if (method.response.type && !(method.response.type.kind === 'bytes' && method.response.type.encode === 'bytes')) {
|
|
1189
|
-
const
|
|
1190
|
-
rustMethod.returns = new rust.Result(this.crate,
|
|
1207
|
+
const response = new rust.Response(this.crate, this.typeToWireType(this.getType(method.response.type)), responseFormat);
|
|
1208
|
+
rustMethod.returns = new rust.Result(this.crate, response);
|
|
1191
1209
|
}
|
|
1192
1210
|
else if (responseHeaders.length > 0) {
|
|
1193
1211
|
// for methods that don't return a modeled type but return headers,
|
|
@@ -1195,14 +1213,14 @@ export class Adapter {
|
|
|
1195
1213
|
const markerType = new rust.MarkerType(`${rustClient.name}${codegen.pascalCase(method.name)}Result`);
|
|
1196
1214
|
markerType.docs.summary = `Contains results for ${this.asDocLink(`${rustClient.name}::${methodName}()`, `crate::generated::clients::${rustClient.name}::${methodName}()`)}`;
|
|
1197
1215
|
this.crate.models.push(markerType);
|
|
1198
|
-
rustMethod.returns = new rust.Result(this.crate, new rust.Response(this.crate, markerType));
|
|
1216
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.Response(this.crate, markerType, responseFormat));
|
|
1199
1217
|
}
|
|
1200
1218
|
else if (method.response.type && method.response.type.kind === 'bytes' && method.response.type.encode === 'bytes') {
|
|
1201
1219
|
// bytes encoding indicates a streaming binary response
|
|
1202
1220
|
rustMethod.returns = new rust.Result(this.crate, new rust.RawResponse(this.crate));
|
|
1203
1221
|
}
|
|
1204
1222
|
else {
|
|
1205
|
-
rustMethod.returns = new rust.Result(this.crate, new rust.Response(this.crate, this.getUnitType()));
|
|
1223
|
+
rustMethod.returns = new rust.Result(this.crate, new rust.Response(this.crate, this.getUnitType(), responseFormat));
|
|
1206
1224
|
}
|
|
1207
1225
|
const responseHeadersMap = this.adaptResposeHeaders(responseHeaders);
|
|
1208
1226
|
rustMethod.responseHeaders = this.adaptResponseHeadersTrait(rustClient, rustMethod, Array.from(responseHeadersMap.values()));
|
|
@@ -1261,6 +1279,7 @@ export class Adapter {
|
|
|
1261
1279
|
const recursiveTypeName = function (type) {
|
|
1262
1280
|
switch (type.kind) {
|
|
1263
1281
|
case 'enum':
|
|
1282
|
+
case 'marker':
|
|
1264
1283
|
case 'model':
|
|
1265
1284
|
return type.name;
|
|
1266
1285
|
case 'hashmap':
|
|
@@ -1281,31 +1300,23 @@ export class Adapter {
|
|
|
1281
1300
|
let implFor;
|
|
1282
1301
|
switch (method.returns.type.kind) {
|
|
1283
1302
|
case 'pageIterator':
|
|
1284
|
-
implFor = method.returns.type.type.content;
|
|
1285
|
-
break;
|
|
1286
1303
|
case 'pager':
|
|
1287
1304
|
implFor = method.returns.type.type;
|
|
1288
1305
|
break;
|
|
1289
1306
|
case 'response':
|
|
1290
|
-
if (method.returns.type.content.kind
|
|
1307
|
+
if (method.returns.type.content.kind === 'unit') {
|
|
1308
|
+
// this is to filter out unit from ResponseTypes.
|
|
1309
|
+
// methods that return unit should have been skipped by our caller
|
|
1310
|
+
// so we should never hit this (if we do, we have a bug elsewhere).
|
|
1291
1311
|
throw new AdapterError('InternalError', `unexpected method content kind ${method.returns.type.content.kind}`);
|
|
1292
1312
|
}
|
|
1293
|
-
implFor = method.returns.type
|
|
1313
|
+
implFor = method.returns.type;
|
|
1294
1314
|
break;
|
|
1295
1315
|
default:
|
|
1296
1316
|
// this is RawResponse which should have been previously skipped
|
|
1297
1317
|
throw new AdapterError('InternalError', `unexpected method return kind ${method.returns.type.kind}`);
|
|
1298
1318
|
}
|
|
1299
|
-
|
|
1300
|
-
switch (implFor.kind) {
|
|
1301
|
-
case 'marker':
|
|
1302
|
-
traitName = implFor.name;
|
|
1303
|
-
break;
|
|
1304
|
-
case 'payload':
|
|
1305
|
-
traitName = recursiveTypeName(implFor.type);
|
|
1306
|
-
break;
|
|
1307
|
-
}
|
|
1308
|
-
traitName += 'Headers';
|
|
1319
|
+
const traitName = `${recursiveTypeName(implFor.content)}Headers`;
|
|
1309
1320
|
// NOTE: the complete doc text will be emitted at codegen time
|
|
1310
1321
|
const docs = this.asDocLink(`${client.name}::${method.name}()`, `crate::generated::clients::${client.name}::${method.name}()`);
|
|
1311
1322
|
const responseHeadersTrait = new rust.ResponseHeadersTrait(traitName, implFor, docs);
|
|
@@ -1404,7 +1415,7 @@ export class Adapter {
|
|
|
1404
1415
|
* @returns a Rust method parameter
|
|
1405
1416
|
*/
|
|
1406
1417
|
adaptMethodParameter(param) {
|
|
1407
|
-
var _a, _b, _c, _d, _e;
|
|
1418
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1408
1419
|
/**
|
|
1409
1420
|
* used to create keys for this.clientMethodParams
|
|
1410
1421
|
* @param param the param for which to create a key
|
|
@@ -1451,7 +1462,7 @@ export class Adapter {
|
|
|
1451
1462
|
requestType = new rust.Bytes(this.crate);
|
|
1452
1463
|
}
|
|
1453
1464
|
else {
|
|
1454
|
-
requestType = new rust.Payload(this.typeToWireType(paramType), this.
|
|
1465
|
+
requestType = new rust.Payload(this.typeToWireType(paramType), this.adaptPayloadFormat(param.defaultContentType));
|
|
1455
1466
|
}
|
|
1456
1467
|
adaptedParam = new rust.BodyParameter(paramName, paramLoc, param.optional, new rust.RequestContent(this.crate, requestType));
|
|
1457
1468
|
break;
|
|
@@ -1487,25 +1498,76 @@ export class Adapter {
|
|
|
1487
1498
|
adaptedParam = new rust.HeaderHashMapParameter(paramName, param.serializedName, paramLoc, param.optional, paramType);
|
|
1488
1499
|
}
|
|
1489
1500
|
else {
|
|
1490
|
-
|
|
1501
|
+
paramType = this.typeToWireType(paramType);
|
|
1502
|
+
switch (paramType.kind) {
|
|
1503
|
+
case 'hashmap':
|
|
1504
|
+
case 'jsonValue':
|
|
1505
|
+
case 'model':
|
|
1506
|
+
case 'slice':
|
|
1507
|
+
case 'str':
|
|
1508
|
+
case 'Vec':
|
|
1509
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar header ${param.serializedName}`, (_e = param.__raw) === null || _e === void 0 ? void 0 : _e.node);
|
|
1510
|
+
}
|
|
1511
|
+
adaptedParam = new rust.HeaderScalarParameter(paramName, param.serializedName, paramLoc, param.optional, paramType);
|
|
1491
1512
|
adaptedParam.isApiVersion = param.isApiVersionParam;
|
|
1492
1513
|
}
|
|
1493
1514
|
break;
|
|
1494
1515
|
case 'path':
|
|
1495
|
-
|
|
1516
|
+
{
|
|
1517
|
+
paramType = this.typeToWireType(paramType);
|
|
1518
|
+
let style = 'simple';
|
|
1519
|
+
{
|
|
1520
|
+
const tspStyleString = param.style;
|
|
1521
|
+
if (!['simple', 'path', 'label', 'matrix'].includes(tspStyleString)) {
|
|
1522
|
+
throw new AdapterError('InternalError', `unsupported style ${tspStyleString} for parameter ${param.serializedName}`, (_f = param.__raw) === null || _f === void 0 ? void 0 : _f.node);
|
|
1523
|
+
}
|
|
1524
|
+
else {
|
|
1525
|
+
style = tspStyleString;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
if (isRefSlice(paramType)) {
|
|
1529
|
+
adaptedParam = new rust.PathCollectionParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, param.allowReserved, style, param.explode);
|
|
1530
|
+
}
|
|
1531
|
+
else if (paramType.kind === 'hashmap') {
|
|
1532
|
+
adaptedParam = new rust.PathHashMapParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, param.allowReserved, style, param.explode);
|
|
1533
|
+
}
|
|
1534
|
+
else {
|
|
1535
|
+
switch (paramType.kind) {
|
|
1536
|
+
case 'jsonValue':
|
|
1537
|
+
case 'model':
|
|
1538
|
+
case 'slice':
|
|
1539
|
+
case 'str':
|
|
1540
|
+
case 'Vec':
|
|
1541
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar path ${param.serializedName}`, (_g = param.__raw) === null || _g === void 0 ? void 0 : _g.node);
|
|
1542
|
+
}
|
|
1543
|
+
adaptedParam = new rust.PathScalarParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, param.allowReserved, style);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1496
1546
|
break;
|
|
1497
1547
|
case 'query':
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1548
|
+
paramType = this.typeToWireType(paramType);
|
|
1549
|
+
if (paramType.kind === 'Vec' || isRefSlice(paramType)) {
|
|
1550
|
+
let format = param.explode ? 'multi' : 'csv';
|
|
1551
|
+
if (param.collectionFormat) {
|
|
1552
|
+
format = param.collectionFormat === 'simple' ? 'csv' : (param.collectionFormat === 'form' ? 'multi' : param.collectionFormat);
|
|
1502
1553
|
}
|
|
1503
1554
|
// TODO: hard-coded encoding setting, https://github.com/Azure/typespec-azure/issues/1314
|
|
1504
1555
|
adaptedParam = new rust.QueryCollectionParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, true, format);
|
|
1505
1556
|
}
|
|
1557
|
+
else if (paramType.kind === 'hashmap') {
|
|
1558
|
+
// TODO: hard-coded encoding setting, https://github.com/Azure/typespec-azure/issues/1314
|
|
1559
|
+
adaptedParam = new rust.QueryHashMapParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, true, param.explode);
|
|
1560
|
+
}
|
|
1506
1561
|
else {
|
|
1562
|
+
switch (paramType.kind) {
|
|
1563
|
+
case 'jsonValue':
|
|
1564
|
+
case 'model':
|
|
1565
|
+
case 'slice':
|
|
1566
|
+
case 'str':
|
|
1567
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar query ${param.serializedName}`, (_h = param.__raw) === null || _h === void 0 ? void 0 : _h.node);
|
|
1568
|
+
}
|
|
1507
1569
|
// TODO: hard-coded encoding setting, https://github.com/Azure/typespec-azure/issues/1314
|
|
1508
|
-
adaptedParam = new rust.
|
|
1570
|
+
adaptedParam = new rust.QueryScalarParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, true);
|
|
1509
1571
|
adaptedParam.isApiVersion = param.isApiVersionParam;
|
|
1510
1572
|
}
|
|
1511
1573
|
break;
|
|
@@ -1604,42 +1666,36 @@ export class Adapter {
|
|
|
1604
1666
|
*/
|
|
1605
1667
|
adaptMethodSpreadParameter(param, format, opParamType) {
|
|
1606
1668
|
var _a, _b;
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
if (property.name === param.name) {
|
|
1614
|
-
serializedName = property.serializedName;
|
|
1615
|
-
break;
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
if (serializedName === undefined) {
|
|
1619
|
-
throw new AdapterError('InternalError', `didn't find body model property for spread parameter ${param.name}`, (_a = param.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
1620
|
-
}
|
|
1621
|
-
// this is the internal model type that the spread params coalesce into
|
|
1622
|
-
const payloadType = this.getType(opParamType);
|
|
1623
|
-
if (payloadType.kind !== 'model') {
|
|
1624
|
-
throw new AdapterError('InternalError', `unexpected kind ${payloadType.kind} for spread body param`, (_b = opParamType.__raw) === null || _b === void 0 ? void 0 : _b.node);
|
|
1625
|
-
}
|
|
1626
|
-
const paramName = naming.getEscapedReservedName(snakeCaseName(param.name), 'param');
|
|
1627
|
-
const paramLoc = 'method';
|
|
1628
|
-
const adaptedParam = new rust.PartialBodyParameter(paramName, paramLoc, param.optional, serializedName, this.getType(param.type), new rust.RequestContent(this.crate, new rust.Payload(payloadType, format)));
|
|
1629
|
-
return adaptedParam;
|
|
1669
|
+
// find the corresponding field within the model so we can get its index
|
|
1670
|
+
let serializedName;
|
|
1671
|
+
for (const property of opParamType.properties) {
|
|
1672
|
+
if (property.name === param.name) {
|
|
1673
|
+
serializedName = property.serializedName;
|
|
1674
|
+
break;
|
|
1630
1675
|
}
|
|
1631
1676
|
}
|
|
1677
|
+
if (serializedName === undefined) {
|
|
1678
|
+
throw new AdapterError('InternalError', `didn't find body model property for spread parameter ${param.name}`, (_a = param.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
1679
|
+
}
|
|
1680
|
+
// this is the internal model type that the spread params coalesce into
|
|
1681
|
+
const payloadType = this.getType(opParamType);
|
|
1682
|
+
if (payloadType.kind !== 'model') {
|
|
1683
|
+
throw new AdapterError('InternalError', `unexpected kind ${payloadType.kind} for spread body param`, (_b = opParamType.__raw) === null || _b === void 0 ? void 0 : _b.node);
|
|
1684
|
+
}
|
|
1685
|
+
const paramName = naming.getEscapedReservedName(snakeCaseName(param.name), 'param');
|
|
1686
|
+
const paramLoc = 'method';
|
|
1687
|
+
const adaptedParam = new rust.PartialBodyParameter(paramName, paramLoc, param.optional, serializedName, this.getType(param.type), new rust.RequestContent(this.crate, new rust.Payload(payloadType, format)));
|
|
1688
|
+
return adaptedParam;
|
|
1632
1689
|
}
|
|
1633
1690
|
/**
|
|
1634
|
-
* converts a Content-Type header value into a
|
|
1691
|
+
* converts a Content-Type header value into a payload format
|
|
1635
1692
|
*
|
|
1636
1693
|
* @param contentType the value of the Content-Type header
|
|
1637
|
-
* @returns a
|
|
1694
|
+
* @returns a payload format
|
|
1638
1695
|
*/
|
|
1639
|
-
|
|
1640
|
-
// we only recognize/support JSON
|
|
1696
|
+
adaptPayloadFormat(contentType) {
|
|
1697
|
+
// we only recognize/support JSON and XML content types.
|
|
1641
1698
|
if (contentType.match(/json/i)) {
|
|
1642
|
-
this.crate.addDependency(new rust.CrateDependency('serde_json'));
|
|
1643
1699
|
return 'json';
|
|
1644
1700
|
}
|
|
1645
1701
|
else if (contentType.match(/xml/i)) {
|
|
@@ -1651,6 +1707,27 @@ export class Adapter {
|
|
|
1651
1707
|
throw new AdapterError('InternalError', `unexpected contentType ${contentType}`);
|
|
1652
1708
|
}
|
|
1653
1709
|
}
|
|
1710
|
+
/**
|
|
1711
|
+
* converts an accept header value into a response format
|
|
1712
|
+
*
|
|
1713
|
+
* @param accept the value of the Content-Type header
|
|
1714
|
+
* @returns a response format
|
|
1715
|
+
*/
|
|
1716
|
+
adaptResponseFormat(accept) {
|
|
1717
|
+
// we only recognize/support JSON and XML content types.
|
|
1718
|
+
// anything else is NoFormat
|
|
1719
|
+
if (accept.match(/json/i)) {
|
|
1720
|
+
return 'JsonFormat';
|
|
1721
|
+
}
|
|
1722
|
+
else if (accept.match(/xml/i)) {
|
|
1723
|
+
// XML support is disabled by default
|
|
1724
|
+
this.crate.addDependency(new rust.CrateDependency('azure_core', ['xml']));
|
|
1725
|
+
return 'XmlFormat';
|
|
1726
|
+
}
|
|
1727
|
+
else {
|
|
1728
|
+
return 'NoFormat';
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1654
1731
|
}
|
|
1655
1732
|
/** typeguard to determine if type is a Ref<Slice> */
|
|
1656
1733
|
function isRefSlice(type) {
|