@azure-tools/typespec-rust 0.19.0 → 0.21.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.
Files changed (48) hide show
  1. package/dist/src/codegen/cargotoml.d.ts.map +1 -1
  2. package/dist/src/codegen/cargotoml.js +3 -1
  3. package/dist/src/codegen/cargotoml.js.map +1 -1
  4. package/dist/src/codegen/clients.d.ts.map +1 -1
  5. package/dist/src/codegen/clients.js +251 -33
  6. package/dist/src/codegen/clients.js.map +1 -1
  7. package/dist/src/codegen/context.d.ts +10 -0
  8. package/dist/src/codegen/context.d.ts.map +1 -1
  9. package/dist/src/codegen/context.js +51 -3
  10. package/dist/src/codegen/context.js.map +1 -1
  11. package/dist/src/codegen/docTests.d.ts +12 -0
  12. package/dist/src/codegen/docTests.d.ts.map +1 -0
  13. package/dist/src/codegen/docTests.js +46 -0
  14. package/dist/src/codegen/docTests.js.map +1 -0
  15. package/dist/src/codegen/headerTraits.d.ts.map +1 -1
  16. package/dist/src/codegen/headerTraits.js +5 -0
  17. package/dist/src/codegen/headerTraits.js.map +1 -1
  18. package/dist/src/codegen/helpers.d.ts +39 -4
  19. package/dist/src/codegen/helpers.d.ts.map +1 -1
  20. package/dist/src/codegen/helpers.js +70 -7
  21. package/dist/src/codegen/helpers.js.map +1 -1
  22. package/dist/src/codegen/lib.d.ts.map +1 -1
  23. package/dist/src/codegen/lib.js +2 -0
  24. package/dist/src/codegen/lib.js.map +1 -1
  25. package/dist/src/codegen/models.d.ts.map +1 -1
  26. package/dist/src/codegen/models.js +172 -9
  27. package/dist/src/codegen/models.js.map +1 -1
  28. package/dist/src/codegen/use.d.ts.map +1 -1
  29. package/dist/src/codegen/use.js +4 -0
  30. package/dist/src/codegen/use.js.map +1 -1
  31. package/dist/src/codemodel/client.d.ts +14 -1
  32. package/dist/src/codemodel/client.d.ts.map +1 -1
  33. package/dist/src/codemodel/client.js +8 -0
  34. package/dist/src/codemodel/client.js.map +1 -1
  35. package/dist/src/codemodel/crate.js.map +1 -1
  36. package/dist/src/codemodel/types.d.ts +40 -16
  37. package/dist/src/codemodel/types.d.ts.map +1 -1
  38. package/dist/src/codemodel/types.js +15 -1
  39. package/dist/src/codemodel/types.js.map +1 -1
  40. package/dist/src/shared/shared.d.ts +6 -0
  41. package/dist/src/shared/shared.d.ts.map +1 -1
  42. package/dist/src/shared/shared.js +15 -0
  43. package/dist/src/shared/shared.js.map +1 -1
  44. package/dist/src/tcgcadapter/adapter.d.ts +8 -3
  45. package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
  46. package/dist/src/tcgcadapter/adapter.js +131 -42
  47. package/dist/src/tcgcadapter/adapter.js.map +1 -1
  48. package/package.json +28 -28
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAAyB,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAIpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG/C,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C,oDAAoD;AACpD,MAAM,MAAM,SAAS;AACnB,qFAAqF;AACrF,eAAe;AAEf,mDAAmD;AACnD,iBAAiB;AAEjB;;;GAGG;AACH,eAAe;AAEf,sEAAsE;AACtE,gBAAgB,CAAC;AAEnB;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,QAAQ,CAAC;gBAExC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB;CAKxE;AAED,2DAA2D;AAC3D,qBAAa,OAAO;IAClB;;;;;OAKG;WACU,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,kBAAkB,CAAC,GAAG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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;IAgP5B;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAmBjC;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IA4C5B;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAwB3B;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IA+UnB;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAoB5B;;;;;;;;OAQG;IACH,OAAO,CAAC,yBAAyB;IAiEjC;;;;;;;OAOG;IACH,OAAO,CAAC,2BAA2B;IA+EnC;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAoK5B;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IA4C5B;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IA2BtB;;;;;;;OAOG;IACH,OAAO,CAAC,0BAA0B;IA2BlC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;CAa/B"}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- // cspell: ignore responseheader subclients lropaging
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
8
  import { NoTarget } from '@typespec/compiler';
@@ -173,7 +173,7 @@ export class Adapter {
173
173
  * @returns a Rust model
174
174
  */
175
175
  getModel(model, stack) {
176
- var _a, _b;
176
+ var _a, _b, _c, _d;
177
177
  if (model.name.length === 0) {
178
178
  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
179
179
  }
@@ -204,6 +204,7 @@ export class Adapter {
204
204
  for (const prop of model.properties) {
205
205
  allProps.push(prop);
206
206
  }
207
+ let addlProps = model.additionalProperties;
207
208
  let parent = model.baseModel;
208
209
  while (parent) {
209
210
  for (const parentProp of parent.properties) {
@@ -215,7 +216,14 @@ export class Adapter {
215
216
  }
216
217
  allProps.push(parentProp);
217
218
  }
218
- // TODO: propagate additional properties https://github.com/Azure/typespec-rust/issues/4
219
+ // propagate parent's additional properties if we don't yet have any.
220
+ // if we do, ensure that their kinds match.
221
+ if (!addlProps) {
222
+ addlProps = parent.additionalProperties;
223
+ }
224
+ else if (parent.additionalProperties && addlProps.kind !== parent.additionalProperties.kind) {
225
+ throw new AdapterError('UnsupportedTsp', `model ${model.name} has additional properties kind ${addlProps.kind} which conflicts with parent model ${parent.name} additional properties kind ${parent.additionalProperties.kind}`, (_b = model.__raw) === null || _b === void 0 ? void 0 : _b.node);
226
+ }
219
227
  parent = parent.baseModel;
220
228
  }
221
229
  for (const property of allProps) {
@@ -231,15 +239,25 @@ export class Adapter {
231
239
  // we just adapt it here as a regular model field.
232
240
  }
233
241
  else {
234
- throw new AdapterError('UnsupportedTsp', `model property kind ${property.kind} NYI`, (_b = property.__raw) === null || _b === void 0 ? void 0 : _b.node);
242
+ throw new AdapterError('UnsupportedTsp', `model property kind ${(_c = property.__raw) === null || _c === void 0 ? void 0 : _c.kind} NYI`, (_d = property.__raw) === null || _d === void 0 ? void 0 : _d.node);
235
243
  }
236
244
  }
237
245
  const structField = this.getModelField(property, rustModel.visibility, stack);
238
246
  rustModel.fields.push(structField);
239
247
  }
248
+ if (addlProps) {
249
+ const addlPropsType = this.getHashMap(this.typeToWireType(this.getType(addlProps)));
250
+ const addlPropsField = new rust.ModelAdditionalProperties('additional_properties', 'pub', this.getOptionType(addlPropsType));
251
+ addlPropsField.docs.summary = 'contains unnamed additional properties';
252
+ rustModel.fields.push(addlPropsField);
253
+ }
240
254
  stack.pop();
241
255
  return rustModel;
242
256
  }
257
+ getSerializedPropertyName(property) {
258
+ var _a, _b, _c, _d, _e;
259
+ return property.kind === 'property' ? (_d = (_b = (_a = property.serializationOptions.json) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = property.serializationOptions.xml) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : (_e = property.serializationOptions.multipart) === null || _e === void 0 ? void 0 : _e.name : undefined;
260
+ }
243
261
  /**
244
262
  * converts a tcgc model property to a model field
245
263
  *
@@ -249,17 +267,19 @@ export class Adapter {
249
267
  * @returns a Rust model field
250
268
  */
251
269
  getModelField(property, modelVisibility, stack) {
270
+ var _a;
252
271
  let fieldType = this.getType(property.type, stack);
253
272
  // if the field's type is a model and it's in the type stack then
254
273
  // box it. this is to avoid infinitely recursive type definitions.
255
274
  if (fieldType.kind === 'model' && stack.includes(fieldType.name)) {
256
- fieldType = new rust.Box(fieldType);
275
+ fieldType = this.getBoxType(fieldType);
257
276
  }
258
277
  // for public models each field is always an Option<T>.
259
278
  if (modelVisibility === 'pub' || property.optional) {
260
- fieldType = new rust.Option(fieldType.kind === 'box' ? fieldType : this.typeToWireType(fieldType));
279
+ fieldType = this.getOptionType(fieldType.kind === 'box' ? fieldType : this.typeToWireType(fieldType));
261
280
  }
262
- const modelField = new rust.ModelField(naming.getEscapedReservedName(snakeCaseName(property.name), 'prop'), property.serializedName, modelVisibility, fieldType, property.optional);
281
+ const serializedName = (_a = this.getSerializedPropertyName(property)) !== null && _a !== void 0 ? _a : property.name;
282
+ const modelField = new rust.ModelField(naming.getEscapedReservedName(snakeCaseName(property.name), 'prop'), serializedName, modelVisibility, fieldType, property.optional);
263
283
  modelField.docs = this.adaptDocs(property.summary, property.doc);
264
284
  // if this is a literal, add a doc comment explaining its behavior
265
285
  const unwrappedType = shared.unwrapOption(fieldType);
@@ -423,6 +443,16 @@ export class Adapter {
423
443
  throw new AdapterError('UnsupportedTsp', `unhandled tcgc type ${type.kind}`, (_b = type.__raw) === null || _b === void 0 ? void 0 : _b.node);
424
444
  }
425
445
  }
446
+ /** returns a Box type */
447
+ getBoxType(type) {
448
+ const typeKey = recursiveKeyName('box', type);
449
+ let boxType = this.types.get(typeKey);
450
+ if (!boxType) {
451
+ boxType = new rust.Box(type);
452
+ this.types.set(typeKey, boxType);
453
+ }
454
+ return boxType;
455
+ }
426
456
  /** returns an EncodedBytes type with the specified encoding */
427
457
  getEncodedBytes(encoding, asSlice) {
428
458
  const keyName = `encodedBytes-${encoding}${asSlice ? '-slice' : ''}`;
@@ -445,6 +475,16 @@ export class Adapter {
445
475
  this.types.set(keyName, hashmapType);
446
476
  return hashmapType;
447
477
  }
478
+ /** returns an Option<T> where T is specified in type */
479
+ getOptionType(type) {
480
+ const typeKey = recursiveKeyName('option', type);
481
+ let optionType = this.types.get(typeKey);
482
+ if (!optionType) {
483
+ optionType = new rust.Option(type);
484
+ this.types.set(typeKey, optionType);
485
+ }
486
+ return optionType;
487
+ }
448
488
  /** returns the specified type wrapped in a Ref */
449
489
  getRefType(type) {
450
490
  const typeKey = recursiveKeyName('ref', type);
@@ -833,19 +873,21 @@ export class Adapter {
833
873
  this.adaptClientAccessor(client, child, rustClient, subClient);
834
874
  }
835
875
  for (const method of client.methods) {
836
- if (method.kind === 'lro' || method.kind === 'lropaging') {
837
- // skip LROs for now so that codegen is unblocked
876
+ if (method.kind === 'lropaging') {
877
+ // skip Paging LROs for now so that codegen is unblocked
838
878
  // TODO: https://github.com/Azure/typespec-rust/issues/188
839
879
  this.ctx.program.reportDiagnostic({
840
- code: 'LroNotSupported',
880
+ code: 'LroPagingNotSupported',
841
881
  severity: 'warning',
842
- message: `skip emitting LRO ${method.name}`,
882
+ message: `skip emitting Paging LRO ${method.name}`,
843
883
  target: (_e = (_d = method.__raw) === null || _d === void 0 ? void 0 : _d.node) !== null && _e !== void 0 ? _e : NoTarget,
844
884
  });
845
885
  continue;
846
886
  }
847
887
  this.adaptMethod(method, rustClient);
848
888
  }
889
+ // Set the tracing namespace for tracing based on the client's namespace
890
+ rustClient.languageIndependentName = client.crossLanguageDefinitionId;
849
891
  this.crate.clients.push(rustClient);
850
892
  return rustClient;
851
893
  }
@@ -959,7 +1001,7 @@ export class Adapter {
959
1001
  * @param rustClient the client to which the method belongs
960
1002
  */
961
1003
  adaptMethod(method, rustClient) {
962
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1004
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
963
1005
  let srcMethodName = method.name;
964
1006
  if (method.kind === 'paging' && !srcMethodName.match(/^list/i)) {
965
1007
  const chunks = codegen.deconstruct(srcMethodName);
@@ -987,6 +1029,12 @@ export class Adapter {
987
1029
  const methodOptionsField = new rust.StructField('method_options', 'pub', clientMethodOptions);
988
1030
  methodOptionsField.docs.summary = 'Allows customization of the method call.';
989
1031
  methodOptionsStruct.fields.push(methodOptionsField);
1032
+ if (method.kind === 'lro') {
1033
+ const pollerOptions = new rust.ExternalType(this.crate, 'PollerOptions', 'azure_core::http::poller');
1034
+ const pollerOptionsField = new rust.StructField('poller_options', 'pub', pollerOptions);
1035
+ pollerOptionsField.docs.summary = 'Allows customization of the [`Poller`](azure_core::http::poller::Poller).';
1036
+ methodOptionsStruct.fields.push(pollerOptionsField);
1037
+ }
990
1038
  const pub = method.access === 'public' ? 'pub' : 'pubCrate';
991
1039
  const methodOptions = new rust.MethodOptions(methodOptionsStruct);
992
1040
  const httpMethod = method.operation.verb;
@@ -1009,6 +1057,9 @@ export class Adapter {
1009
1057
  case 'paging':
1010
1058
  rustMethod = new rust.PageableMethod(methodName, languageIndependentName, rustClient, pub, methodOptions, httpMethod, httpPath);
1011
1059
  break;
1060
+ case 'lro':
1061
+ rustMethod = new rust.LroMethod(methodName, languageIndependentName, rustClient, pub, methodOptions, httpMethod, httpPath);
1062
+ break;
1012
1063
  default:
1013
1064
  throw new AdapterError('UnsupportedTsp', `method kind ${method.kind} NYI`, (_d = method.__raw) === null || _d === void 0 ? void 0 : _d.node);
1014
1065
  }
@@ -1047,8 +1098,11 @@ export class Adapter {
1047
1098
  else {
1048
1099
  adaptedParam = this.adaptMethodParameter(opParam);
1049
1100
  }
1050
- if (adaptedParam.kind === 'headerScalar' || adaptedParam.kind === 'queryScalar') {
1051
- paramsMap.set(param, adaptedParam);
1101
+ switch (adaptedParam.kind) {
1102
+ case 'headerScalar':
1103
+ case 'queryScalar':
1104
+ paramsMap.set(param, adaptedParam);
1105
+ break;
1052
1106
  }
1053
1107
  adaptedParam.docs = this.adaptDocs(param.summary, param.doc);
1054
1108
  rustMethod.params.push(adaptedParam);
@@ -1069,7 +1123,7 @@ export class Adapter {
1069
1123
  fieldType = field.type;
1070
1124
  }
1071
1125
  else {
1072
- fieldType = new rust.Option(adaptedParam.type);
1126
+ fieldType = this.getOptionType(adaptedParam.type);
1073
1127
  }
1074
1128
  const optionsField = new rust.StructField(adaptedParam.name, 'pub', fieldType);
1075
1129
  optionsField.docs = adaptedParam.docs;
@@ -1104,7 +1158,7 @@ export class Adapter {
1104
1158
  if (!defaultContentType) {
1105
1159
  return 'NoFormat';
1106
1160
  }
1107
- return this.adaptResponseFormat(defaultContentType);
1161
+ return this.adaptPayloadFormatType(defaultContentType);
1108
1162
  };
1109
1163
  // add any response headers
1110
1164
  const responseHeaders = new Array();
@@ -1166,13 +1220,13 @@ export class Adapter {
1166
1220
  let serde;
1167
1221
  switch (responseFormat) {
1168
1222
  case 'JsonFormat':
1169
- if (!segment.serializationOptions.json) {
1223
+ if (segment.kind !== 'property' || !segment.serializationOptions.json) {
1170
1224
  throw new AdapterError('InternalError', `paged method ${method.name} is missing JSON serialization data`, (_k = method.__raw) === null || _k === void 0 ? void 0 : _k.node);
1171
1225
  }
1172
1226
  serde = segment.serializationOptions.json.name;
1173
1227
  break;
1174
1228
  case 'XmlFormat':
1175
- if (!segment.serializationOptions.xml) {
1229
+ if (segment.kind !== 'property' || !segment.serializationOptions.xml) {
1176
1230
  throw new AdapterError('InternalError', `paged method ${method.name} is missing XML serialization data`, (_l = method.__raw) === null || _l === void 0 ? void 0 : _l.node);
1177
1231
  }
1178
1232
  serde = segment.serializationOptions.xml.name;
@@ -1180,11 +1234,14 @@ export class Adapter {
1180
1234
  }
1181
1235
  for (let i = 0; i < typeToUnwrap.fields.length; ++i) {
1182
1236
  const field = typeToUnwrap.fields[i];
1237
+ if (field.kind === 'additionalProperties') {
1238
+ continue;
1239
+ }
1183
1240
  if (field.serde === serde) {
1184
1241
  // check if this has already been unwrapped (e.g. type is shared across operations)
1185
1242
  if (field.type.kind === 'option') {
1186
- typeToUnwrap.fields[i].type = typeToUnwrap.fields[i].type.type;
1187
- typeToUnwrap.fields[i].flags |= rust.ModelFieldFlags.PageItems;
1243
+ field.type = (field.type).type;
1244
+ field.flags |= rust.ModelFieldFlags.PageItems;
1188
1245
  }
1189
1246
  // move to the next segment
1190
1247
  if (field.type.kind === 'model') {
@@ -1206,6 +1263,29 @@ export class Adapter {
1206
1263
  rustMethod.returns = new rust.Result(this.crate, new rust.Pager(this.crate, new rust.Response(this.crate, synthesizedModel, responseFormat)));
1207
1264
  }
1208
1265
  }
1266
+ else if (method.kind === 'lro') {
1267
+ const format = responseFormat === 'NoFormat' ? 'JsonFormat' : responseFormat;
1268
+ const responseType = this.typeToWireType(this.getModel(method.lroMetadata.logicalResult));
1269
+ if (responseType.kind !== 'model') {
1270
+ throw new AdapterError('InternalError', `envelope result for ${method.name} is not a model`, (_o = method.__raw) === null || _o === void 0 ? void 0 : _o.node);
1271
+ }
1272
+ const pushModels = (model, crate) => {
1273
+ if (crate.models.some(m => m === model)) {
1274
+ return;
1275
+ }
1276
+ crate.models.push(model);
1277
+ for (const field of model.fields) {
1278
+ let fieldType = field.type;
1279
+ fieldType = fieldType.kind === 'option' ? fieldType.type : fieldType;
1280
+ fieldType = fieldType.kind === 'Vec' ? fieldType.type : fieldType;
1281
+ if (fieldType.kind === 'model') {
1282
+ pushModels(fieldType, crate);
1283
+ }
1284
+ }
1285
+ };
1286
+ pushModels(responseType, this.crate);
1287
+ rustMethod.returns = new rust.Result(this.crate, new rust.Poller(this.crate, new rust.Response(this.crate, responseType, format)));
1288
+ }
1209
1289
  else if (method.response.type && !(method.response.type.kind === 'bytes' && method.response.type.encode === 'bytes')) {
1210
1290
  const response = new rust.Response(this.crate, this.typeToWireType(this.getType(method.response.type)), responseFormat);
1211
1291
  rustMethod.returns = new rust.Result(this.crate, response);
@@ -1304,6 +1384,7 @@ export class Adapter {
1304
1384
  switch (method.returns.type.kind) {
1305
1385
  case 'pageIterator':
1306
1386
  case 'pager':
1387
+ case 'poller':
1307
1388
  implFor = method.returns.type.type;
1308
1389
  break;
1309
1390
  case 'response':
@@ -1335,7 +1416,7 @@ export class Adapter {
1335
1416
  * @returns the pageable strategy
1336
1417
  */
1337
1418
  adaptPageableMethodStrategy(method, paramsMap, respHeadersMap) {
1338
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1419
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1339
1420
  if (method.pagingMetadata.nextLinkOperation) {
1340
1421
  // TODO: https://github.com/Azure/autorest.rust/issues/103
1341
1422
  throw new AdapterError('UnsupportedTsp', 'next page operation NYI', (_a = method.__raw) === null || _a === void 0 ? void 0 : _a.node);
@@ -1403,12 +1484,12 @@ export class Adapter {
1403
1484
  break;
1404
1485
  }
1405
1486
  default:
1406
- throw new AdapterError('InternalError', `unhandled continuationTokenResponseSegment kind ${tokenResp.kind}`);
1487
+ throw new AdapterError('InternalError', `missing continuation token`, (_l = method.__raw) === null || _l === void 0 ? void 0 : _l.node);
1407
1488
  }
1408
1489
  return new rust.PageableStrategyContinuationToken(requestToken, responseToken);
1409
1490
  }
1410
1491
  else {
1411
- throw new AdapterError('InternalError', `unknown paging strategy for operation ${method.name}`, (_l = method.__raw) === null || _l === void 0 ? void 0 : _l.node);
1492
+ throw new AdapterError('InternalError', `unknown paging strategy for operation ${method.name}`, (_m = method.__raw) === null || _m === void 0 ? void 0 : _m.node);
1412
1493
  }
1413
1494
  }
1414
1495
  /**
@@ -1467,7 +1548,8 @@ export class Adapter {
1467
1548
  else {
1468
1549
  requestType = new rust.Payload(this.typeToWireType(paramType), this.adaptPayloadFormat(param.defaultContentType));
1469
1550
  }
1470
- adaptedParam = new rust.BodyParameter(paramName, paramLoc, param.optional, new rust.RequestContent(this.crate, requestType));
1551
+ const requestFormatType = this.adaptPayloadFormatType(param.defaultContentType);
1552
+ adaptedParam = new rust.BodyParameter(paramName, paramLoc, param.optional, new rust.RequestContent(this.crate, requestType, requestFormatType));
1471
1553
  break;
1472
1554
  }
1473
1555
  case 'cookie':
@@ -1519,14 +1601,12 @@ export class Adapter {
1519
1601
  {
1520
1602
  paramType = this.typeToWireType(paramType);
1521
1603
  let style = 'simple';
1522
- {
1523
- const tspStyleString = param.style;
1524
- if (!['simple', 'path', 'label', 'matrix'].includes(tspStyleString)) {
1525
- throw new AdapterError('InternalError', `unsupported style ${tspStyleString} for parameter ${param.serializedName}`, (_f = param.__raw) === null || _f === void 0 ? void 0 : _f.node);
1526
- }
1527
- else {
1528
- style = tspStyleString;
1529
- }
1604
+ const tspStyleString = param.style;
1605
+ if (!['simple', 'path', 'label', 'matrix'].includes(tspStyleString)) {
1606
+ throw new AdapterError('InternalError', `unsupported style ${tspStyleString} for parameter ${param.serializedName}`, (_f = param.__raw) === null || _f === void 0 ? void 0 : _f.node);
1607
+ }
1608
+ else {
1609
+ style = tspStyleString;
1530
1610
  }
1531
1611
  if (isRefSlice(paramType)) {
1532
1612
  adaptedParam = new rust.PathCollectionParameter(paramName, param.serializedName, paramLoc, param.optional, paramType, param.allowReserved, style, param.explode);
@@ -1678,8 +1758,8 @@ export class Adapter {
1678
1758
  // find the corresponding field within the model so we can get its index
1679
1759
  let serializedName;
1680
1760
  for (const property of opParamType.properties) {
1681
- if (property.name === param.name) {
1682
- serializedName = property.serializedName;
1761
+ if (property.kind === 'property' && property.name === param.name) {
1762
+ serializedName = this.getSerializedPropertyName(property);
1683
1763
  break;
1684
1764
  }
1685
1765
  }
@@ -1693,7 +1773,8 @@ export class Adapter {
1693
1773
  }
1694
1774
  const paramName = naming.getEscapedReservedName(snakeCaseName(param.name), 'param');
1695
1775
  const paramLoc = 'method';
1696
- const adaptedParam = new rust.PartialBodyParameter(paramName, paramLoc, param.optional, serializedName, this.getType(param.type), new rust.RequestContent(this.crate, new rust.Payload(payloadType, format)));
1776
+ const formatType = shared.getPayloadFormatType(format);
1777
+ const adaptedParam = new rust.PartialBodyParameter(paramName, paramLoc, param.optional, serializedName, this.getType(param.type), new rust.RequestContent(this.crate, new rust.Payload(payloadType, format), formatType));
1697
1778
  return adaptedParam;
1698
1779
  }
1699
1780
  /**
@@ -1717,18 +1798,18 @@ export class Adapter {
1717
1798
  }
1718
1799
  }
1719
1800
  /**
1720
- * converts an accept header value into a response format
1801
+ * converts an accept or content-type header value into a payload format type
1721
1802
  *
1722
- * @param accept the value of the Content-Type header
1803
+ * @param contentType the value of the Accept or Content-Type header
1723
1804
  * @returns a response format
1724
1805
  */
1725
- adaptResponseFormat(accept) {
1806
+ adaptPayloadFormatType(contentType) {
1726
1807
  // we only recognize/support JSON and XML content types.
1727
1808
  // anything else is NoFormat
1728
- if (accept.match(/json/i)) {
1809
+ if (contentType.match(/json/i)) {
1729
1810
  return 'JsonFormat';
1730
1811
  }
1731
- else if (accept.match(/xml/i)) {
1812
+ else if (contentType.match(/xml/i)) {
1732
1813
  // XML support is disabled by default
1733
1814
  this.crate.addDependency(new rust.CrateDependency('azure_core', ['xml']));
1734
1815
  return 'XmlFormat';
@@ -1781,17 +1862,18 @@ function snakeCaseName(name) {
1781
1862
  * this is idempotent so providing the same type will create
1782
1863
  * the same key.
1783
1864
  *
1784
- * obj is recursively unwrapped, and each layer is used to construct
1865
+ * type is recursively unwrapped, and each layer is used to construct
1785
1866
  * the key. e.g. if obj is a HashMap<String, Vec<i32>> this would
1786
1867
  * unwrap to hashmap-Vec-i32.
1787
1868
  *
1788
1869
  * @param root the starting value for the key
1789
- * @param obj the type for which to create the key
1870
+ * @param type the type for which to create the key
1790
1871
  * @returns a string containing the complete map key
1791
1872
  */
1792
1873
  function recursiveKeyName(root, type) {
1793
1874
  switch (type.kind) {
1794
1875
  case 'Vec':
1876
+ case 'box':
1795
1877
  return recursiveKeyName(`${root}-${type.kind}`, type.type);
1796
1878
  case 'encodedBytes':
1797
1879
  return `${root}-${type.kind}-${type.encoding}${type.slice ? '-slice' : ''}`;
@@ -1804,9 +1886,16 @@ function recursiveKeyName(root, type) {
1804
1886
  case 'offsetDateTime':
1805
1887
  return `${root}-${type.kind}-${type.encoding}${type.utc ? '-utc' : ''}`;
1806
1888
  case 'model':
1889
+ case 'struct':
1807
1890
  return `${root}-${type.kind}-${type.name}`;
1891
+ case 'literal':
1892
+ return `${recursiveKeyName(`${root}-${type.kind}`, type.valueKind)}-${type.value}`;
1893
+ case 'payload':
1894
+ return recursiveKeyName(`${root}-${type.kind}-${type.format}`, type.type);
1808
1895
  case 'ref':
1809
1896
  return recursiveKeyName(`${root}-${type.kind}`, type.type);
1897
+ case 'requestContent':
1898
+ return recursiveKeyName(`${root}-${type.kind}`, type.content);
1810
1899
  case 'safeint':
1811
1900
  case 'decimal':
1812
1901
  return `${root}-${type.kind}${type.stringEncoding ? '-string' : ''}`;