@azure-tools/typespec-java 0.31.4 → 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 +178 -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 +5 -0
  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 +15 -13
@@ -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;
@@ -367,7 +368,7 @@ export class CodeModelBuilder {
367
368
  clientName = this.options["service-name"].replace(/\s+/g, "") + "ManagementClient";
368
369
  }
369
370
  }
370
- const codeModelClient = new CodeModelClient(clientName, (_a = client.doc) !== null && _a !== void 0 ? _a : "", {
371
+ const codeModelClient = new CodeModelClient(clientName, client.doc ?? "", {
371
372
  summary: client.summary,
372
373
  language: {
373
374
  default: {
@@ -408,7 +409,6 @@ export class CodeModelBuilder {
408
409
  let baseUri = "{endpoint}";
409
410
  let hostParameters = [];
410
411
  client.clientInitialization.parameters.forEach((initializationProperty) => {
411
- var _a;
412
412
  if (initializationProperty.kind === "endpoint") {
413
413
  let sdkPathParameters = [];
414
414
  if (initializationProperty.type.kind === "union") {
@@ -424,7 +424,7 @@ export class CodeModelBuilder {
424
424
  else if (initializationProperty.type.variantTypes.length > 2) {
425
425
  reportDiagnostic(this.program, {
426
426
  code: "multiple-server-not-supported",
427
- target: (_a = initializationProperty.type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
427
+ target: initializationProperty.type.__raw ?? NoTarget,
428
428
  });
429
429
  }
430
430
  }
@@ -437,7 +437,7 @@ export class CodeModelBuilder {
437
437
  }
438
438
  });
439
439
  const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters, codeModelClient.apiVersions);
440
- const enableSubclient = (_b = optionBoolean(this.options["enable-subclient"])) !== null && _b !== void 0 ? _b : false;
440
+ const enableSubclient = optionBoolean(this.options["enable-subclient"]) ?? false;
441
441
  // preprocess operation groups and operations
442
442
  // operations without operation group
443
443
  const serviceMethodsWithoutSubClient = client.methods;
@@ -448,7 +448,7 @@ export class CodeModelBuilder {
448
448
  codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, ""));
449
449
  }
450
450
  }
451
- if (((_c = codeModelGroup.operations) === null || _c === void 0 ? void 0 : _c.length) > 0 || enableSubclient) {
451
+ if (codeModelGroup.operations?.length > 0 || enableSubclient) {
452
452
  codeModelClient.operationGroups.push(codeModelGroup);
453
453
  }
454
454
  const subClients = this.listSubClientsUnderClient(client, !enableSubclient);
@@ -553,11 +553,9 @@ export class CodeModelBuilder {
553
553
  * Whether we support advanced versioning in non-breaking fashion.
554
554
  */
555
555
  supportsAdvancedVersioning() {
556
- var _a;
557
- return (_a = optionBoolean(this.options["advanced-versioning"])) !== null && _a !== void 0 ? _a : false;
556
+ return optionBoolean(this.options["advanced-versioning"]) ?? false;
558
557
  }
559
558
  getOperationExample(sdkMethod) {
560
- var _a, _b;
561
559
  const httpOperationExamples = sdkMethod.operation.examples;
562
560
  if (httpOperationExamples && httpOperationExamples.length > 0) {
563
561
  const operationExamples = {};
@@ -566,7 +564,7 @@ export class CodeModelBuilder {
566
564
  // example.filePath is relative path from sdkContext.examplesDir
567
565
  // this is not a URL format (file:// or https://)
568
566
  operationExample["x-ms-original-file"] = example.filePath;
569
- 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;
570
568
  }
571
569
  return operationExamples;
572
570
  }
@@ -575,12 +573,11 @@ export class CodeModelBuilder {
575
573
  }
576
574
  }
577
575
  processOperation(sdkMethod, clientContext, groupName) {
578
- var _a, _b, _c, _d;
579
576
  const operationName = sdkMethod.name;
580
577
  const httpOperation = sdkMethod.operation;
581
578
  const operationId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
582
579
  const operationExamples = this.getOperationExample(sdkMethod);
583
- const codeModelOperation = new CodeModelOperation(operationName, (_a = sdkMethod.doc) !== null && _a !== void 0 ? _a : "", {
580
+ const codeModelOperation = new CodeModelOperation(operationName, sdkMethod.doc ?? "", {
584
581
  operationId: operationId,
585
582
  summary: sdkMethod.summary,
586
583
  extensions: {
@@ -603,7 +600,7 @@ export class CodeModelBuilder {
603
600
  code: "protocol-api-not-generated",
604
601
  messageId: "multipartFormData",
605
602
  format: { operationName: operationName },
606
- target: (_b = sdkMethod.__raw) !== null && _b !== void 0 ? _b : NoTarget,
603
+ target: sdkMethod.__raw ?? NoTarget,
607
604
  });
608
605
  this.program.reportDiagnostic(diagnostic);
609
606
  }
@@ -615,7 +612,7 @@ export class CodeModelBuilder {
615
612
  code: "convenience-api-not-generated",
616
613
  messageId: "multipleContentType",
617
614
  format: { operationName: operationName },
618
- target: (_c = sdkMethod.__raw) !== null && _c !== void 0 ? _c : NoTarget,
615
+ target: sdkMethod.__raw ?? NoTarget,
619
616
  });
620
617
  this.program.reportDiagnostic(diagnostic);
621
618
  }
@@ -627,7 +624,7 @@ export class CodeModelBuilder {
627
624
  code: "convenience-api-not-generated",
628
625
  messageId: "jsonMergePatch",
629
626
  format: { operationName: operationName },
630
- target: (_d = sdkMethod.__raw) !== null && _d !== void 0 ? _d : NoTarget,
627
+ target: sdkMethod.__raw ?? NoTarget,
631
628
  });
632
629
  this.program.reportDiagnostic(diagnostic);
633
630
  }
@@ -703,7 +700,6 @@ export class CodeModelBuilder {
703
700
  return codeModelOperation;
704
701
  }
705
702
  processRouteForPaged(op, sdkMethod) {
706
- var _a, _b, _c, _d;
707
703
  if (sdkMethod.kind !== "paging" && sdkMethod.kind !== "lropaging") {
708
704
  return;
709
705
  }
@@ -717,49 +713,46 @@ export class CodeModelBuilder {
717
713
  if (!bodyType || bodyType.kind !== "model") {
718
714
  return;
719
715
  }
720
- (_a = op.responses) === null || _a === void 0 ? void 0 : _a.forEach((r) => {
716
+ op.responses?.forEach((r) => {
721
717
  if (r instanceof SchemaResponse) {
722
718
  this.trackSchemaUsage(r.schema, { usage: [SchemaContext.Paged] });
723
719
  }
724
720
  });
725
- function getLastPropertySegment(segments) {
726
- if (segments) {
727
- const lastSegment = segments[segments.length - 1];
728
- if (lastSegment.kind === "property") {
729
- return lastSegment;
730
- }
731
- }
732
- return undefined;
733
- }
734
721
  function getLastSegment(segments) {
735
722
  if (segments) {
736
723
  return segments[segments.length - 1];
737
724
  }
738
725
  return undefined;
739
726
  }
740
- function getLastSegmentSerializedName(segments) {
741
- const lastSegment = getLastPropertySegment(segments);
742
- return lastSegment ? getPropertySerializedName(lastSegment) : undefined;
743
- }
744
- // TODO: in future the property could be nested, so that the "itemSegments" or "nextLinkSegments" would contain more than 1 element
745
- // item/result
746
- // "itemsSegments" should exist for "paging"/"lropaging"
747
- 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;
748
734
  // nextLink
749
- 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;
750
741
  // continuationToken
751
742
  let continuationTokenParameter;
752
743
  let continuationTokenResponseProperty;
753
744
  let continuationTokenResponseHeader;
754
745
  if (!this.isBranded()) {
746
+ // parameter would either be query or header parameter, so taking the last segment would be enough
755
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
756
749
  const continuationTokenResponseSegment = getLastSegment(sdkMethod.pagingMetadata.continuationTokenResponseSegments);
757
750
  if (continuationTokenParameterSegment && op.parameters) {
758
751
  // for now, continuationToken is either request query or header parameter
759
752
  const parameter = getHttpOperationParameter(sdkMethod, continuationTokenParameterSegment);
760
753
  if (parameter) {
761
754
  for (const param of op.parameters) {
762
- if (((_b = param.protocol.http) === null || _b === void 0 ? void 0 : _b.in) === parameter.kind) {
755
+ if (param.protocol.http?.in === parameter.kind) {
763
756
  if (parameter.kind === "header" &&
764
757
  param.language.default.serializedName.toLowerCase() ===
765
758
  parameter.serializedName.toLowerCase()) {
@@ -776,7 +769,7 @@ export class CodeModelBuilder {
776
769
  }
777
770
  }
778
771
  if (continuationTokenResponseSegment && op.responses) {
779
- if ((continuationTokenResponseSegment === null || continuationTokenResponseSegment === void 0 ? void 0 : continuationTokenResponseSegment.kind) === "responseheader") {
772
+ if (continuationTokenResponseSegment?.kind === "responseheader") {
780
773
  // continuationToken is response header
781
774
  for (const response of op.responses) {
782
775
  if (response instanceof SchemaResponse && response.protocol.http) {
@@ -793,25 +786,8 @@ export class CodeModelBuilder {
793
786
  }
794
787
  }
795
788
  }
796
- else if ((continuationTokenResponseSegment === null || continuationTokenResponseSegment === void 0 ? void 0 : continuationTokenResponseSegment.kind) === "property") {
797
- // continuationToken is response body property
798
- // TODO: the property could be nested
799
- for (const response of op.responses) {
800
- if (response instanceof SchemaResponse &&
801
- response.schema instanceof ObjectSchema &&
802
- response.schema.properties) {
803
- for (const property of response.schema.properties) {
804
- if (property.serializedName ===
805
- getPropertySerializedName(continuationTokenResponseSegment)) {
806
- continuationTokenResponseProperty = [property];
807
- break;
808
- }
809
- }
810
- }
811
- if (continuationTokenResponseProperty) {
812
- break;
813
- }
814
- }
789
+ else if (continuationTokenResponseSegment?.kind === "property") {
790
+ continuationTokenResponseProperty = findResponsePropertySegments(op, sdkMethod.pagingMetadata.continuationTokenResponseSegments);
815
791
  }
816
792
  }
817
793
  }
@@ -830,7 +806,7 @@ export class CodeModelBuilder {
830
806
  if (parameter) {
831
807
  // find the corresponding parameter in the code model operation
832
808
  for (const opParam of op.parameters) {
833
- if (((_c = opParam.protocol.http) === null || _c === void 0 ? void 0 : _c.in) === parameter.kind &&
809
+ if (opParam.protocol.http?.in === parameter.kind &&
834
810
  opParam.language.default.serializedName === parameter.serializedName) {
835
811
  nextLinkReInjectedParameters.push(opParam);
836
812
  break;
@@ -841,10 +817,14 @@ export class CodeModelBuilder {
841
817
  }
842
818
  }
843
819
  }
844
- op.extensions = (_d = op.extensions) !== null && _d !== void 0 ? _d : {};
820
+ op.extensions = op.extensions ?? {};
845
821
  op.extensions["x-ms-pageable"] = {
822
+ // this part need to be compatible with modelerfour
846
823
  itemName: itemSerializedName,
847
824
  nextLinkName: nextLinkSerializedName,
825
+ // this part is only available in TypeSpec
826
+ pageItemsProperty: pageItemsResponseProperty,
827
+ nextLinkProperty: nextLinkResponseProperty,
848
828
  continuationToken: continuationTokenParameter
849
829
  ? new PageableContinuationToken(continuationTokenParameter, continuationTokenResponseProperty, continuationTokenResponseHeader)
850
830
  : undefined,
@@ -926,15 +906,13 @@ export class CodeModelBuilder {
926
906
  return new LongRunningMetadata(false);
927
907
  }
928
908
  processRouteForLongRunning(op, lroMetadata) {
929
- var _a;
930
909
  if (lroMetadata.longRunning) {
931
- op.extensions = (_a = op.extensions) !== null && _a !== void 0 ? _a : {};
910
+ op.extensions = op.extensions ?? {};
932
911
  op.extensions["x-ms-long-running-operation"] = true;
933
912
  return;
934
913
  }
935
914
  }
936
915
  processParameter(op, param, clientContext) {
937
- var _a, _b, _c;
938
916
  if (clientContext.apiVersions && this.isApiVersionParameter(param) && param.kind !== "cookie") {
939
917
  // pre-condition for "isApiVersion": the client supports ApiVersions
940
918
  if (this.isArm()) {
@@ -961,7 +939,7 @@ export class CodeModelBuilder {
961
939
  else if (param.kind === "header" &&
962
940
  SPECIAL_HEADER_NAMES.has(param.serializedName.toLowerCase())) {
963
941
  // special headers
964
- op.specialHeaders = (_a = op.specialHeaders) !== null && _a !== void 0 ? _a : [];
942
+ op.specialHeaders = op.specialHeaders ?? [];
965
943
  if (!stringArrayContainsIgnoreCase(op.specialHeaders, param.serializedName)) {
966
944
  op.specialHeaders.push(param.serializedName);
967
945
  }
@@ -973,7 +951,7 @@ export class CodeModelBuilder {
973
951
  let extensions = undefined;
974
952
  if (param.kind === "path") {
975
953
  if (param.allowReserved) {
976
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
954
+ extensions = extensions ?? {};
977
955
  extensions["x-ms-skip-url-encoding"] = true;
978
956
  }
979
957
  }
@@ -981,14 +959,14 @@ export class CodeModelBuilder {
981
959
  if ((param.kind === "query" || param.kind === "path") &&
982
960
  isSdkBuiltInKind(sdkType.kind) &&
983
961
  schema instanceof UriSchema) {
984
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
962
+ extensions = extensions ?? {};
985
963
  extensions["x-ms-skip-url-encoding"] = true;
986
964
  }
987
965
  if (this.supportsAdvancedVersioning() && param.__raw) {
988
966
  // versioning
989
967
  const addedOn = getAddedOnVersions(this.program, param.__raw);
990
968
  if (addedOn) {
991
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
969
+ extensions = extensions ?? {};
992
970
  extensions["x-ms-versioning-added"] = clientContext.getAddedVersions(addedOn);
993
971
  }
994
972
  }
@@ -1034,7 +1012,7 @@ export class CodeModelBuilder {
1034
1012
  reportDiagnostic(this.program, {
1035
1013
  code: "header-parameter-format-not-supported",
1036
1014
  format: { format: format },
1037
- target: (_b = param.__raw) !== null && _b !== void 0 ? _b : NoTarget,
1015
+ target: param.__raw ?? NoTarget,
1038
1016
  });
1039
1017
  }
1040
1018
  break;
@@ -1050,7 +1028,7 @@ export class CodeModelBuilder {
1050
1028
  }
1051
1029
  }
1052
1030
  const nullable = param.type.kind === "nullable";
1053
- const parameter = new Parameter(parameterName, (_c = param.doc) !== null && _c !== void 0 ? _c : "", schema, {
1031
+ const parameter = new Parameter(parameterName, param.doc ?? "", schema, {
1054
1032
  summary: param.summary,
1055
1033
  implementation: parameterOnClient
1056
1034
  ? ImplementationLocation.Client
@@ -1102,9 +1080,8 @@ export class CodeModelBuilder {
1102
1080
  }
1103
1081
  }
1104
1082
  processSdkMethodOverride(op, sdkMethod) {
1105
- var _a, _b, _c;
1106
1083
  // method be called, only if "op.convenienceApi"
1107
- 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];
1108
1085
  let requestParameters;
1109
1086
  if (request) {
1110
1087
  requestParameters = request.parameters;
@@ -1125,7 +1102,7 @@ export class CodeModelBuilder {
1125
1102
  if (parameter.type.kind !== "constant") {
1126
1103
  if (parameter.kind === "body") {
1127
1104
  // there should be only 1 body parameter
1128
- 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");
1129
1106
  }
1130
1107
  else if (parameter.kind === "property") {
1131
1108
  // body property
@@ -1135,11 +1112,8 @@ export class CodeModelBuilder {
1135
1112
  }
1136
1113
  else {
1137
1114
  // query, path, header
1138
- opParameter = requestParameters.find((it) => {
1139
- var _a;
1140
- return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === parameter.kind &&
1141
- it.language.default.serializedName === parameter.serializedName;
1142
- });
1115
+ opParameter = requestParameters.find((it) => it.protocol.http?.in === parameter.kind &&
1116
+ it.language.default.serializedName === parameter.serializedName);
1143
1117
  }
1144
1118
  }
1145
1119
  return opParameter;
@@ -1180,7 +1154,7 @@ export class CodeModelBuilder {
1180
1154
  });
1181
1155
  }
1182
1156
  // group parameter
1183
- 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, {
1184
1158
  summary: sdkMethodParameter.summary,
1185
1159
  implementation: ImplementationLocation.Method,
1186
1160
  required: !sdkMethodParameter.optional,
@@ -1198,13 +1172,12 @@ export class CodeModelBuilder {
1198
1172
  }
1199
1173
  processGroupSchema(type, parameters, name, description = undefined) {
1200
1174
  // the "GroupSchema" is simliar to "ObjectSchema", but the process is different
1201
- var _a, _b;
1202
1175
  if (type && this.schemaCache.has(type)) {
1203
1176
  return this.schemaCache.get(type);
1204
1177
  }
1205
1178
  // option bag schema
1206
- 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 : "", {
1207
- 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,
1208
1181
  language: {
1209
1182
  default: {
1210
1183
  namespace: type ? getNamespace(type.__raw) : this.namespace,
@@ -1231,10 +1204,9 @@ export class CodeModelBuilder {
1231
1204
  return optionBagSchema;
1232
1205
  }
1233
1206
  checkGroupingAfterBodyParameterFlatten(op) {
1234
- var _a, _b;
1235
1207
  // method be called, only if "op.convenienceApi" is defined
1236
1208
  // method signature of the convenience API after body parameter flatten
1237
- 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];
1238
1210
  if (request &&
1239
1211
  request.signatureParameters &&
1240
1212
  request.parameters &&
@@ -1260,7 +1232,6 @@ export class CodeModelBuilder {
1260
1232
  }
1261
1233
  }
1262
1234
  processEtagHeaderParameters(op, httpOperation) {
1263
- var _a, _b;
1264
1235
  if (op.convenienceApi && op.parameters && op.signatureParameters) {
1265
1236
  const etagHeadersNames = new Set([
1266
1237
  "if-match",
@@ -1294,7 +1265,7 @@ export class CodeModelBuilder {
1294
1265
  }
1295
1266
  if (groupToRequestConditions || groupToMatchConditions) {
1296
1267
  // method be called, only if "op.convenienceApi"
1297
- 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];
1298
1269
  let requestParameters;
1299
1270
  let requestSignatureParameters;
1300
1271
  if (request) {
@@ -1389,7 +1360,6 @@ export class CodeModelBuilder {
1389
1360
  }
1390
1361
  }
1391
1362
  processParameterBody(op, sdkMethod, sdkBody) {
1392
- var _a, _b, _c;
1393
1363
  let bodyParameterFlattened = false;
1394
1364
  const sdkHttpOperation = sdkMethod.operation;
1395
1365
  // set contentTypes to mediaTypes
@@ -1407,7 +1377,7 @@ export class CodeModelBuilder {
1407
1377
  schema = this.processSchema(getNonNullSdkType(sdkType), sdkBody.name);
1408
1378
  }
1409
1379
  const parameterName = sdkBody.name;
1410
- const parameter = new Parameter(parameterName, (_a = sdkBody.doc) !== null && _a !== void 0 ? _a : "", schema, {
1380
+ const parameter = new Parameter(parameterName, sdkBody.doc ?? "", schema, {
1411
1381
  summary: sdkBody.summary,
1412
1382
  implementation: ImplementationLocation.Method,
1413
1383
  required: !sdkBody.optional,
@@ -1418,7 +1388,7 @@ export class CodeModelBuilder {
1418
1388
  op.addParameter(parameter);
1419
1389
  const jsonMergePatch = operationIsJsonMergePatch(sdkHttpOperation);
1420
1390
  const schemaIsPublicBeforeProcess = schema instanceof ObjectSchema &&
1421
- ((_b = schema.usage) === null || _b === void 0 ? void 0 : _b.includes(SchemaContext.Public));
1391
+ schema.usage?.includes(SchemaContext.Public);
1422
1392
  this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });
1423
1393
  if (op.convenienceApi) {
1424
1394
  // model/schema does not need to be Public or Internal, if it is not to be used in convenience API
@@ -1445,7 +1415,7 @@ export class CodeModelBuilder {
1445
1415
  const bodyParameterFlatten = !this.isArm() &&
1446
1416
  schema instanceof ObjectSchema &&
1447
1417
  sdkType.kind === "model" &&
1448
- sdkBody.type !== ((_c = sdkBody.correspondingMethodParams[0]) === null || _c === void 0 ? void 0 : _c.type);
1418
+ sdkBody.type !== sdkBody.correspondingMethodParams[0]?.type;
1449
1419
  if (schema instanceof ObjectSchema && bodyParameterFlatten) {
1450
1420
  // flatten body parameter
1451
1421
  const parameters = sdkHttpOperation.parameters;
@@ -1464,10 +1434,10 @@ export class CodeModelBuilder {
1464
1434
  // flatten body parameter
1465
1435
  bodyParameterFlattened = true;
1466
1436
  const schemaUsage = schema.usage;
1467
- if (!schemaIsPublicBeforeProcess && (schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.includes(SchemaContext.Public))) {
1437
+ if (!schemaIsPublicBeforeProcess && schemaUsage?.includes(SchemaContext.Public)) {
1468
1438
  // Public added in this op, change it to PublicSpread
1469
1439
  // This means that if this op would originally add Public to this schema, it adds PublicSpread instead
1470
- 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);
1471
1441
  this.trackSchemaUsage(schema, { usage: [SchemaContext.PublicSpread] });
1472
1442
  }
1473
1443
  op.convenienceApi.requests = [];
@@ -1496,7 +1466,6 @@ export class CodeModelBuilder {
1496
1466
  return bodyParameterFlattened;
1497
1467
  }
1498
1468
  addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, originalParameter) {
1499
- var _a, _b, _c, _d, _e;
1500
1469
  const serializedName = opParameter.kind === "property"
1501
1470
  ? getPropertySerializedName(opParameter)
1502
1471
  : opParameter.serializedName;
@@ -1504,24 +1473,21 @@ export class CodeModelBuilder {
1504
1473
  if (opParameter.kind !== "property") {
1505
1474
  // not body property
1506
1475
  // header/query/path, same location and same serializedName
1507
- existParameter = (_a = op.parameters) === null || _a === void 0 ? void 0 : _a.find((it) => {
1508
- var _a;
1509
- return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === opParameter.kind &&
1510
- it.language.default.serializedName === serializedName;
1511
- });
1476
+ existParameter = op.parameters?.find((it) => it.protocol.http?.in === opParameter.kind &&
1477
+ it.language.default.serializedName === serializedName);
1512
1478
  }
1513
- request.parameters = (_b = request.parameters) !== null && _b !== void 0 ? _b : [];
1479
+ request.parameters = request.parameters ?? [];
1514
1480
  if (existParameter) {
1515
1481
  // parameter
1516
1482
  if (existParameter.implementation === ImplementationLocation.Method &&
1517
- ((_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) &&
1518
1484
  !(existParameter.schema instanceof ConstantSchema)) {
1519
1485
  request.parameters.push(cloneOperationParameter(existParameter));
1520
1486
  }
1521
1487
  }
1522
1488
  else {
1523
1489
  // property from anonymous model
1524
- 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);
1525
1491
  if (existBodyProperty &&
1526
1492
  !existBodyProperty.readOnly &&
1527
1493
  !(existBodyProperty.schema instanceof ConstantSchema)) {
@@ -1542,7 +1508,6 @@ export class CodeModelBuilder {
1542
1508
  }
1543
1509
  }
1544
1510
  processResponse(op, statusCode, sdkResponse, longRunning, isErrorResponse) {
1545
- var _a, _b;
1546
1511
  // TODO: what to do if more than 1 response?
1547
1512
  // It happens when the response type is Union, on one status code.
1548
1513
  // let response: Response;
@@ -1556,7 +1521,7 @@ export class CodeModelBuilder {
1556
1521
  language: {
1557
1522
  default: {
1558
1523
  name: header.serializedName,
1559
- description: (_a = header.summary) !== null && _a !== void 0 ? _a : header.doc,
1524
+ description: header.summary ?? header.doc,
1560
1525
  },
1561
1526
  },
1562
1527
  }));
@@ -1640,7 +1605,7 @@ export class CodeModelBuilder {
1640
1605
  outputErrorModel = true;
1641
1606
  }
1642
1607
  if (this.isBranded() &&
1643
- !((_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)) {
1644
1609
  outputErrorModel = true;
1645
1610
  }
1646
1611
  if (outputErrorModel) {
@@ -1683,7 +1648,6 @@ export class CodeModelBuilder {
1683
1648
  return this.schemaCache.process(type, nameHint) || fail("Unable to process schema.");
1684
1649
  }
1685
1650
  processSchemaImpl(type, nameHint) {
1686
- var _a, _b, _c;
1687
1651
  if (isSdkBuiltInKind(type.kind)) {
1688
1652
  return this.processBuiltInType(type, nameHint);
1689
1653
  }
@@ -1709,7 +1673,7 @@ export class CodeModelBuilder {
1709
1673
  reportDiagnostic(this.program, {
1710
1674
  code: "unknown-encode",
1711
1675
  format: { encode: type.encode },
1712
- target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
1676
+ target: type.__raw ?? NoTarget,
1713
1677
  });
1714
1678
  return this.processBuiltInType(type.wireType, nameHint);
1715
1679
  }
@@ -1729,7 +1693,7 @@ export class CodeModelBuilder {
1729
1693
  reportDiagnostic(this.program, {
1730
1694
  code: "unknown-encode",
1731
1695
  format: { encode: type.encode },
1732
- target: (_b = type.__raw) !== null && _b !== void 0 ? _b : NoTarget,
1696
+ target: type.__raw ?? NoTarget,
1733
1697
  });
1734
1698
  return this.processBuiltInType(type.wireType, nameHint);
1735
1699
  }
@@ -1738,12 +1702,11 @@ export class CodeModelBuilder {
1738
1702
  const diagnostic = createDiagnostic({
1739
1703
  code: "unrecognized-type",
1740
1704
  format: { typeKind: type.kind },
1741
- target: (_c = type.__raw) !== null && _c !== void 0 ? _c : NoTarget,
1705
+ target: type.__raw ?? NoTarget,
1742
1706
  });
1743
1707
  throw new DiagnosticError(diagnostic);
1744
1708
  }
1745
1709
  processBuiltInType(type, nameHint) {
1746
- var _a;
1747
1710
  nameHint = nameHint || type.kind;
1748
1711
  if (isSdkIntKind(type.kind)) {
1749
1712
  const integerSize = type.kind === "safeint" || type.kind.includes("int64") ? 64 : 32;
@@ -1770,7 +1733,7 @@ export class CodeModelBuilder {
1770
1733
  reportDiagnostic(this.program, {
1771
1734
  code: "unknown-encode",
1772
1735
  format: { encode: type.encode },
1773
- target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
1736
+ target: type.__raw ?? NoTarget,
1774
1737
  });
1775
1738
  return this.processStringSchema(type, nameHint);
1776
1739
  }
@@ -1789,22 +1752,19 @@ export class CodeModelBuilder {
1789
1752
  return this.anySchema;
1790
1753
  }
1791
1754
  processStringSchema(type, name) {
1792
- var _a;
1793
- 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 ?? "", {
1794
1756
  summary: type.summary,
1795
1757
  }));
1796
1758
  }
1797
1759
  processByteArraySchema(type, name) {
1798
- var _a;
1799
1760
  const base64Encoded = type.encode === "base64url";
1800
- 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 ?? "", {
1801
1762
  summary: type.summary,
1802
1763
  format: base64Encoded ? "base64url" : "byte",
1803
1764
  }));
1804
1765
  }
1805
1766
  processIntegerSchema(type, name, precision) {
1806
- var _a;
1807
- 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, {
1808
1768
  summary: type.summary,
1809
1769
  });
1810
1770
  if (type.encode === "string") {
@@ -1813,26 +1773,22 @@ export class CodeModelBuilder {
1813
1773
  return this.codeModel.schemas.add(schema);
1814
1774
  }
1815
1775
  processNumberSchema(type, name) {
1816
- var _a;
1817
- 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, {
1818
1777
  summary: type.summary,
1819
1778
  }));
1820
1779
  }
1821
1780
  processDecimalSchema(type, name) {
1822
- var _a;
1823
1781
  // "Infinity" maps to "BigDecimal" in Java
1824
- 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, {
1825
1783
  summary: type.summary,
1826
1784
  }));
1827
1785
  }
1828
1786
  processBooleanSchema(type, name) {
1829
- var _a;
1830
- 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 ?? "", {
1831
1788
  summary: type.summary,
1832
1789
  }));
1833
1790
  }
1834
1791
  processArraySchema(type, name) {
1835
- var _a;
1836
1792
  let nullableItems = false;
1837
1793
  let elementType = type.valueType;
1838
1794
  if (elementType.kind === "nullable") {
@@ -1840,14 +1796,13 @@ export class CodeModelBuilder {
1840
1796
  elementType = elementType.type;
1841
1797
  }
1842
1798
  const elementSchema = this.processSchema(elementType, name);
1843
- 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, {
1844
1800
  summary: type.summary,
1845
1801
  nullableItems: nullableItems,
1846
1802
  }));
1847
1803
  }
1848
1804
  processDictionarySchema(type, name) {
1849
- var _a;
1850
- const dictSchema = new DictionarySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", null, {
1805
+ const dictSchema = new DictionarySchema(name, type.doc ?? "", null, {
1851
1806
  summary: type.summary,
1852
1807
  });
1853
1808
  // cache this now before we accidentally recurse on this type.
@@ -1866,14 +1821,13 @@ export class CodeModelBuilder {
1866
1821
  return this.codeModel.schemas.add(dictSchema);
1867
1822
  }
1868
1823
  processChoiceSchema(type, name) {
1869
- var _a, _b;
1870
1824
  const rawEnumType = type.__raw;
1871
1825
  const namespace = getNamespace(rawEnumType);
1872
1826
  const valueType = this.processSchema(type.valueType, type.valueType.kind);
1873
1827
  const choices = [];
1874
- 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)));
1875
1829
  const schemaType = type.isFixed ? SealedChoiceSchema : ChoiceSchema;
1876
- 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 ?? "", {
1877
1831
  summary: type.summary,
1878
1832
  choiceType: valueType,
1879
1833
  choices: choices,
@@ -1890,72 +1844,63 @@ export class CodeModelBuilder {
1890
1844
  return this.codeModel.schemas.add(schema);
1891
1845
  }
1892
1846
  processConstantSchema(type, name) {
1893
- var _a, _b;
1894
1847
  const valueType = this.processSchema(type.valueType, type.valueType.kind);
1895
- 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 ?? "", {
1896
1849
  summary: type.summary,
1897
1850
  valueType: valueType,
1898
1851
  value: new ConstantValue(type.value),
1899
1852
  }));
1900
1853
  }
1901
1854
  processConstantSchemaFromEnumValue(type, name) {
1902
- var _a, _b, _c;
1903
1855
  const valueType = this.processSchema(type.enumType, type.enumType.name);
1904
- 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 ?? "", {
1905
1857
  summary: type.summary,
1906
1858
  valueType: valueType,
1907
- value: new ConstantValue((_c = type.value) !== null && _c !== void 0 ? _c : type.name),
1859
+ value: new ConstantValue(type.value ?? type.name),
1908
1860
  }));
1909
1861
  }
1910
1862
  processUnixTimeSchema(type, name) {
1911
- var _a;
1912
- 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 ?? "", {
1913
1864
  summary: type.summary,
1914
1865
  }));
1915
1866
  }
1916
1867
  processDateTimeSchema(type, name, rfc1123) {
1917
- var _a;
1918
- 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 ?? "", {
1919
1869
  summary: type.summary,
1920
1870
  format: rfc1123 ? "date-time-rfc1123" : "date-time",
1921
1871
  }));
1922
1872
  }
1923
1873
  processDateSchema(type, name) {
1924
- var _a;
1925
- 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 ?? "", {
1926
1875
  summary: type.summary,
1927
1876
  }));
1928
1877
  }
1929
1878
  processTimeSchema(type, name) {
1930
- var _a;
1931
- 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 ?? "", {
1932
1880
  summary: type.summary,
1933
1881
  }));
1934
1882
  }
1935
1883
  processDurationSchema(type, name, format = "duration-rfc3339") {
1936
- var _a;
1937
- 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 ?? "", {
1938
1885
  summary: type.summary,
1939
1886
  format: format,
1940
1887
  }));
1941
1888
  }
1942
1889
  processUrlSchema(type, name) {
1943
- var _a;
1944
- 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 ?? "", {
1945
1891
  summary: type.summary,
1946
1892
  }));
1947
1893
  }
1948
1894
  processObjectSchema(type, name) {
1949
- var _a, _b, _c, _d;
1950
1895
  const rawModelType = type.__raw;
1951
1896
  if (!name && !type.name) {
1952
1897
  reportDiagnostic(this.program, {
1953
1898
  code: "empty-name",
1954
- target: rawModelType !== null && rawModelType !== void 0 ? rawModelType : NoTarget,
1899
+ target: rawModelType ?? NoTarget,
1955
1900
  });
1956
1901
  }
1957
1902
  const namespace = getNamespace(rawModelType);
1958
- 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 ?? "", {
1959
1904
  summary: type.summary,
1960
1905
  language: {
1961
1906
  default: {
@@ -1988,14 +1933,13 @@ export class CodeModelBuilder {
1988
1933
  // therefore, copy all properties from "Error" to this class
1989
1934
  const parentSchema = this.processSchema(type.baseModel, type.baseModel.name);
1990
1935
  if (parentSchema instanceof ObjectSchema) {
1991
- (_c = parentSchema.properties) === null || _c === void 0 ? void 0 : _c.forEach((p) => {
1992
- var _a;
1936
+ parentSchema.properties?.forEach((p) => {
1993
1937
  objectSchema.addProperty(p);
1994
1938
  // improve the casing for Java
1995
1939
  if (p.serializedName === "innererror") {
1996
1940
  p.language.default.name = "innerError";
1997
1941
  if (p.schema instanceof ObjectSchema) {
1998
- (_a = p.schema.properties) === null || _a === void 0 ? void 0 : _a.forEach((innerErrorProperty) => {
1942
+ p.schema.properties?.forEach((innerErrorProperty) => {
1999
1943
  if (innerErrorProperty.serializedName === "innererror") {
2000
1944
  innerErrorProperty.language.default.name = "innerError";
2001
1945
  }
@@ -2042,7 +1986,7 @@ export class CodeModelBuilder {
2042
1986
  decorators: [],
2043
1987
  };
2044
1988
  const parentSchema = this.processSchema(sdkDictType, "Record");
2045
- objectSchema.parents = (_d = objectSchema.parents) !== null && _d !== void 0 ? _d : new Relations();
1989
+ objectSchema.parents = objectSchema.parents ?? new Relations();
2046
1990
  objectSchema.parents.immediate.push(parentSchema);
2047
1991
  pushDistinct(objectSchema.parents.all, parentSchema);
2048
1992
  objectSchema.discriminatorValue = type.discriminatorValue;
@@ -2056,7 +2000,6 @@ export class CodeModelBuilder {
2056
2000
  return objectSchema;
2057
2001
  }
2058
2002
  processModelProperty(prop) {
2059
- var _a, _b;
2060
2003
  let nullable = false;
2061
2004
  let nonNullType = prop.type;
2062
2005
  if (nonNullType.kind === "nullable") {
@@ -2066,22 +2009,22 @@ export class CodeModelBuilder {
2066
2009
  let schema;
2067
2010
  let extensions = undefined;
2068
2011
  if (this.isSecret(prop)) {
2069
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
2012
+ extensions = extensions ?? {};
2070
2013
  extensions["x-ms-secret"] = true;
2071
2014
  // if the property does not return in response, it had to be nullable
2072
2015
  nullable = true;
2073
2016
  }
2074
2017
  if (prop.kind === "property" && prop.flatten) {
2075
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
2018
+ extensions = extensions ?? {};
2076
2019
  extensions["x-ms-client-flatten"] = true;
2077
2020
  }
2078
2021
  const mutability = this.getMutability(prop);
2079
2022
  if (mutability) {
2080
- extensions = extensions !== null && extensions !== void 0 ? extensions : {};
2023
+ extensions = extensions ?? {};
2081
2024
  extensions["x-ms-mutability"] = mutability;
2082
2025
  }
2083
2026
  if (prop.kind === "property" && prop.serializationOptions.multipart) {
2084
- if ((_a = prop.serializationOptions.multipart) === null || _a === void 0 ? void 0 : _a.isFilePart) {
2027
+ if (prop.serializationOptions.multipart?.isFilePart) {
2085
2028
  schema = this.processMultipartFormDataFilePropertySchema(prop);
2086
2029
  }
2087
2030
  else if (prop.type.kind === "model" &&
@@ -2096,7 +2039,7 @@ export class CodeModelBuilder {
2096
2039
  else {
2097
2040
  schema = this.processSchema(nonNullType, "");
2098
2041
  }
2099
- return new Property(prop.name, (_b = prop.doc) !== null && _b !== void 0 ? _b : "", schema, {
2042
+ return new Property(prop.name, prop.doc ?? "", schema, {
2100
2043
  summary: prop.summary,
2101
2044
  required: !prop.optional,
2102
2045
  nullable: nullable,
@@ -2106,30 +2049,28 @@ export class CodeModelBuilder {
2106
2049
  });
2107
2050
  }
2108
2051
  processUnionSchema(type, name) {
2109
- var _a, _b, _c;
2110
2052
  if (!(type.__raw && type.__raw.kind === "Union")) {
2111
2053
  reportDiagnostic(this.program, {
2112
2054
  code: "unrecognized-type",
2113
2055
  messageId: "unionType",
2114
2056
  format: { typeKind: type.kind },
2115
- target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
2057
+ target: type.__raw ?? NoTarget,
2116
2058
  });
2117
2059
  }
2118
2060
  const rawUnionType = type.__raw;
2119
2061
  const namespace = getNamespace(rawUnionType);
2120
- const baseName = (_b = type.name) !== null && _b !== void 0 ? _b : pascalCase(name) + "Model";
2062
+ const baseName = type.name ?? pascalCase(name) + "Model";
2121
2063
  this.trace(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
2122
- const unionSchema = new OrSchema(baseName + "Base", (_c = type.doc) !== null && _c !== void 0 ? _c : "", {
2064
+ const unionSchema = new OrSchema(baseName + "Base", type.doc ?? "", {
2123
2065
  summary: type.summary,
2124
2066
  });
2125
2067
  unionSchema.anyOf = [];
2126
2068
  type.variantTypes.forEach((it) => {
2127
- var _a, _b;
2128
2069
  const variantName = this.getUnionVariantName(it.__raw, { depth: 0 });
2129
2070
  const modelName = variantName + baseName;
2130
2071
  const propertyName = "value";
2131
2072
  // these ObjectSchema is not added to codeModel.schemas
2132
- const objectSchema = new ObjectSchema(modelName, (_a = it.doc) !== null && _a !== void 0 ? _a : "", {
2073
+ const objectSchema = new ObjectSchema(modelName, it.doc ?? "", {
2133
2074
  summary: it.summary,
2134
2075
  language: {
2135
2076
  default: {
@@ -2141,7 +2082,7 @@ export class CodeModelBuilder {
2141
2082
  },
2142
2083
  });
2143
2084
  const variantSchema = this.processSchema(it, variantName);
2144
- objectSchema.addProperty(new Property(propertyName, (_b = type.doc) !== null && _b !== void 0 ? _b : "", variantSchema, {
2085
+ objectSchema.addProperty(new Property(propertyName, type.doc ?? "", variantSchema, {
2145
2086
  summary: type.summary,
2146
2087
  required: true,
2147
2088
  readOnly: false,
@@ -2151,13 +2092,11 @@ export class CodeModelBuilder {
2151
2092
  return this.codeModel.schemas.add(unionSchema);
2152
2093
  }
2153
2094
  processBinarySchema(type) {
2154
- var _a;
2155
- 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 ?? "", {
2156
2096
  summary: type.summary,
2157
2097
  }));
2158
2098
  }
2159
2099
  getUnionVariantName(type, option) {
2160
- var _a, _b;
2161
2100
  if (type === undefined) {
2162
2101
  this.trace("Union variant type is undefined.");
2163
2102
  return "UnionVariant";
@@ -2213,20 +2152,18 @@ export class CodeModelBuilder {
2213
2152
  case "Boolean":
2214
2153
  return pascalCase(type.value ? "True" : "False");
2215
2154
  case "Union":
2216
- return (_a = type.name) !== null && _a !== void 0 ? _a : "Union";
2155
+ return type.name ?? "Union";
2217
2156
  case "UnionVariant":
2218
- 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";
2219
2158
  default:
2220
2159
  this.trace(`Unrecognized type for union variable: '${type.kind}'.`);
2221
2160
  return "UnionVariant";
2222
2161
  }
2223
2162
  }
2224
2163
  processMultipartFormDataFilePropertySchema(property) {
2225
- var _a, _b;
2226
2164
  const processSchemaFunc = (type) => this.processSchema(type, "");
2227
2165
  const processNamespaceFunc = (type) => {
2228
- var _a;
2229
- 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;
2230
2167
  const javaNamespace = type.kind === "model" ? this.getJavaNamespace(type) : this.getJavaNamespace();
2231
2168
  return { namespace, javaNamespace };
2232
2169
  };
@@ -2237,7 +2174,7 @@ export class CodeModelBuilder {
2237
2174
  else if (property.type.kind === "array" &&
2238
2175
  (property.type.valueType.kind === "bytes" || property.type.valueType.kind === "model")) {
2239
2176
  const namespaceTuple = processNamespaceFunc(property.type.valueType);
2240
- 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), {
2241
2178
  summary: property.summary,
2242
2179
  });
2243
2180
  }
@@ -2246,7 +2183,7 @@ export class CodeModelBuilder {
2246
2183
  code: "unrecognized-type",
2247
2184
  messageId: "multipartFormData",
2248
2185
  format: { typeKind: property.type.kind },
2249
- target: (_b = property.type.__raw) !== null && _b !== void 0 ? _b : NoTarget,
2186
+ target: property.type.__raw ?? NoTarget,
2250
2187
  });
2251
2188
  throw new DiagnosticError(diagnostic);
2252
2189
  }
@@ -2336,7 +2273,7 @@ export class CodeModelBuilder {
2336
2273
  }
2337
2274
  getJavaNamespace(type = undefined) {
2338
2275
  // clientNamespace from TCGC
2339
- const clientNamespace = type === null || type === void 0 ? void 0 : type.namespace;
2276
+ const clientNamespace = type?.namespace;
2340
2277
  // we still keep the mapping of models from TypeSpec namespace and Azure namespace to "baseJavaNamespace"
2341
2278
  if (type) {
2342
2279
  const crossLanguageDefinitionId = type.crossLanguageDefinitionId;
@@ -2409,33 +2346,39 @@ export class CodeModelBuilder {
2409
2346
  trace(msg) {
2410
2347
  trace(this.program, msg);
2411
2348
  }
2349
+ _stringSchema;
2412
2350
  get stringSchema() {
2413
2351
  return (this._stringSchema ||
2414
2352
  (this._stringSchema = this.codeModel.schemas.add(new StringSchema("string", "simple string"))));
2415
2353
  }
2354
+ _integerSchema;
2416
2355
  get integerSchema() {
2417
2356
  return (this._integerSchema ||
2418
2357
  (this._integerSchema = this.codeModel.schemas.add(new NumberSchema("integer", "simple integer", SchemaType.Integer, 64))));
2419
2358
  }
2359
+ _doubleSchema;
2420
2360
  get doubleSchema() {
2421
2361
  return (this._doubleSchema ||
2422
2362
  (this._doubleSchema = this.codeModel.schemas.add(new NumberSchema("double", "simple float", SchemaType.Number, 64))));
2423
2363
  }
2364
+ _booleanSchema;
2424
2365
  get booleanSchema() {
2425
2366
  return (this._booleanSchema ||
2426
2367
  (this._booleanSchema = this.codeModel.schemas.add(new BooleanSchema("boolean", "simple boolean"))));
2427
2368
  }
2369
+ _anySchema;
2428
2370
  get anySchema() {
2429
- var _a;
2430
- 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"))));
2431
2372
  }
2373
+ _binarySchema;
2432
2374
  get binarySchema() {
2433
2375
  return (this._binarySchema ||
2434
2376
  (this._binarySchema = this.codeModel.schemas.add(new BinarySchema("simple binary"))));
2435
2377
  }
2378
+ _pollResultSchema;
2436
2379
  get pollResultSchema() {
2437
- var _a;
2438
- 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)));
2439
2382
  }
2440
2383
  createApiVersionParameter(serializedName, parameterLocation, value = "") {
2441
2384
  return new Parameter(serializedName, "Version parameter", this.codeModel.schemas.add(new ConstantSchema(serializedName, "API Version", {
@@ -2458,6 +2401,10 @@ export class CodeModelBuilder {
2458
2401
  isApiVersionParameter(param) {
2459
2402
  return param.isApiVersionParam;
2460
2403
  }
2404
+ _apiVersionParameter;
2405
+ _apiVersionParameterInPath;
2406
+ _apiVersionParameterInHeader;
2407
+ _armApiVersionParameter;
2461
2408
  getApiVersionParameter(param) {
2462
2409
  // apiVersionParameter is cached by param.kind
2463
2410
  // we didn't expect Azure service have more than 1 type of api-version, and certainly not more than 1 of each kind.
@@ -2496,15 +2443,14 @@ export class CodeModelBuilder {
2496
2443
  }
2497
2444
  return this._subscriptionParameter;
2498
2445
  }
2446
+ _subscriptionParameter;
2499
2447
  propagateSchemaUsage(schema) {
2500
- var _a, _b, _c, _d;
2501
2448
  const processedSchemas = new Set();
2502
2449
  const innerApplySchemaUsage = (schema, schemaUsage) => {
2503
2450
  this.trackSchemaUsage(schema, schemaUsage);
2504
2451
  innerPropagateSchemaUsage(schema, schemaUsage);
2505
2452
  };
2506
2453
  const innerPropagateSchemaUsage = (schema, schemaUsage) => {
2507
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2508
2454
  if (processedSchemas.has(schema)) {
2509
2455
  return;
2510
2456
  }
@@ -2520,9 +2466,8 @@ export class CodeModelBuilder {
2520
2466
  }
2521
2467
  if (schemaUsage.usage || schemaUsage.serializationFormats) {
2522
2468
  if (!skipPropergateProperties) {
2523
- (_a = schema.properties) === null || _a === void 0 ? void 0 : _a.forEach((p) => {
2524
- var _a;
2525
- 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)) {
2526
2471
  const schemaUsageWithoutInput = {
2527
2472
  usage: schemaUsage.usage.filter((it) => it !== SchemaContext.Input),
2528
2473
  serializationFormats: schemaUsage.serializationFormats,
@@ -2535,16 +2480,16 @@ export class CodeModelBuilder {
2535
2480
  });
2536
2481
  }
2537
2482
  if (schema instanceof ObjectSchema) {
2538
- (_c = (_b = schema.parents) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.forEach((p) => innerApplySchemaUsage(p, schemaUsage));
2539
- (_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));
2540
2485
  if (schema.discriminator) {
2541
2486
  // propagate access/usage to immediate children, if the schema is a discriminated model
2542
2487
  // if the schema is not a discriminated model, its children likely not valid for the mode/API
2543
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)
2544
- (_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));
2545
2490
  }
2546
- if ((_j = (_h = schema.discriminator) === null || _h === void 0 ? void 0 : _h.property) === null || _j === void 0 ? void 0 : _j.schema) {
2547
- 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);
2548
2493
  }
2549
2494
  }
2550
2495
  }
@@ -2556,25 +2501,25 @@ export class CodeModelBuilder {
2556
2501
  innerApplySchemaUsage(schema.elementType, schemaUsage);
2557
2502
  }
2558
2503
  else if (schema instanceof OrSchema) {
2559
- (_m = schema.anyOf) === null || _m === void 0 ? void 0 : _m.forEach((it) => innerApplySchemaUsage(it, schemaUsage));
2504
+ schema.anyOf?.forEach((it) => innerApplySchemaUsage(it, schemaUsage));
2560
2505
  }
2561
2506
  else if (schema instanceof ConstantSchema) {
2562
2507
  innerApplySchemaUsage(schema.valueType, schemaUsage);
2563
2508
  }
2564
2509
  };
2565
2510
  // Exclude context that not to be propagated
2566
- const updatedSchemaUsage = (_a = schema.usage) === null || _a === void 0 ? void 0 : _a.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.PublicSpread);
2567
- 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);
2568
2513
  if (updatedSchemaUsage &&
2569
2514
  indexSpread &&
2570
2515
  indexSpread >= 0 &&
2571
- !((_c = schema.usage) === null || _c === void 0 ? void 0 : _c.includes(SchemaContext.Public))) {
2516
+ !schema.usage?.includes(SchemaContext.Public)) {
2572
2517
  // Propagate Public, if schema is PublicSpread
2573
2518
  updatedSchemaUsage.push(SchemaContext.Public);
2574
2519
  }
2575
2520
  const schemaUsage = {
2576
2521
  usage: updatedSchemaUsage,
2577
- 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),
2578
2523
  };
2579
2524
  // Propagate the usage of the initial schema itself
2580
2525
  innerPropagateSchemaUsage(schema, schemaUsage);