@azure-tools/typespec-java 0.31.3 → 0.31.5

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 (37) hide show
  1. package/dist/src/code-model-builder.d.ts.map +1 -1
  2. package/dist/src/code-model-builder.js +180 -233
  3. package/dist/src/code-model-builder.js.map +1 -1
  4. package/dist/src/common/client.js +14 -0
  5. package/dist/src/common/client.js.map +1 -1
  6. package/dist/src/common/code-model.js +3 -4
  7. package/dist/src/common/code-model.js.map +1 -1
  8. package/dist/src/common/long-running-metadata.js +5 -1
  9. package/dist/src/common/long-running-metadata.js.map +1 -1
  10. package/dist/src/common/operation.js +3 -4
  11. package/dist/src/common/operation.js.map +1 -1
  12. package/dist/src/emitter.d.ts.map +1 -1
  13. package/dist/src/emitter.js +12 -8
  14. package/dist/src/emitter.js.map +1 -1
  15. package/dist/src/external-schemas.js +4 -5
  16. package/dist/src/external-schemas.js.map +1 -1
  17. package/dist/src/models.js +6 -1
  18. package/dist/src/models.js.map +1 -1
  19. package/dist/src/operation-utils.d.ts +11 -2
  20. package/dist/src/operation-utils.d.ts.map +1 -1
  21. package/dist/src/operation-utils.js +38 -4
  22. package/dist/src/operation-utils.js.map +1 -1
  23. package/dist/src/options.d.ts.map +1 -1
  24. package/dist/src/options.js +6 -1
  25. package/dist/src/options.js.map +1 -1
  26. package/dist/src/type-utils.js +9 -6
  27. package/dist/src/type-utils.js.map +1 -1
  28. package/dist/src/utils.js +3 -0
  29. package/dist/src/utils.js.map +1 -1
  30. package/dist/src/validate.js +2 -3
  31. package/dist/src/validate.js.map +1 -1
  32. package/dist/src/versioning-utils.js +3 -2
  33. package/dist/src/versioning-utils.js.map +1 -1
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/generator/http-client-generator/target/classes/PerfAutomation.jfc +948 -0
  36. package/generator/http-client-generator/target/emitter.jar +0 -0
  37. package/package.json +17 -15
@@ -19,7 +19,7 @@ import { SchemaContext } from "./common/schemas/usage.js";
19
19
  import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
20
20
  import { createDiagnostic, reportDiagnostic } from "./lib.js";
21
21
  import { ClientContext } from "./models.js";
22
- import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
22
+ import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, findResponsePropertySegments, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
23
23
  import { LIB_NAME } from "./options.js";
24
24
  import { BYTES_KNOWN_ENCODING, DATETIME_KNOWN_ENCODING, DURATION_KNOWN_ENCODING, ProcessingCache, getAccess, getDurationFormat, getNonNullSdkType, getPropertySerializedName, getUnionDescription, getUsage, modelIs, pushDistinct, } from "./type-utils.js";
25
25
  import { DiagnosticError, escapeJavaKeywords, getNamespace, optionBoolean, pascalCase, removeClientSuffix, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
@@ -27,10 +27,20 @@ import { getFilteredApiVersions, getServiceApiVersions } from "./versioning-util
27
27
  const { isEqual } = pkg;
28
28
  const AZURE_CORE_FOUNDATIONS_ERROR_ID = "Azure.Core.Foundations.Error";
29
29
  export class CodeModelBuilder {
30
+ program;
31
+ typeNameOptions;
32
+ namespace;
33
+ baseJavaNamespace;
34
+ sdkContext;
35
+ options;
36
+ codeModel;
37
+ emitterContext;
38
+ serviceNamespace;
39
+ javaNamespaceCache = new Map();
40
+ schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
41
+ // current apiVersion name to generate code
42
+ apiVersion;
30
43
  constructor(program1, context) {
31
- var _a, _b;
32
- this.javaNamespaceCache = new Map();
33
- this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
34
44
  this.options = context.options;
35
45
  this.program = program1;
36
46
  this.emitterContext = context;
@@ -44,7 +54,7 @@ export class CodeModelBuilder {
44
54
  target: NoTarget,
45
55
  });
46
56
  }
47
- this.serviceNamespace = (_a = service === null || service === void 0 ? void 0 : service.type) !== null && _a !== void 0 ? _a : this.program.getGlobalNamespaceType();
57
+ this.serviceNamespace = service?.type ?? this.program.getGlobalNamespaceType();
48
58
  this.namespace = getNamespaceFullName(this.serviceNamespace) || "Client";
49
59
  const namespace1 = this.namespace;
50
60
  this.typeNameOptions = {
@@ -55,7 +65,7 @@ export class CodeModelBuilder {
55
65
  },
56
66
  };
57
67
  // init code model
58
- const title = (_b = this.options["service-name"]) !== null && _b !== void 0 ? _b : this.serviceNamespace.name;
68
+ const title = this.options["service-name"] ?? this.serviceNamespace.name;
59
69
  const description = this.getDoc(this.serviceNamespace);
60
70
  this.codeModel = new CodeModel(title, false, {
61
71
  info: {
@@ -122,7 +132,6 @@ export class CodeModelBuilder {
122
132
  const hostParameters = [];
123
133
  let parameter;
124
134
  sdkPathParameters.forEach((arg) => {
125
- var _a;
126
135
  if (this.isApiVersionParameter(arg)) {
127
136
  parameter = this.createApiVersionParameter(arg.name, ParameterLocation.Uri);
128
137
  }
@@ -131,7 +140,7 @@ export class CodeModelBuilder {
131
140
  this.trackSchemaUsage(schema, {
132
141
  usage: [SchemaContext.Input, SchemaContext.Output, SchemaContext.Public],
133
142
  });
134
- parameter = new Parameter(arg.name, (_a = arg.doc) !== null && _a !== void 0 ? _a : "", schema, {
143
+ parameter = new Parameter(arg.name, arg.doc ?? "", schema, {
135
144
  implementation: ImplementationLocation.Client,
136
145
  origin: "modelerfour:synthesized/host",
137
146
  required: true,
@@ -219,17 +228,14 @@ export class CodeModelBuilder {
219
228
  }
220
229
  }
221
230
  isBranded() {
222
- var _a, _b;
223
- return (((_a = this.options["flavor"]) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "azure" ||
224
- ((_b = this.options["flavor"]) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === "azurev2");
231
+ return (this.options["flavor"]?.toLocaleLowerCase() === "azure" ||
232
+ this.options["flavor"]?.toLocaleLowerCase() === "azurev2");
225
233
  }
226
234
  isAzureV1() {
227
- var _a;
228
- return ((_a = this.options["flavor"]) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "azure";
235
+ return this.options["flavor"]?.toLocaleLowerCase() === "azure";
229
236
  }
230
237
  isAzureV2() {
231
- var _a;
232
- return ((_a = this.options["flavor"]) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "azurev2";
238
+ return this.options["flavor"]?.toLocaleLowerCase() === "azurev2";
233
239
  }
234
240
  processModels() {
235
241
  const processedSdkModels = new Set();
@@ -267,30 +273,27 @@ export class CodeModelBuilder {
267
273
  }
268
274
  }
269
275
  processSchemaUsage() {
270
- var _a, _b, _c, _d, _e, _f, _g;
271
- (_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => this.propagateSchemaUsage(it));
276
+ this.codeModel.schemas.objects?.forEach((it) => this.propagateSchemaUsage(it));
272
277
  // post process for schema usage
273
- (_b = this.codeModel.schemas.objects) === null || _b === void 0 ? void 0 : _b.forEach((it) => this.resolveSchemaUsage(it));
274
- (_c = this.codeModel.schemas.groups) === null || _c === void 0 ? void 0 : _c.forEach((it) => this.resolveSchemaUsage(it));
275
- (_d = this.codeModel.schemas.choices) === null || _d === void 0 ? void 0 : _d.forEach((it) => this.resolveSchemaUsage(it));
276
- (_e = this.codeModel.schemas.sealedChoices) === null || _e === void 0 ? void 0 : _e.forEach((it) => this.resolveSchemaUsage(it));
277
- (_f = this.codeModel.schemas.ors) === null || _f === void 0 ? void 0 : _f.forEach((it) => this.resolveSchemaUsage(it));
278
- (_g = this.codeModel.schemas.constants) === null || _g === void 0 ? void 0 : _g.forEach((it) => this.resolveSchemaUsage(it));
278
+ this.codeModel.schemas.objects?.forEach((it) => this.resolveSchemaUsage(it));
279
+ this.codeModel.schemas.groups?.forEach((it) => this.resolveSchemaUsage(it));
280
+ this.codeModel.schemas.choices?.forEach((it) => this.resolveSchemaUsage(it));
281
+ this.codeModel.schemas.sealedChoices?.forEach((it) => this.resolveSchemaUsage(it));
282
+ this.codeModel.schemas.ors?.forEach((it) => this.resolveSchemaUsage(it));
283
+ this.codeModel.schemas.constants?.forEach((it) => this.resolveSchemaUsage(it));
279
284
  }
280
285
  deduplicateSchemaName() {
281
- var _a, _b, _c, _d, _e, _f;
282
286
  // deduplicate model name
283
287
  const nameCount = new Map();
284
288
  const deduplicateName = (schema) => {
285
- var _a, _b, _c, _d, _e, _f, _g, _h;
286
289
  const name = schema.language.default.name;
287
290
  if (name &&
288
291
  // skip models under "com.azure.core." in java, or "Azure." in typespec, if branded
289
292
  !((this.isBranded() &&
290
- (((_b = (_a = schema.language.java) === null || _a === void 0 ? void 0 : _a.namespace) === null || _b === void 0 ? void 0 : _b.startsWith("com.azure.core.")) ||
291
- ((_d = (_c = schema.language.default) === null || _c === void 0 ? void 0 : _c.namespace) === null || _d === void 0 ? void 0 : _d.startsWith("Azure.")) ||
292
- ((_f = (_e = schema.language.java) === null || _e === void 0 ? void 0 : _e.namespace) === null || _f === void 0 ? void 0 : _f.startsWith("com.azure.v2.core.")) ||
293
- ((_h = (_g = schema.language.java) === null || _g === void 0 ? void 0 : _g.namespace) === null || _h === void 0 ? void 0 : _h.startsWith("io.clientcore.core.")))) // because azure core v2 uses clientcore types
293
+ (schema.language.java?.namespace?.startsWith("com.azure.core.") ||
294
+ schema.language.default?.namespace?.startsWith("Azure.") ||
295
+ schema.language.java?.namespace?.startsWith("com.azure.v2.core.") ||
296
+ schema.language.java?.namespace?.startsWith("io.clientcore.core."))) // because azure core v2 uses clientcore types
294
297
  )) {
295
298
  if (!nameCount.has(name)) {
296
299
  nameCount.set(name, 1);
@@ -302,12 +305,12 @@ export class CodeModelBuilder {
302
305
  }
303
306
  }
304
307
  };
305
- (_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => deduplicateName(it));
306
- (_b = this.codeModel.schemas.groups) === null || _b === void 0 ? void 0 : _b.forEach((it) => deduplicateName(it)); // it may contain RequestConditions under "com.azure.core."
307
- (_c = this.codeModel.schemas.choices) === null || _c === void 0 ? void 0 : _c.forEach((it) => deduplicateName(it));
308
- (_d = this.codeModel.schemas.sealedChoices) === null || _d === void 0 ? void 0 : _d.forEach((it) => deduplicateName(it));
309
- (_e = this.codeModel.schemas.ors) === null || _e === void 0 ? void 0 : _e.forEach((it) => deduplicateName(it));
310
- (_f = this.codeModel.schemas.constants) === null || _f === void 0 ? void 0 : _f.forEach((it) => deduplicateName(it));
308
+ this.codeModel.schemas.objects?.forEach((it) => deduplicateName(it));
309
+ this.codeModel.schemas.groups?.forEach((it) => deduplicateName(it)); // it may contain RequestConditions under "com.azure.core."
310
+ this.codeModel.schemas.choices?.forEach((it) => deduplicateName(it));
311
+ this.codeModel.schemas.sealedChoices?.forEach((it) => deduplicateName(it));
312
+ this.codeModel.schemas.ors?.forEach((it) => deduplicateName(it));
313
+ this.codeModel.schemas.constants?.forEach((it) => deduplicateName(it));
311
314
  }
312
315
  resolveSchemaUsage(schema) {
313
316
  if (schema instanceof ObjectSchema ||
@@ -318,18 +321,18 @@ export class CodeModelBuilder {
318
321
  schema instanceof ConstantSchema) {
319
322
  const schemaUsage = schema.usage;
320
323
  // Public override Internal
321
- if (schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.includes(SchemaContext.Public)) {
324
+ if (schemaUsage?.includes(SchemaContext.Public)) {
322
325
  const index = schemaUsage.indexOf(SchemaContext.Internal);
323
326
  if (index >= 0) {
324
327
  schemaUsage.splice(index, 1);
325
328
  }
326
329
  }
327
330
  // Internal on PublicSpread, but Public takes precedence
328
- if (schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.includes(SchemaContext.PublicSpread)) {
331
+ if (schemaUsage?.includes(SchemaContext.PublicSpread)) {
329
332
  // remove PublicSpread as it now served its purpose
330
333
  schemaUsage.splice(schemaUsage.indexOf(SchemaContext.PublicSpread), 1);
331
334
  // Public would override PublicSpread, hence do nothing if this schema is Public
332
- if (!(schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.includes(SchemaContext.Public))) {
335
+ if (!schemaUsage?.includes(SchemaContext.Public)) {
333
336
  // set the model as Internal, so that it is not exposed to user
334
337
  if (!schemaUsage.includes(SchemaContext.Internal)) {
335
338
  schemaUsage.push(SchemaContext.Internal);
@@ -340,15 +343,13 @@ export class CodeModelBuilder {
340
343
  }
341
344
  processClients() {
342
345
  // preprocess group-etag-headers
343
- var _a;
344
- this.options["group-etag-headers"] = (_a = this.options["group-etag-headers"]) !== null && _a !== void 0 ? _a : true;
346
+ this.options["group-etag-headers"] = this.options["group-etag-headers"] ?? true;
345
347
  const sdkPackage = this.sdkContext.sdkPackage;
346
348
  for (const client of sdkPackage.clients) {
347
349
  this.processClient(client);
348
350
  }
349
351
  }
350
352
  processClient(client) {
351
- var _a, _b, _c;
352
353
  let clientName = client.name;
353
354
  let javaNamespace = this.getJavaNamespace(client);
354
355
  const clientFullName = client.name;
@@ -360,12 +361,14 @@ export class CodeModelBuilder {
360
361
  }
361
362
  if (this.isArm()) {
362
363
  if (this.options["service-name"] &&
364
+ client.__raw &&
365
+ client.__raw.type &&
363
366
  !getClientNameOverride(this.sdkContext, client.__raw.type)) {
364
367
  // When no `@clientName` override, use "service-name" to infer the client name
365
368
  clientName = this.options["service-name"].replace(/\s+/g, "") + "ManagementClient";
366
369
  }
367
370
  }
368
- const codeModelClient = new CodeModelClient(clientName, (_a = client.doc) !== null && _a !== void 0 ? _a : "", {
371
+ const codeModelClient = new CodeModelClient(clientName, client.doc ?? "", {
369
372
  summary: client.summary,
370
373
  language: {
371
374
  default: {
@@ -406,7 +409,6 @@ export class CodeModelBuilder {
406
409
  let baseUri = "{endpoint}";
407
410
  let hostParameters = [];
408
411
  client.clientInitialization.parameters.forEach((initializationProperty) => {
409
- var _a;
410
412
  if (initializationProperty.kind === "endpoint") {
411
413
  let sdkPathParameters = [];
412
414
  if (initializationProperty.type.kind === "union") {
@@ -422,7 +424,7 @@ export class CodeModelBuilder {
422
424
  else if (initializationProperty.type.variantTypes.length > 2) {
423
425
  reportDiagnostic(this.program, {
424
426
  code: "multiple-server-not-supported",
425
- target: (_a = initializationProperty.type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
427
+ target: initializationProperty.type.__raw ?? NoTarget,
426
428
  });
427
429
  }
428
430
  }
@@ -435,7 +437,7 @@ export class CodeModelBuilder {
435
437
  }
436
438
  });
437
439
  const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters, codeModelClient.apiVersions);
438
- const enableSubclient = (_b = optionBoolean(this.options["enable-subclient"])) !== null && _b !== void 0 ? _b : false;
440
+ const enableSubclient = optionBoolean(this.options["enable-subclient"]) ?? false;
439
441
  // preprocess operation groups and operations
440
442
  // operations without operation group
441
443
  const serviceMethodsWithoutSubClient = client.methods;
@@ -446,7 +448,7 @@ export class CodeModelBuilder {
446
448
  codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, ""));
447
449
  }
448
450
  }
449
- if (((_c = codeModelGroup.operations) === null || _c === void 0 ? void 0 : _c.length) > 0 || enableSubclient) {
451
+ if (codeModelGroup.operations?.length > 0 || enableSubclient) {
450
452
  codeModelClient.operationGroups.push(codeModelGroup);
451
453
  }
452
454
  const subClients = this.listSubClientsUnderClient(client, !enableSubclient);
@@ -551,11 +553,9 @@ export class CodeModelBuilder {
551
553
  * Whether we support advanced versioning in non-breaking fashion.
552
554
  */
553
555
  supportsAdvancedVersioning() {
554
- var _a;
555
- return (_a = optionBoolean(this.options["advanced-versioning"])) !== null && _a !== void 0 ? _a : false;
556
+ return optionBoolean(this.options["advanced-versioning"]) ?? false;
556
557
  }
557
558
  getOperationExample(sdkMethod) {
558
- var _a, _b;
559
559
  const httpOperationExamples = sdkMethod.operation.examples;
560
560
  if (httpOperationExamples && httpOperationExamples.length > 0) {
561
561
  const operationExamples = {};
@@ -564,7 +564,7 @@ export class CodeModelBuilder {
564
564
  // example.filePath is relative path from sdkContext.examplesDir
565
565
  // this is not a URL format (file:// or https://)
566
566
  operationExample["x-ms-original-file"] = example.filePath;
567
- operationExamples[(_b = (_a = operationExample.title) !== null && _a !== void 0 ? _a : operationExample.operationId) !== null && _b !== void 0 ? _b : sdkMethod.name] = operationExample;
567
+ operationExamples[operationExample.title ?? operationExample.operationId ?? sdkMethod.name] = operationExample;
568
568
  }
569
569
  return operationExamples;
570
570
  }
@@ -573,12 +573,11 @@ export class CodeModelBuilder {
573
573
  }
574
574
  }
575
575
  processOperation(sdkMethod, clientContext, groupName) {
576
- var _a, _b, _c, _d;
577
576
  const operationName = sdkMethod.name;
578
577
  const httpOperation = sdkMethod.operation;
579
578
  const operationId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
580
579
  const operationExamples = this.getOperationExample(sdkMethod);
581
- const codeModelOperation = new CodeModelOperation(operationName, (_a = sdkMethod.doc) !== null && _a !== void 0 ? _a : "", {
580
+ const codeModelOperation = new CodeModelOperation(operationName, sdkMethod.doc ?? "", {
582
581
  operationId: operationId,
583
582
  summary: sdkMethod.summary,
584
583
  extensions: {
@@ -601,7 +600,7 @@ export class CodeModelBuilder {
601
600
  code: "protocol-api-not-generated",
602
601
  messageId: "multipartFormData",
603
602
  format: { operationName: operationName },
604
- target: (_b = sdkMethod.__raw) !== null && _b !== void 0 ? _b : NoTarget,
603
+ target: sdkMethod.__raw ?? NoTarget,
605
604
  });
606
605
  this.program.reportDiagnostic(diagnostic);
607
606
  }
@@ -613,7 +612,7 @@ export class CodeModelBuilder {
613
612
  code: "convenience-api-not-generated",
614
613
  messageId: "multipleContentType",
615
614
  format: { operationName: operationName },
616
- target: (_c = sdkMethod.__raw) !== null && _c !== void 0 ? _c : NoTarget,
615
+ target: sdkMethod.__raw ?? NoTarget,
617
616
  });
618
617
  this.program.reportDiagnostic(diagnostic);
619
618
  }
@@ -625,7 +624,7 @@ export class CodeModelBuilder {
625
624
  code: "convenience-api-not-generated",
626
625
  messageId: "jsonMergePatch",
627
626
  format: { operationName: operationName },
628
- target: (_d = sdkMethod.__raw) !== null && _d !== void 0 ? _d : NoTarget,
627
+ target: sdkMethod.__raw ?? NoTarget,
629
628
  });
630
629
  this.program.reportDiagnostic(diagnostic);
631
630
  }
@@ -701,7 +700,6 @@ export class CodeModelBuilder {
701
700
  return codeModelOperation;
702
701
  }
703
702
  processRouteForPaged(op, sdkMethod) {
704
- var _a, _b, _c, _d;
705
703
  if (sdkMethod.kind !== "paging" && sdkMethod.kind !== "lropaging") {
706
704
  return;
707
705
  }
@@ -715,49 +713,46 @@ export class CodeModelBuilder {
715
713
  if (!bodyType || bodyType.kind !== "model") {
716
714
  return;
717
715
  }
718
- (_a = op.responses) === null || _a === void 0 ? void 0 : _a.forEach((r) => {
716
+ op.responses?.forEach((r) => {
719
717
  if (r instanceof SchemaResponse) {
720
718
  this.trackSchemaUsage(r.schema, { usage: [SchemaContext.Paged] });
721
719
  }
722
720
  });
723
- function getLastPropertySegment(segments) {
724
- if (segments) {
725
- const lastSegment = segments[segments.length - 1];
726
- if (lastSegment.kind === "property") {
727
- return lastSegment;
728
- }
729
- }
730
- return undefined;
731
- }
732
721
  function getLastSegment(segments) {
733
722
  if (segments) {
734
723
  return segments[segments.length - 1];
735
724
  }
736
725
  return undefined;
737
726
  }
738
- function getLastSegmentSerializedName(segments) {
739
- const lastSegment = getLastPropertySegment(segments);
740
- return lastSegment ? getPropertySerializedName(lastSegment) : undefined;
741
- }
742
- // TODO: in future the property could be nested, so that the "itemSegments" or "nextLinkSegments" would contain more than 1 element
743
- // item/result
744
- // "itemsSegments" should exist for "paging"/"lropaging"
745
- const itemSerializedName = getLastSegmentSerializedName(sdkMethod.response.resultSegments);
727
+ // pageItems
728
+ const pageItemsResponseProperty = findResponsePropertySegments(op, sdkMethod.response.resultSegments);
729
+ // "sdkMethod.response.resultSegments" should not be empty for "paging"/"lropaging"
730
+ // "itemSerializedName" take 1st property for backward compatibility
731
+ const itemSerializedName = pageItemsResponseProperty && pageItemsResponseProperty.length > 0
732
+ ? pageItemsResponseProperty[0].serializedName
733
+ : undefined;
746
734
  // nextLink
747
- const nextLinkSerializedName = getLastSegmentSerializedName(sdkMethod.pagingMetadata.nextLinkSegments);
735
+ // TODO: nextLink can also be a response header, similar to "sdkMethod.pagingMetadata.continuationTokenResponseSegments"
736
+ const nextLinkResponseProperty = findResponsePropertySegments(op, sdkMethod.pagingMetadata.nextLinkSegments);
737
+ // "nextLinkSerializedName" take 1st property for backward compatibility
738
+ const nextLinkSerializedName = nextLinkResponseProperty && nextLinkResponseProperty.length > 0
739
+ ? nextLinkResponseProperty[0].serializedName
740
+ : undefined;
748
741
  // continuationToken
749
742
  let continuationTokenParameter;
750
743
  let continuationTokenResponseProperty;
751
744
  let continuationTokenResponseHeader;
752
745
  if (!this.isBranded()) {
746
+ // parameter would either be query or header parameter, so taking the last segment would be enough
753
747
  const continuationTokenParameterSegment = getLastSegment(sdkMethod.pagingMetadata.continuationTokenParameterSegments);
748
+ // response could be response header, where the last segment would do; or it be json path in the response body, where we use "findResponsePropertySegments" to find them
754
749
  const continuationTokenResponseSegment = getLastSegment(sdkMethod.pagingMetadata.continuationTokenResponseSegments);
755
750
  if (continuationTokenParameterSegment && op.parameters) {
756
751
  // for now, continuationToken is either request query or header parameter
757
752
  const parameter = getHttpOperationParameter(sdkMethod, continuationTokenParameterSegment);
758
753
  if (parameter) {
759
754
  for (const param of op.parameters) {
760
- if (((_b = param.protocol.http) === null || _b === void 0 ? void 0 : _b.in) === parameter.kind) {
755
+ if (param.protocol.http?.in === parameter.kind) {
761
756
  if (parameter.kind === "header" &&
762
757
  param.language.default.serializedName.toLowerCase() ===
763
758
  parameter.serializedName.toLowerCase()) {
@@ -774,7 +769,7 @@ export class CodeModelBuilder {
774
769
  }
775
770
  }
776
771
  if (continuationTokenResponseSegment && op.responses) {
777
- if ((continuationTokenResponseSegment === null || continuationTokenResponseSegment === void 0 ? void 0 : continuationTokenResponseSegment.kind) === "responseheader") {
772
+ if (continuationTokenResponseSegment?.kind === "responseheader") {
778
773
  // continuationToken is response header
779
774
  for (const response of op.responses) {
780
775
  if (response instanceof SchemaResponse && response.protocol.http) {
@@ -791,25 +786,8 @@ export class CodeModelBuilder {
791
786
  }
792
787
  }
793
788
  }
794
- else if ((continuationTokenResponseSegment === null || continuationTokenResponseSegment === void 0 ? void 0 : continuationTokenResponseSegment.kind) === "property") {
795
- // continuationToken is response body property
796
- // TODO: the property could be nested
797
- for (const response of op.responses) {
798
- if (response instanceof SchemaResponse &&
799
- response.schema instanceof ObjectSchema &&
800
- response.schema.properties) {
801
- for (const property of response.schema.properties) {
802
- if (property.serializedName ===
803
- getPropertySerializedName(continuationTokenResponseSegment)) {
804
- continuationTokenResponseProperty = [property];
805
- break;
806
- }
807
- }
808
- }
809
- if (continuationTokenResponseProperty) {
810
- break;
811
- }
812
- }
789
+ else if (continuationTokenResponseSegment?.kind === "property") {
790
+ continuationTokenResponseProperty = findResponsePropertySegments(op, sdkMethod.pagingMetadata.continuationTokenResponseSegments);
813
791
  }
814
792
  }
815
793
  }
@@ -828,7 +806,7 @@ export class CodeModelBuilder {
828
806
  if (parameter) {
829
807
  // find the corresponding parameter in the code model operation
830
808
  for (const opParam of op.parameters) {
831
- if (((_c = opParam.protocol.http) === null || _c === void 0 ? void 0 : _c.in) === parameter.kind &&
809
+ if (opParam.protocol.http?.in === parameter.kind &&
832
810
  opParam.language.default.serializedName === parameter.serializedName) {
833
811
  nextLinkReInjectedParameters.push(opParam);
834
812
  break;
@@ -839,10 +817,14 @@ export class CodeModelBuilder {
839
817
  }
840
818
  }
841
819
  }
842
- op.extensions = (_d = op.extensions) !== null && _d !== void 0 ? _d : {};
820
+ op.extensions = op.extensions ?? {};
843
821
  op.extensions["x-ms-pageable"] = {
822
+ // this part need to be compatible with modelerfour
844
823
  itemName: itemSerializedName,
845
824
  nextLinkName: nextLinkSerializedName,
825
+ // this part is only available in TypeSpec
826
+ pageItemsProperty: pageItemsResponseProperty,
827
+ nextLinkProperty: nextLinkResponseProperty,
846
828
  continuationToken: continuationTokenParameter
847
829
  ? new PageableContinuationToken(continuationTokenParameter, continuationTokenResponseProperty, continuationTokenResponseHeader)
848
830
  : undefined,
@@ -924,15 +906,13 @@ export class CodeModelBuilder {
924
906
  return new LongRunningMetadata(false);
925
907
  }
926
908
  processRouteForLongRunning(op, lroMetadata) {
927
- var _a;
928
909
  if (lroMetadata.longRunning) {
929
- op.extensions = (_a = op.extensions) !== null && _a !== void 0 ? _a : {};
910
+ op.extensions = op.extensions ?? {};
930
911
  op.extensions["x-ms-long-running-operation"] = true;
931
912
  return;
932
913
  }
933
914
  }
934
915
  processParameter(op, param, clientContext) {
935
- var _a, _b, _c;
936
916
  if (clientContext.apiVersions && this.isApiVersionParameter(param) && param.kind !== "cookie") {
937
917
  // pre-condition for "isApiVersion": the client supports ApiVersions
938
918
  if (this.isArm()) {
@@ -959,7 +939,7 @@ export class CodeModelBuilder {
959
939
  else if (param.kind === "header" &&
960
940
  SPECIAL_HEADER_NAMES.has(param.serializedName.toLowerCase())) {
961
941
  // special headers
962
- op.specialHeaders = (_a = op.specialHeaders) !== null && _a !== void 0 ? _a : [];
942
+ op.specialHeaders = op.specialHeaders ?? [];
963
943
  if (!stringArrayContainsIgnoreCase(op.specialHeaders, param.serializedName)) {
964
944
  op.specialHeaders.push(param.serializedName);
965
945
  }
@@ -971,7 +951,7 @@ export class CodeModelBuilder {
971
951
  let extensions = undefined;
972
952
  if (param.kind === "path") {
973
953
  if (param.allowReserved) {
974
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
954
+ extensions = extensions ?? {};
975
955
  extensions["x-ms-skip-url-encoding"] = true;
976
956
  }
977
957
  }
@@ -979,14 +959,14 @@ export class CodeModelBuilder {
979
959
  if ((param.kind === "query" || param.kind === "path") &&
980
960
  isSdkBuiltInKind(sdkType.kind) &&
981
961
  schema instanceof UriSchema) {
982
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
962
+ extensions = extensions ?? {};
983
963
  extensions["x-ms-skip-url-encoding"] = true;
984
964
  }
985
965
  if (this.supportsAdvancedVersioning() && param.__raw) {
986
966
  // versioning
987
967
  const addedOn = getAddedOnVersions(this.program, param.__raw);
988
968
  if (addedOn) {
989
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
969
+ extensions = extensions ?? {};
990
970
  extensions["x-ms-versioning-added"] = clientContext.getAddedVersions(addedOn);
991
971
  }
992
972
  }
@@ -1032,7 +1012,7 @@ export class CodeModelBuilder {
1032
1012
  reportDiagnostic(this.program, {
1033
1013
  code: "header-parameter-format-not-supported",
1034
1014
  format: { format: format },
1035
- target: (_b = param.__raw) !== null && _b !== void 0 ? _b : NoTarget,
1015
+ target: param.__raw ?? NoTarget,
1036
1016
  });
1037
1017
  }
1038
1018
  break;
@@ -1048,7 +1028,7 @@ export class CodeModelBuilder {
1048
1028
  }
1049
1029
  }
1050
1030
  const nullable = param.type.kind === "nullable";
1051
- const parameter = new Parameter(parameterName, (_c = param.doc) !== null && _c !== void 0 ? _c : "", schema, {
1031
+ const parameter = new Parameter(parameterName, param.doc ?? "", schema, {
1052
1032
  summary: param.summary,
1053
1033
  implementation: parameterOnClient
1054
1034
  ? ImplementationLocation.Client
@@ -1100,9 +1080,8 @@ export class CodeModelBuilder {
1100
1080
  }
1101
1081
  }
1102
1082
  processSdkMethodOverride(op, sdkMethod) {
1103
- var _a, _b, _c;
1104
1083
  // method be called, only if "op.convenienceApi"
1105
- let request = (_b = (_a = op.convenienceApi) === null || _a === void 0 ? void 0 : _a.requests) === null || _b === void 0 ? void 0 : _b[0];
1084
+ let request = op.convenienceApi?.requests?.[0];
1106
1085
  let requestParameters;
1107
1086
  if (request) {
1108
1087
  requestParameters = request.parameters;
@@ -1123,7 +1102,7 @@ export class CodeModelBuilder {
1123
1102
  if (parameter.type.kind !== "constant") {
1124
1103
  if (parameter.kind === "body") {
1125
1104
  // there should be only 1 body parameter
1126
- opParameter = requestParameters.find((it) => { var _a; return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === "body"; });
1105
+ opParameter = requestParameters.find((it) => it.protocol.http?.in === "body");
1127
1106
  }
1128
1107
  else if (parameter.kind === "property") {
1129
1108
  // body property
@@ -1133,11 +1112,8 @@ export class CodeModelBuilder {
1133
1112
  }
1134
1113
  else {
1135
1114
  // query, path, header
1136
- opParameter = requestParameters.find((it) => {
1137
- var _a;
1138
- return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === parameter.kind &&
1139
- it.language.default.serializedName === parameter.serializedName;
1140
- });
1115
+ opParameter = requestParameters.find((it) => it.protocol.http?.in === parameter.kind &&
1116
+ it.language.default.serializedName === parameter.serializedName);
1141
1117
  }
1142
1118
  }
1143
1119
  return opParameter;
@@ -1178,7 +1154,7 @@ export class CodeModelBuilder {
1178
1154
  });
1179
1155
  }
1180
1156
  // group parameter
1181
- const groupParameter = new Parameter(sdkMethodParameter.name, (_c = sdkMethodParameter.doc) !== null && _c !== void 0 ? _c : "", groupSchema, {
1157
+ const groupParameter = new Parameter(sdkMethodParameter.name, sdkMethodParameter.doc ?? "", groupSchema, {
1182
1158
  summary: sdkMethodParameter.summary,
1183
1159
  implementation: ImplementationLocation.Method,
1184
1160
  required: !sdkMethodParameter.optional,
@@ -1196,13 +1172,12 @@ export class CodeModelBuilder {
1196
1172
  }
1197
1173
  processGroupSchema(type, parameters, name, description = undefined) {
1198
1174
  // the "GroupSchema" is simliar to "ObjectSchema", but the process is different
1199
- var _a, _b;
1200
1175
  if (type && this.schemaCache.has(type)) {
1201
1176
  return this.schemaCache.get(type);
1202
1177
  }
1203
1178
  // option bag schema
1204
- const optionBagSchema = this.codeModel.schemas.add(new GroupSchema(name, (_b = (_a = type === null || type === void 0 ? void 0 : type.doc) !== null && _a !== void 0 ? _a : description) !== null && _b !== void 0 ? _b : "", {
1205
- summary: type === null || type === void 0 ? void 0 : type.summary,
1179
+ const optionBagSchema = this.codeModel.schemas.add(new GroupSchema(name, type?.doc ?? description ?? "", {
1180
+ summary: type?.summary,
1206
1181
  language: {
1207
1182
  default: {
1208
1183
  namespace: type ? getNamespace(type.__raw) : this.namespace,
@@ -1229,10 +1204,9 @@ export class CodeModelBuilder {
1229
1204
  return optionBagSchema;
1230
1205
  }
1231
1206
  checkGroupingAfterBodyParameterFlatten(op) {
1232
- var _a, _b;
1233
1207
  // method be called, only if "op.convenienceApi" is defined
1234
1208
  // method signature of the convenience API after body parameter flatten
1235
- const request = (_b = (_a = op.convenienceApi) === null || _a === void 0 ? void 0 : _a.requests) === null || _b === void 0 ? void 0 : _b[0];
1209
+ const request = op.convenienceApi?.requests?.[0];
1236
1210
  if (request &&
1237
1211
  request.signatureParameters &&
1238
1212
  request.parameters &&
@@ -1258,7 +1232,6 @@ export class CodeModelBuilder {
1258
1232
  }
1259
1233
  }
1260
1234
  processEtagHeaderParameters(op, httpOperation) {
1261
- var _a, _b;
1262
1235
  if (op.convenienceApi && op.parameters && op.signatureParameters) {
1263
1236
  const etagHeadersNames = new Set([
1264
1237
  "if-match",
@@ -1292,7 +1265,7 @@ export class CodeModelBuilder {
1292
1265
  }
1293
1266
  if (groupToRequestConditions || groupToMatchConditions) {
1294
1267
  // method be called, only if "op.convenienceApi"
1295
- let request = (_b = (_a = op.convenienceApi) === null || _a === void 0 ? void 0 : _a.requests) === null || _b === void 0 ? void 0 : _b[0];
1268
+ let request = op.convenienceApi?.requests?.[0];
1296
1269
  let requestParameters;
1297
1270
  let requestSignatureParameters;
1298
1271
  if (request) {
@@ -1387,7 +1360,6 @@ export class CodeModelBuilder {
1387
1360
  }
1388
1361
  }
1389
1362
  processParameterBody(op, sdkMethod, sdkBody) {
1390
- var _a, _b, _c;
1391
1363
  let bodyParameterFlattened = false;
1392
1364
  const sdkHttpOperation = sdkMethod.operation;
1393
1365
  // set contentTypes to mediaTypes
@@ -1405,7 +1377,7 @@ export class CodeModelBuilder {
1405
1377
  schema = this.processSchema(getNonNullSdkType(sdkType), sdkBody.name);
1406
1378
  }
1407
1379
  const parameterName = sdkBody.name;
1408
- const parameter = new Parameter(parameterName, (_a = sdkBody.doc) !== null && _a !== void 0 ? _a : "", schema, {
1380
+ const parameter = new Parameter(parameterName, sdkBody.doc ?? "", schema, {
1409
1381
  summary: sdkBody.summary,
1410
1382
  implementation: ImplementationLocation.Method,
1411
1383
  required: !sdkBody.optional,
@@ -1416,7 +1388,7 @@ export class CodeModelBuilder {
1416
1388
  op.addParameter(parameter);
1417
1389
  const jsonMergePatch = operationIsJsonMergePatch(sdkHttpOperation);
1418
1390
  const schemaIsPublicBeforeProcess = schema instanceof ObjectSchema &&
1419
- ((_b = schema.usage) === null || _b === void 0 ? void 0 : _b.includes(SchemaContext.Public));
1391
+ schema.usage?.includes(SchemaContext.Public);
1420
1392
  this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });
1421
1393
  if (op.convenienceApi) {
1422
1394
  // model/schema does not need to be Public or Internal, if it is not to be used in convenience API
@@ -1443,7 +1415,7 @@ export class CodeModelBuilder {
1443
1415
  const bodyParameterFlatten = !this.isArm() &&
1444
1416
  schema instanceof ObjectSchema &&
1445
1417
  sdkType.kind === "model" &&
1446
- sdkBody.type !== ((_c = sdkBody.correspondingMethodParams[0]) === null || _c === void 0 ? void 0 : _c.type);
1418
+ sdkBody.type !== sdkBody.correspondingMethodParams[0]?.type;
1447
1419
  if (schema instanceof ObjectSchema && bodyParameterFlatten) {
1448
1420
  // flatten body parameter
1449
1421
  const parameters = sdkHttpOperation.parameters;
@@ -1462,10 +1434,10 @@ export class CodeModelBuilder {
1462
1434
  // flatten body parameter
1463
1435
  bodyParameterFlattened = true;
1464
1436
  const schemaUsage = schema.usage;
1465
- if (!schemaIsPublicBeforeProcess && (schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.includes(SchemaContext.Public))) {
1437
+ if (!schemaIsPublicBeforeProcess && schemaUsage?.includes(SchemaContext.Public)) {
1466
1438
  // Public added in this op, change it to PublicSpread
1467
1439
  // This means that if this op would originally add Public to this schema, it adds PublicSpread instead
1468
- schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.splice(schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.indexOf(SchemaContext.Public), 1);
1440
+ schemaUsage?.splice(schemaUsage?.indexOf(SchemaContext.Public), 1);
1469
1441
  this.trackSchemaUsage(schema, { usage: [SchemaContext.PublicSpread] });
1470
1442
  }
1471
1443
  op.convenienceApi.requests = [];
@@ -1494,7 +1466,6 @@ export class CodeModelBuilder {
1494
1466
  return bodyParameterFlattened;
1495
1467
  }
1496
1468
  addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, originalParameter) {
1497
- var _a, _b, _c, _d, _e;
1498
1469
  const serializedName = opParameter.kind === "property"
1499
1470
  ? getPropertySerializedName(opParameter)
1500
1471
  : opParameter.serializedName;
@@ -1502,24 +1473,21 @@ export class CodeModelBuilder {
1502
1473
  if (opParameter.kind !== "property") {
1503
1474
  // not body property
1504
1475
  // header/query/path, same location and same serializedName
1505
- existParameter = (_a = op.parameters) === null || _a === void 0 ? void 0 : _a.find((it) => {
1506
- var _a;
1507
- return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === opParameter.kind &&
1508
- it.language.default.serializedName === serializedName;
1509
- });
1476
+ existParameter = op.parameters?.find((it) => it.protocol.http?.in === opParameter.kind &&
1477
+ it.language.default.serializedName === serializedName);
1510
1478
  }
1511
- request.parameters = (_b = request.parameters) !== null && _b !== void 0 ? _b : [];
1479
+ request.parameters = request.parameters ?? [];
1512
1480
  if (existParameter) {
1513
1481
  // parameter
1514
1482
  if (existParameter.implementation === ImplementationLocation.Method &&
1515
- ((_d = (_c = existParameter.origin) === null || _c === void 0 ? void 0 : _c.startsWith("modelerfour:synthesized/")) !== null && _d !== void 0 ? _d : true) &&
1483
+ (existParameter.origin?.startsWith("modelerfour:synthesized/") ?? true) &&
1516
1484
  !(existParameter.schema instanceof ConstantSchema)) {
1517
1485
  request.parameters.push(cloneOperationParameter(existParameter));
1518
1486
  }
1519
1487
  }
1520
1488
  else {
1521
1489
  // property from anonymous model
1522
- const existBodyProperty = (_e = schema.properties) === null || _e === void 0 ? void 0 : _e.find((it) => it.serializedName === serializedName);
1490
+ const existBodyProperty = schema.properties?.find((it) => it.serializedName === serializedName);
1523
1491
  if (existBodyProperty &&
1524
1492
  !existBodyProperty.readOnly &&
1525
1493
  !(existBodyProperty.schema instanceof ConstantSchema)) {
@@ -1540,7 +1508,6 @@ export class CodeModelBuilder {
1540
1508
  }
1541
1509
  }
1542
1510
  processResponse(op, statusCode, sdkResponse, longRunning, isErrorResponse) {
1543
- var _a, _b;
1544
1511
  // TODO: what to do if more than 1 response?
1545
1512
  // It happens when the response type is Union, on one status code.
1546
1513
  // let response: Response;
@@ -1554,7 +1521,7 @@ export class CodeModelBuilder {
1554
1521
  language: {
1555
1522
  default: {
1556
1523
  name: header.serializedName,
1557
- description: (_a = header.summary) !== null && _a !== void 0 ? _a : header.doc,
1524
+ description: header.summary ?? header.doc,
1558
1525
  },
1559
1526
  },
1560
1527
  }));
@@ -1638,7 +1605,7 @@ export class CodeModelBuilder {
1638
1605
  outputErrorModel = true;
1639
1606
  }
1640
1607
  if (this.isBranded() &&
1641
- !((_b = optionBoolean(this.options["use-default-http-status-code-to-exception-type-mapping"])) !== null && _b !== void 0 ? _b : true)) {
1608
+ !(optionBoolean(this.options["use-default-http-status-code-to-exception-type-mapping"]) ?? true)) {
1642
1609
  outputErrorModel = true;
1643
1610
  }
1644
1611
  if (outputErrorModel) {
@@ -1681,7 +1648,6 @@ export class CodeModelBuilder {
1681
1648
  return this.schemaCache.process(type, nameHint) || fail("Unable to process schema.");
1682
1649
  }
1683
1650
  processSchemaImpl(type, nameHint) {
1684
- var _a, _b, _c;
1685
1651
  if (isSdkBuiltInKind(type.kind)) {
1686
1652
  return this.processBuiltInType(type, nameHint);
1687
1653
  }
@@ -1707,7 +1673,7 @@ export class CodeModelBuilder {
1707
1673
  reportDiagnostic(this.program, {
1708
1674
  code: "unknown-encode",
1709
1675
  format: { encode: type.encode },
1710
- target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
1676
+ target: type.__raw ?? NoTarget,
1711
1677
  });
1712
1678
  return this.processBuiltInType(type.wireType, nameHint);
1713
1679
  }
@@ -1727,7 +1693,7 @@ export class CodeModelBuilder {
1727
1693
  reportDiagnostic(this.program, {
1728
1694
  code: "unknown-encode",
1729
1695
  format: { encode: type.encode },
1730
- target: (_b = type.__raw) !== null && _b !== void 0 ? _b : NoTarget,
1696
+ target: type.__raw ?? NoTarget,
1731
1697
  });
1732
1698
  return this.processBuiltInType(type.wireType, nameHint);
1733
1699
  }
@@ -1736,12 +1702,11 @@ export class CodeModelBuilder {
1736
1702
  const diagnostic = createDiagnostic({
1737
1703
  code: "unrecognized-type",
1738
1704
  format: { typeKind: type.kind },
1739
- target: (_c = type.__raw) !== null && _c !== void 0 ? _c : NoTarget,
1705
+ target: type.__raw ?? NoTarget,
1740
1706
  });
1741
1707
  throw new DiagnosticError(diagnostic);
1742
1708
  }
1743
1709
  processBuiltInType(type, nameHint) {
1744
- var _a;
1745
1710
  nameHint = nameHint || type.kind;
1746
1711
  if (isSdkIntKind(type.kind)) {
1747
1712
  const integerSize = type.kind === "safeint" || type.kind.includes("int64") ? 64 : 32;
@@ -1768,7 +1733,7 @@ export class CodeModelBuilder {
1768
1733
  reportDiagnostic(this.program, {
1769
1734
  code: "unknown-encode",
1770
1735
  format: { encode: type.encode },
1771
- target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
1736
+ target: type.__raw ?? NoTarget,
1772
1737
  });
1773
1738
  return this.processStringSchema(type, nameHint);
1774
1739
  }
@@ -1787,22 +1752,19 @@ export class CodeModelBuilder {
1787
1752
  return this.anySchema;
1788
1753
  }
1789
1754
  processStringSchema(type, name) {
1790
- var _a;
1791
- return this.codeModel.schemas.add(new StringSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1755
+ return this.codeModel.schemas.add(new StringSchema(name, type.doc ?? "", {
1792
1756
  summary: type.summary,
1793
1757
  }));
1794
1758
  }
1795
1759
  processByteArraySchema(type, name) {
1796
- var _a;
1797
1760
  const base64Encoded = type.encode === "base64url";
1798
- return this.codeModel.schemas.add(new ByteArraySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1761
+ return this.codeModel.schemas.add(new ByteArraySchema(name, type.doc ?? "", {
1799
1762
  summary: type.summary,
1800
1763
  format: base64Encoded ? "base64url" : "byte",
1801
1764
  }));
1802
1765
  }
1803
1766
  processIntegerSchema(type, name, precision) {
1804
- var _a;
1805
- const schema = new NumberSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", SchemaType.Integer, precision, {
1767
+ const schema = new NumberSchema(name, type.doc ?? "", SchemaType.Integer, precision, {
1806
1768
  summary: type.summary,
1807
1769
  });
1808
1770
  if (type.encode === "string") {
@@ -1811,26 +1773,22 @@ export class CodeModelBuilder {
1811
1773
  return this.codeModel.schemas.add(schema);
1812
1774
  }
1813
1775
  processNumberSchema(type, name) {
1814
- var _a;
1815
- return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", SchemaType.Number, 64, {
1776
+ return this.codeModel.schemas.add(new NumberSchema(name, type.doc ?? "", SchemaType.Number, 64, {
1816
1777
  summary: type.summary,
1817
1778
  }));
1818
1779
  }
1819
1780
  processDecimalSchema(type, name) {
1820
- var _a;
1821
1781
  // "Infinity" maps to "BigDecimal" in Java
1822
- return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", SchemaType.Number, Infinity, {
1782
+ return this.codeModel.schemas.add(new NumberSchema(name, type.doc ?? "", SchemaType.Number, Infinity, {
1823
1783
  summary: type.summary,
1824
1784
  }));
1825
1785
  }
1826
1786
  processBooleanSchema(type, name) {
1827
- var _a;
1828
- return this.codeModel.schemas.add(new BooleanSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1787
+ return this.codeModel.schemas.add(new BooleanSchema(name, type.doc ?? "", {
1829
1788
  summary: type.summary,
1830
1789
  }));
1831
1790
  }
1832
1791
  processArraySchema(type, name) {
1833
- var _a;
1834
1792
  let nullableItems = false;
1835
1793
  let elementType = type.valueType;
1836
1794
  if (elementType.kind === "nullable") {
@@ -1838,14 +1796,13 @@ export class CodeModelBuilder {
1838
1796
  elementType = elementType.type;
1839
1797
  }
1840
1798
  const elementSchema = this.processSchema(elementType, name);
1841
- return this.codeModel.schemas.add(new ArraySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", elementSchema, {
1799
+ return this.codeModel.schemas.add(new ArraySchema(name, type.doc ?? "", elementSchema, {
1842
1800
  summary: type.summary,
1843
1801
  nullableItems: nullableItems,
1844
1802
  }));
1845
1803
  }
1846
1804
  processDictionarySchema(type, name) {
1847
- var _a;
1848
- const dictSchema = new DictionarySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", null, {
1805
+ const dictSchema = new DictionarySchema(name, type.doc ?? "", null, {
1849
1806
  summary: type.summary,
1850
1807
  });
1851
1808
  // cache this now before we accidentally recurse on this type.
@@ -1864,14 +1821,13 @@ export class CodeModelBuilder {
1864
1821
  return this.codeModel.schemas.add(dictSchema);
1865
1822
  }
1866
1823
  processChoiceSchema(type, name) {
1867
- var _a, _b;
1868
1824
  const rawEnumType = type.__raw;
1869
1825
  const namespace = getNamespace(rawEnumType);
1870
1826
  const valueType = this.processSchema(type.valueType, type.valueType.kind);
1871
1827
  const choices = [];
1872
- type.values.forEach((it) => { var _a, _b; return choices.push(new ChoiceValue(it.name, (_a = it.doc) !== null && _a !== void 0 ? _a : "", (_b = it.value) !== null && _b !== void 0 ? _b : it.name)); });
1828
+ type.values.forEach((it) => choices.push(new ChoiceValue(it.name, it.doc ?? "", it.value ?? it.name)));
1873
1829
  const schemaType = type.isFixed ? SealedChoiceSchema : ChoiceSchema;
1874
- const schema = new schemaType((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
1830
+ const schema = new schemaType(type.name ?? name, type.doc ?? "", {
1875
1831
  summary: type.summary,
1876
1832
  choiceType: valueType,
1877
1833
  choices: choices,
@@ -1888,72 +1844,63 @@ export class CodeModelBuilder {
1888
1844
  return this.codeModel.schemas.add(schema);
1889
1845
  }
1890
1846
  processConstantSchema(type, name) {
1891
- var _a, _b;
1892
1847
  const valueType = this.processSchema(type.valueType, type.valueType.kind);
1893
- return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
1848
+ return this.codeModel.schemas.add(new ConstantSchema(type.name ?? name, type.doc ?? "", {
1894
1849
  summary: type.summary,
1895
1850
  valueType: valueType,
1896
1851
  value: new ConstantValue(type.value),
1897
1852
  }));
1898
1853
  }
1899
1854
  processConstantSchemaFromEnumValue(type, name) {
1900
- var _a, _b, _c;
1901
1855
  const valueType = this.processSchema(type.enumType, type.enumType.name);
1902
- return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
1856
+ return this.codeModel.schemas.add(new ConstantSchema(type.name ?? name, type.doc ?? "", {
1903
1857
  summary: type.summary,
1904
1858
  valueType: valueType,
1905
- value: new ConstantValue((_c = type.value) !== null && _c !== void 0 ? _c : type.name),
1859
+ value: new ConstantValue(type.value ?? type.name),
1906
1860
  }));
1907
1861
  }
1908
1862
  processUnixTimeSchema(type, name) {
1909
- var _a;
1910
- return this.codeModel.schemas.add(new UnixTimeSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1863
+ return this.codeModel.schemas.add(new UnixTimeSchema(name, type.doc ?? "", {
1911
1864
  summary: type.summary,
1912
1865
  }));
1913
1866
  }
1914
1867
  processDateTimeSchema(type, name, rfc1123) {
1915
- var _a;
1916
- return this.codeModel.schemas.add(new DateTimeSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1868
+ return this.codeModel.schemas.add(new DateTimeSchema(name, type.doc ?? "", {
1917
1869
  summary: type.summary,
1918
1870
  format: rfc1123 ? "date-time-rfc1123" : "date-time",
1919
1871
  }));
1920
1872
  }
1921
1873
  processDateSchema(type, name) {
1922
- var _a;
1923
- return this.codeModel.schemas.add(new DateSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1874
+ return this.codeModel.schemas.add(new DateSchema(name, type.doc ?? "", {
1924
1875
  summary: type.summary,
1925
1876
  }));
1926
1877
  }
1927
1878
  processTimeSchema(type, name) {
1928
- var _a;
1929
- return this.codeModel.schemas.add(new TimeSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1879
+ return this.codeModel.schemas.add(new TimeSchema(name, type.doc ?? "", {
1930
1880
  summary: type.summary,
1931
1881
  }));
1932
1882
  }
1933
1883
  processDurationSchema(type, name, format = "duration-rfc3339") {
1934
- var _a;
1935
- return this.codeModel.schemas.add(new DurationSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1884
+ return this.codeModel.schemas.add(new DurationSchema(name, type.doc ?? "", {
1936
1885
  summary: type.summary,
1937
1886
  format: format,
1938
1887
  }));
1939
1888
  }
1940
1889
  processUrlSchema(type, name) {
1941
- var _a;
1942
- return this.codeModel.schemas.add(new UriSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
1890
+ return this.codeModel.schemas.add(new UriSchema(name, type.doc ?? "", {
1943
1891
  summary: type.summary,
1944
1892
  }));
1945
1893
  }
1946
1894
  processObjectSchema(type, name) {
1947
- var _a, _b, _c, _d;
1948
1895
  const rawModelType = type.__raw;
1949
1896
  if (!name && !type.name) {
1950
1897
  reportDiagnostic(this.program, {
1951
1898
  code: "empty-name",
1952
- target: rawModelType !== null && rawModelType !== void 0 ? rawModelType : NoTarget,
1899
+ target: rawModelType ?? NoTarget,
1953
1900
  });
1954
1901
  }
1955
1902
  const namespace = getNamespace(rawModelType);
1956
- const objectSchema = new ObjectSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
1903
+ const objectSchema = new ObjectSchema(type.name ?? name, type.doc ?? "", {
1957
1904
  summary: type.summary,
1958
1905
  language: {
1959
1906
  default: {
@@ -1986,14 +1933,13 @@ export class CodeModelBuilder {
1986
1933
  // therefore, copy all properties from "Error" to this class
1987
1934
  const parentSchema = this.processSchema(type.baseModel, type.baseModel.name);
1988
1935
  if (parentSchema instanceof ObjectSchema) {
1989
- (_c = parentSchema.properties) === null || _c === void 0 ? void 0 : _c.forEach((p) => {
1990
- var _a;
1936
+ parentSchema.properties?.forEach((p) => {
1991
1937
  objectSchema.addProperty(p);
1992
1938
  // improve the casing for Java
1993
1939
  if (p.serializedName === "innererror") {
1994
1940
  p.language.default.name = "innerError";
1995
1941
  if (p.schema instanceof ObjectSchema) {
1996
- (_a = p.schema.properties) === null || _a === void 0 ? void 0 : _a.forEach((innerErrorProperty) => {
1942
+ p.schema.properties?.forEach((innerErrorProperty) => {
1997
1943
  if (innerErrorProperty.serializedName === "innererror") {
1998
1944
  innerErrorProperty.language.default.name = "innerError";
1999
1945
  }
@@ -2040,7 +1986,7 @@ export class CodeModelBuilder {
2040
1986
  decorators: [],
2041
1987
  };
2042
1988
  const parentSchema = this.processSchema(sdkDictType, "Record");
2043
- objectSchema.parents = (_d = objectSchema.parents) !== null && _d !== void 0 ? _d : new Relations();
1989
+ objectSchema.parents = objectSchema.parents ?? new Relations();
2044
1990
  objectSchema.parents.immediate.push(parentSchema);
2045
1991
  pushDistinct(objectSchema.parents.all, parentSchema);
2046
1992
  objectSchema.discriminatorValue = type.discriminatorValue;
@@ -2054,7 +2000,6 @@ export class CodeModelBuilder {
2054
2000
  return objectSchema;
2055
2001
  }
2056
2002
  processModelProperty(prop) {
2057
- var _a, _b;
2058
2003
  let nullable = false;
2059
2004
  let nonNullType = prop.type;
2060
2005
  if (nonNullType.kind === "nullable") {
@@ -2064,22 +2009,22 @@ export class CodeModelBuilder {
2064
2009
  let schema;
2065
2010
  let extensions = undefined;
2066
2011
  if (this.isSecret(prop)) {
2067
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
2012
+ extensions = extensions ?? {};
2068
2013
  extensions["x-ms-secret"] = true;
2069
2014
  // if the property does not return in response, it had to be nullable
2070
2015
  nullable = true;
2071
2016
  }
2072
2017
  if (prop.kind === "property" && prop.flatten) {
2073
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
2018
+ extensions = extensions ?? {};
2074
2019
  extensions["x-ms-client-flatten"] = true;
2075
2020
  }
2076
2021
  const mutability = this.getMutability(prop);
2077
2022
  if (mutability) {
2078
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
2023
+ extensions = extensions ?? {};
2079
2024
  extensions["x-ms-mutability"] = mutability;
2080
2025
  }
2081
2026
  if (prop.kind === "property" && prop.serializationOptions.multipart) {
2082
- if ((_a = prop.serializationOptions.multipart) === null || _a === void 0 ? void 0 : _a.isFilePart) {
2027
+ if (prop.serializationOptions.multipart?.isFilePart) {
2083
2028
  schema = this.processMultipartFormDataFilePropertySchema(prop);
2084
2029
  }
2085
2030
  else if (prop.type.kind === "model" &&
@@ -2094,7 +2039,7 @@ export class CodeModelBuilder {
2094
2039
  else {
2095
2040
  schema = this.processSchema(nonNullType, "");
2096
2041
  }
2097
- return new Property(prop.name, (_b = prop.doc) !== null && _b !== void 0 ? _b : "", schema, {
2042
+ return new Property(prop.name, prop.doc ?? "", schema, {
2098
2043
  summary: prop.summary,
2099
2044
  required: !prop.optional,
2100
2045
  nullable: nullable,
@@ -2104,30 +2049,28 @@ export class CodeModelBuilder {
2104
2049
  });
2105
2050
  }
2106
2051
  processUnionSchema(type, name) {
2107
- var _a, _b, _c;
2108
2052
  if (!(type.__raw && type.__raw.kind === "Union")) {
2109
2053
  reportDiagnostic(this.program, {
2110
2054
  code: "unrecognized-type",
2111
2055
  messageId: "unionType",
2112
2056
  format: { typeKind: type.kind },
2113
- target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
2057
+ target: type.__raw ?? NoTarget,
2114
2058
  });
2115
2059
  }
2116
2060
  const rawUnionType = type.__raw;
2117
2061
  const namespace = getNamespace(rawUnionType);
2118
- const baseName = (_b = type.name) !== null && _b !== void 0 ? _b : pascalCase(name) + "Model";
2062
+ const baseName = type.name ?? pascalCase(name) + "Model";
2119
2063
  this.trace(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
2120
- const unionSchema = new OrSchema(baseName + "Base", (_c = type.doc) !== null && _c !== void 0 ? _c : "", {
2064
+ const unionSchema = new OrSchema(baseName + "Base", type.doc ?? "", {
2121
2065
  summary: type.summary,
2122
2066
  });
2123
2067
  unionSchema.anyOf = [];
2124
2068
  type.variantTypes.forEach((it) => {
2125
- var _a, _b;
2126
2069
  const variantName = this.getUnionVariantName(it.__raw, { depth: 0 });
2127
2070
  const modelName = variantName + baseName;
2128
2071
  const propertyName = "value";
2129
2072
  // these ObjectSchema is not added to codeModel.schemas
2130
- const objectSchema = new ObjectSchema(modelName, (_a = it.doc) !== null && _a !== void 0 ? _a : "", {
2073
+ const objectSchema = new ObjectSchema(modelName, it.doc ?? "", {
2131
2074
  summary: it.summary,
2132
2075
  language: {
2133
2076
  default: {
@@ -2139,7 +2082,7 @@ export class CodeModelBuilder {
2139
2082
  },
2140
2083
  });
2141
2084
  const variantSchema = this.processSchema(it, variantName);
2142
- objectSchema.addProperty(new Property(propertyName, (_b = type.doc) !== null && _b !== void 0 ? _b : "", variantSchema, {
2085
+ objectSchema.addProperty(new Property(propertyName, type.doc ?? "", variantSchema, {
2143
2086
  summary: type.summary,
2144
2087
  required: true,
2145
2088
  readOnly: false,
@@ -2149,13 +2092,11 @@ export class CodeModelBuilder {
2149
2092
  return this.codeModel.schemas.add(unionSchema);
2150
2093
  }
2151
2094
  processBinarySchema(type) {
2152
- var _a;
2153
- return this.codeModel.schemas.add(new BinarySchema((_a = type.doc) !== null && _a !== void 0 ? _a : "", {
2095
+ return this.codeModel.schemas.add(new BinarySchema(type.doc ?? "", {
2154
2096
  summary: type.summary,
2155
2097
  }));
2156
2098
  }
2157
2099
  getUnionVariantName(type, option) {
2158
- var _a, _b;
2159
2100
  if (type === undefined) {
2160
2101
  this.trace("Union variant type is undefined.");
2161
2102
  return "UnionVariant";
@@ -2211,20 +2152,18 @@ export class CodeModelBuilder {
2211
2152
  case "Boolean":
2212
2153
  return pascalCase(type.value ? "True" : "False");
2213
2154
  case "Union":
2214
- return (_a = type.name) !== null && _a !== void 0 ? _a : "Union";
2155
+ return type.name ?? "Union";
2215
2156
  case "UnionVariant":
2216
- return (_b = (typeof type.name === "string" ? type.name : undefined)) !== null && _b !== void 0 ? _b : "UnionVariant";
2157
+ return (typeof type.name === "string" ? type.name : undefined) ?? "UnionVariant";
2217
2158
  default:
2218
2159
  this.trace(`Unrecognized type for union variable: '${type.kind}'.`);
2219
2160
  return "UnionVariant";
2220
2161
  }
2221
2162
  }
2222
2163
  processMultipartFormDataFilePropertySchema(property) {
2223
- var _a, _b;
2224
2164
  const processSchemaFunc = (type) => this.processSchema(type, "");
2225
2165
  const processNamespaceFunc = (type) => {
2226
- var _a;
2227
- const namespace = type.kind === "model" ? ((_a = getNamespace(type.__raw)) !== null && _a !== void 0 ? _a : this.namespace) : this.namespace;
2166
+ const namespace = type.kind === "model" ? (getNamespace(type.__raw) ?? this.namespace) : this.namespace;
2228
2167
  const javaNamespace = type.kind === "model" ? this.getJavaNamespace(type) : this.getJavaNamespace();
2229
2168
  return { namespace, javaNamespace };
2230
2169
  };
@@ -2235,7 +2174,7 @@ export class CodeModelBuilder {
2235
2174
  else if (property.type.kind === "array" &&
2236
2175
  (property.type.valueType.kind === "bytes" || property.type.valueType.kind === "model")) {
2237
2176
  const namespaceTuple = processNamespaceFunc(property.type.valueType);
2238
- return new ArraySchema(property.name, (_a = property.doc) !== null && _a !== void 0 ? _a : "", getFileDetailsSchema(property, namespaceTuple.namespace, namespaceTuple.javaNamespace, this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc), {
2177
+ return new ArraySchema(property.name, property.doc ?? "", getFileDetailsSchema(property, namespaceTuple.namespace, namespaceTuple.javaNamespace, this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc), {
2239
2178
  summary: property.summary,
2240
2179
  });
2241
2180
  }
@@ -2244,7 +2183,7 @@ export class CodeModelBuilder {
2244
2183
  code: "unrecognized-type",
2245
2184
  messageId: "multipartFormData",
2246
2185
  format: { typeKind: property.type.kind },
2247
- target: (_b = property.type.__raw) !== null && _b !== void 0 ? _b : NoTarget,
2186
+ target: property.type.__raw ?? NoTarget,
2248
2187
  });
2249
2188
  throw new DiagnosticError(diagnostic);
2250
2189
  }
@@ -2334,7 +2273,7 @@ export class CodeModelBuilder {
2334
2273
  }
2335
2274
  getJavaNamespace(type = undefined) {
2336
2275
  // clientNamespace from TCGC
2337
- const clientNamespace = type === null || type === void 0 ? void 0 : type.namespace;
2276
+ const clientNamespace = type?.namespace;
2338
2277
  // we still keep the mapping of models from TypeSpec namespace and Azure namespace to "baseJavaNamespace"
2339
2278
  if (type) {
2340
2279
  const crossLanguageDefinitionId = type.crossLanguageDefinitionId;
@@ -2407,33 +2346,39 @@ export class CodeModelBuilder {
2407
2346
  trace(msg) {
2408
2347
  trace(this.program, msg);
2409
2348
  }
2349
+ _stringSchema;
2410
2350
  get stringSchema() {
2411
2351
  return (this._stringSchema ||
2412
2352
  (this._stringSchema = this.codeModel.schemas.add(new StringSchema("string", "simple string"))));
2413
2353
  }
2354
+ _integerSchema;
2414
2355
  get integerSchema() {
2415
2356
  return (this._integerSchema ||
2416
2357
  (this._integerSchema = this.codeModel.schemas.add(new NumberSchema("integer", "simple integer", SchemaType.Integer, 64))));
2417
2358
  }
2359
+ _doubleSchema;
2418
2360
  get doubleSchema() {
2419
2361
  return (this._doubleSchema ||
2420
2362
  (this._doubleSchema = this.codeModel.schemas.add(new NumberSchema("double", "simple float", SchemaType.Number, 64))));
2421
2363
  }
2364
+ _booleanSchema;
2422
2365
  get booleanSchema() {
2423
2366
  return (this._booleanSchema ||
2424
2367
  (this._booleanSchema = this.codeModel.schemas.add(new BooleanSchema("boolean", "simple boolean"))));
2425
2368
  }
2369
+ _anySchema;
2426
2370
  get anySchema() {
2427
- var _a;
2428
- return ((_a = this._anySchema) !== null && _a !== void 0 ? _a : (this._anySchema = this.codeModel.schemas.add(new AnySchema("Anything"))));
2371
+ return (this._anySchema ?? (this._anySchema = this.codeModel.schemas.add(new AnySchema("Anything"))));
2429
2372
  }
2373
+ _binarySchema;
2430
2374
  get binarySchema() {
2431
2375
  return (this._binarySchema ||
2432
2376
  (this._binarySchema = this.codeModel.schemas.add(new BinarySchema("simple binary"))));
2433
2377
  }
2378
+ _pollResultSchema;
2434
2379
  get pollResultSchema() {
2435
- var _a;
2436
- return ((_a = this._pollResultSchema) !== null && _a !== void 0 ? _a : (this._pollResultSchema = createPollOperationDetailsSchema(this.codeModel.schemas, this.stringSchema)));
2380
+ return (this._pollResultSchema ??
2381
+ (this._pollResultSchema = createPollOperationDetailsSchema(this.codeModel.schemas, this.stringSchema)));
2437
2382
  }
2438
2383
  createApiVersionParameter(serializedName, parameterLocation, value = "") {
2439
2384
  return new Parameter(serializedName, "Version parameter", this.codeModel.schemas.add(new ConstantSchema(serializedName, "API Version", {
@@ -2456,6 +2401,10 @@ export class CodeModelBuilder {
2456
2401
  isApiVersionParameter(param) {
2457
2402
  return param.isApiVersionParam;
2458
2403
  }
2404
+ _apiVersionParameter;
2405
+ _apiVersionParameterInPath;
2406
+ _apiVersionParameterInHeader;
2407
+ _armApiVersionParameter;
2459
2408
  getApiVersionParameter(param) {
2460
2409
  // apiVersionParameter is cached by param.kind
2461
2410
  // we didn't expect Azure service have more than 1 type of api-version, and certainly not more than 1 of each kind.
@@ -2494,15 +2443,14 @@ export class CodeModelBuilder {
2494
2443
  }
2495
2444
  return this._subscriptionParameter;
2496
2445
  }
2446
+ _subscriptionParameter;
2497
2447
  propagateSchemaUsage(schema) {
2498
- var _a, _b, _c, _d;
2499
2448
  const processedSchemas = new Set();
2500
2449
  const innerApplySchemaUsage = (schema, schemaUsage) => {
2501
2450
  this.trackSchemaUsage(schema, schemaUsage);
2502
2451
  innerPropagateSchemaUsage(schema, schemaUsage);
2503
2452
  };
2504
2453
  const innerPropagateSchemaUsage = (schema, schemaUsage) => {
2505
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2506
2454
  if (processedSchemas.has(schema)) {
2507
2455
  return;
2508
2456
  }
@@ -2518,9 +2466,8 @@ export class CodeModelBuilder {
2518
2466
  }
2519
2467
  if (schemaUsage.usage || schemaUsage.serializationFormats) {
2520
2468
  if (!skipPropergateProperties) {
2521
- (_a = schema.properties) === null || _a === void 0 ? void 0 : _a.forEach((p) => {
2522
- var _a;
2523
- if (p.readOnly && ((_a = schemaUsage.usage) === null || _a === void 0 ? void 0 : _a.includes(SchemaContext.Input))) {
2469
+ schema.properties?.forEach((p) => {
2470
+ if (p.readOnly && schemaUsage.usage?.includes(SchemaContext.Input)) {
2524
2471
  const schemaUsageWithoutInput = {
2525
2472
  usage: schemaUsage.usage.filter((it) => it !== SchemaContext.Input),
2526
2473
  serializationFormats: schemaUsage.serializationFormats,
@@ -2533,16 +2480,16 @@ export class CodeModelBuilder {
2533
2480
  });
2534
2481
  }
2535
2482
  if (schema instanceof ObjectSchema) {
2536
- (_c = (_b = schema.parents) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.forEach((p) => innerApplySchemaUsage(p, schemaUsage));
2537
- (_e = (_d = schema.parents) === null || _d === void 0 ? void 0 : _d.immediate) === null || _e === void 0 ? void 0 : _e.forEach((p) => innerApplySchemaUsage(p, schemaUsage));
2483
+ schema.parents?.all?.forEach((p) => innerApplySchemaUsage(p, schemaUsage));
2484
+ schema.parents?.immediate?.forEach((p) => innerApplySchemaUsage(p, schemaUsage));
2538
2485
  if (schema.discriminator) {
2539
2486
  // propagate access/usage to immediate children, if the schema is a discriminated model
2540
2487
  // if the schema is not a discriminated model, its children likely not valid for the mode/API
2541
2488
  // TODO: it does not handle the case that concrete model (kind: "type1") for the discriminated model have depth larger than 1 (e.g. kind: "type1" | "type2" in middle)
2542
- (_g = (_f = schema.children) === null || _f === void 0 ? void 0 : _f.immediate) === null || _g === void 0 ? void 0 : _g.forEach((c) => innerApplySchemaUsage(c, schemaUsage));
2489
+ schema.children?.immediate?.forEach((c) => innerApplySchemaUsage(c, schemaUsage));
2543
2490
  }
2544
- if ((_j = (_h = schema.discriminator) === null || _h === void 0 ? void 0 : _h.property) === null || _j === void 0 ? void 0 : _j.schema) {
2545
- innerApplySchemaUsage((_l = (_k = schema.discriminator) === null || _k === void 0 ? void 0 : _k.property) === null || _l === void 0 ? void 0 : _l.schema, schemaUsage);
2491
+ if (schema.discriminator?.property?.schema) {
2492
+ innerApplySchemaUsage(schema.discriminator?.property?.schema, schemaUsage);
2546
2493
  }
2547
2494
  }
2548
2495
  }
@@ -2554,25 +2501,25 @@ export class CodeModelBuilder {
2554
2501
  innerApplySchemaUsage(schema.elementType, schemaUsage);
2555
2502
  }
2556
2503
  else if (schema instanceof OrSchema) {
2557
- (_m = schema.anyOf) === null || _m === void 0 ? void 0 : _m.forEach((it) => innerApplySchemaUsage(it, schemaUsage));
2504
+ schema.anyOf?.forEach((it) => innerApplySchemaUsage(it, schemaUsage));
2558
2505
  }
2559
2506
  else if (schema instanceof ConstantSchema) {
2560
2507
  innerApplySchemaUsage(schema.valueType, schemaUsage);
2561
2508
  }
2562
2509
  };
2563
2510
  // Exclude context that not to be propagated
2564
- const updatedSchemaUsage = (_a = schema.usage) === null || _a === void 0 ? void 0 : _a.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.PublicSpread);
2565
- const indexSpread = (_b = schema.usage) === null || _b === void 0 ? void 0 : _b.indexOf(SchemaContext.PublicSpread);
2511
+ const updatedSchemaUsage = schema.usage?.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.PublicSpread);
2512
+ const indexSpread = schema.usage?.indexOf(SchemaContext.PublicSpread);
2566
2513
  if (updatedSchemaUsage &&
2567
2514
  indexSpread &&
2568
2515
  indexSpread >= 0 &&
2569
- !((_c = schema.usage) === null || _c === void 0 ? void 0 : _c.includes(SchemaContext.Public))) {
2516
+ !schema.usage?.includes(SchemaContext.Public)) {
2570
2517
  // Propagate Public, if schema is PublicSpread
2571
2518
  updatedSchemaUsage.push(SchemaContext.Public);
2572
2519
  }
2573
2520
  const schemaUsage = {
2574
2521
  usage: updatedSchemaUsage,
2575
- serializationFormats: (_d = schema.serializationFormats) === null || _d === void 0 ? void 0 : _d.filter((it) => it !== KnownMediaType.Multipart),
2522
+ serializationFormats: schema.serializationFormats?.filter((it) => it !== KnownMediaType.Multipart),
2576
2523
  };
2577
2524
  // Propagate the usage of the initial schema itself
2578
2525
  innerPropagateSchemaUsage(schema, schemaUsage);