@azure-tools/typespec-java 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -78,6 +78,8 @@ export declare class CodeModelBuilder {
78
78
  get stringSchema(): StringSchema;
79
79
  private _integerSchema?;
80
80
  get integerSchema(): NumberSchema;
81
+ private _doubleSchema?;
82
+ get doubleSchema(): NumberSchema;
81
83
  private _booleanSchema?;
82
84
  get booleanSchema(): BooleanSchema;
83
85
  private _anySchema?;
@@ -91,6 +93,7 @@ export declare class CodeModelBuilder {
91
93
  get apiVersionParameterInPath(): Parameter;
92
94
  private propagateSchemaUsage;
93
95
  private trackSchemaUsage;
96
+ private isArmLongRunningOperation;
94
97
  private isSchemaUsageEmpty;
95
98
  }
96
99
  //# sourceMappingURL=code-model-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAoBL,OAAO,EAGP,IAAI,EAEJ,KAAK,EASL,WAAW,EAOZ,MAAM,oBAAoB,CAAC;AA+B5B,OAAO,EACL,SAAS,EAIT,aAAa,EAUb,YAAY,EACZ,YAAY,EACZ,SAAS,EAKT,MAAM,EAIN,YAAY,EAeb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAUnD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAW9C,OAAO,EACL,eAAe,EAchB,MAAM,iBAAiB,CAAC;AAoBzB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,SAAS,CAAY;IAE7B,QAAQ,CAAC,WAAW,gCAAyF;IA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AAC,UAAU;IAIlB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED,OAAO,CAAC,cAAc,CAAC,CAAe;IACtC,IAAI,aAAa,IAAI,YAAY,CAOhC;IAED,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,IAAI,YAAY,IAAI,YAAY,CAO/B;IAED,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,IAAI,aAAa,IAAI,aAAa,CAKjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED,OAAO,CAAC,iBAAiB,CAAC,CAAe;IACzC,IAAI,gBAAgB,IAAI,YAAY,CAKnC;IAED,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,oBAAoB,CAAC,CAAY;IACzC,IAAI,mBAAmB,IAAI,SAAS,CAKnC;IAED,OAAO,CAAC,0BAA0B,CAAC,CAAY;IAC/C,IAAI,yBAAyB,IAAI,SAAS,CAMzC;IAED,OAAO,CAAC,oBAAoB;IA+D5B,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,kBAAkB;CAiB3B"}
@@ -16,12 +16,13 @@ import { OrSchema } from "./common/schemas/relationship.js";
16
16
  import { LongRunningMetadata } from "./common/long-running-metadata.js";
17
17
  import { DurationSchema } from "./common/schemas/time.js";
18
18
  import { PreNamer } from "./prenamer/prenamer.js";
19
- import { createPollResultSchema } from "./external-schemas.js";
19
+ import { createPollOperationDetailsSchema } from "./external-schemas.js";
20
20
  import { ClientContext } from "./models.js";
21
21
  import { stringArrayContainsIgnoreCase, getJavaNamespace, getNamespace, pascalCase, logWarning, trace, } from "./utils.js";
22
- import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, isSameLiteralTypes, getAccess, getUsage, unionReferredByType, getUnionName, modelIs, } from "./type-utils.js";
23
- import { getClientApiVersions, getServiceVersion, operationIsJsonMergePatch, isPayloadProperty, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, loadExamples, isLroNewPollingStrategy, operationIsMultipleContentTypes, cloneOperationParameter, operationRefersUnion, operationIsMultipart, isKnownContentType, CONTENT_TYPE_KEY, } from "./operation-utils.js";
22
+ import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, isSameLiteralTypes, getAccess, getUsage, getUnionDescription, modelIs, getModelNameForProperty, isAllValueInteger, } from "./type-utils.js";
23
+ import { getClientApiVersions, getServiceVersion, operationIsJsonMergePatch, isPayloadProperty, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, loadExamples, isLroNewPollingStrategy, operationIsMultipleContentTypes, cloneOperationParameter, operationIsMultipart, isKnownContentType, CONTENT_TYPE_KEY, } from "./operation-utils.js";
24
24
  import pkg from "lodash";
25
+ import { getExtensions } from "@typespec/openapi";
25
26
  const { isEqual } = pkg;
26
27
  export class CodeModelBuilder {
27
28
  constructor(program1, context) {
@@ -34,7 +35,7 @@ export class CodeModelBuilder {
34
35
  if (this.options["skip-special-headers"]) {
35
36
  this.options["skip-special-headers"].forEach((it) => SPECIAL_HEADER_NAMES.add(it.toLowerCase()));
36
37
  }
37
- this.sdkContext = createSdkContext(context);
38
+ this.sdkContext = createSdkContext(context, "@azure-tools/typespec-java");
38
39
  const service = listServices(this.program)[0];
39
40
  const serviceNamespace = service.type;
40
41
  if (serviceNamespace === undefined) {
@@ -166,17 +167,21 @@ export class CodeModelBuilder {
166
167
  break;
167
168
  case "http":
168
169
  {
169
- const schemeOrApiKeyPrefix = scheme.scheme;
170
+ let schemeOrApiKeyPrefix = scheme.scheme;
170
171
  if (schemeOrApiKeyPrefix === "basic" || schemeOrApiKeyPrefix === "bearer") {
171
- this.logWarning(`{scheme.scheme} auth method is currently not supported.`);
172
- }
173
- else {
174
- const keyScheme = new KeySecurityScheme({
175
- name: "authorization",
176
- });
177
- keyScheme.prefix = schemeOrApiKeyPrefix; // TODO (weidxu): modify KeySecurityScheme, after design stable
178
- securitySchemes.push(keyScheme);
172
+ // HTTP Authentication should use "Basic token" or "Bearer token"
173
+ schemeOrApiKeyPrefix = pascalCase(schemeOrApiKeyPrefix);
174
+ if (!(this.options.branded === false)) {
175
+ // Azure would not allow BasicAuth or BearerAuth
176
+ this.logWarning(`{scheme.scheme} auth method is currently not supported.`);
177
+ continue;
178
+ }
179
179
  }
180
+ const keyScheme = new KeySecurityScheme({
181
+ name: "authorization",
182
+ });
183
+ keyScheme.prefix = schemeOrApiKeyPrefix; // TODO (weidxu): modify KeySecurityScheme, after design stable
184
+ securitySchemes.push(keyScheme);
180
185
  }
181
186
  break;
182
187
  }
@@ -207,11 +212,14 @@ export class CodeModelBuilder {
207
212
  // lambda to mark model as public
208
213
  const modelAsPublic = (model) => {
209
214
  // check it does not contain Union
210
- const union = unionReferredByType(this.program, model, this.typeUnionRefCache);
211
- if (union) {
212
- const errorMsg = `Model '${getTypeName(model, this.typeNameOptions)}' cannot be set as access=public, as it refers Union '${getUnionName(union, this.typeNameOptions)}'`;
213
- throw new Error(errorMsg);
214
- }
215
+ // const union = unionReferredByType(this.program, model, this.typeUnionRefCache);
216
+ // if (union) {
217
+ // const errorMsg = `Model '${getTypeName(
218
+ // model,
219
+ // this.typeNameOptions,
220
+ // )}' cannot be set as access=public, as it refers Union '${getUnionDescription(union, this.typeNameOptions)}'`;
221
+ // throw new Error(errorMsg);
222
+ // }
215
223
  const schema = this.processSchema(model, model.name);
216
224
  this.trackSchemaUsage(schema, {
217
225
  usage: [SchemaContext.Public],
@@ -242,7 +250,7 @@ export class CodeModelBuilder {
242
250
  }
243
251
  }
244
252
  processSchemaUsage() {
245
- var _a, _b, _c, _d, _e, _f, _g;
253
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
246
254
  (_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => this.propagateSchemaUsage(it));
247
255
  // post process for schema usage
248
256
  (_b = this.codeModel.schemas.objects) === null || _b === void 0 ? void 0 : _b.forEach((it) => this.resolveSchemaUsage(it));
@@ -251,6 +259,28 @@ export class CodeModelBuilder {
251
259
  (_e = this.codeModel.schemas.sealedChoices) === null || _e === void 0 ? void 0 : _e.forEach((it) => this.resolveSchemaUsage(it));
252
260
  (_f = this.codeModel.schemas.ors) === null || _f === void 0 ? void 0 : _f.forEach((it) => this.resolveSchemaUsage(it));
253
261
  (_g = this.codeModel.schemas.constants) === null || _g === void 0 ? void 0 : _g.forEach((it) => this.resolveSchemaUsage(it));
262
+ // deduplicate model name
263
+ const nameCount = new Map();
264
+ const deduplicateName = (schema) => {
265
+ var _a;
266
+ const name = schema.language.default.name;
267
+ // skip models under "com.azure.core."
268
+ if (schema.language.default.name && ((_a = schema.language.default.namespace) === null || _a === void 0 ? void 0 : _a.startsWith("com.azure.core."))) {
269
+ if (!nameCount.has(name)) {
270
+ nameCount.set(name, 1);
271
+ }
272
+ else {
273
+ const count = nameCount.get(name);
274
+ nameCount.set(name, count + 1);
275
+ schema.language.default.name = name + count;
276
+ }
277
+ }
278
+ };
279
+ (_h = this.codeModel.schemas.objects) === null || _h === void 0 ? void 0 : _h.forEach((it) => deduplicateName(it));
280
+ (_j = this.codeModel.schemas.groups) === null || _j === void 0 ? void 0 : _j.forEach((it) => deduplicateName(it)); // it has RequestConditions
281
+ (_k = this.codeModel.schemas.choices) === null || _k === void 0 ? void 0 : _k.forEach((it) => deduplicateName(it));
282
+ (_l = this.codeModel.schemas.sealedChoices) === null || _l === void 0 ? void 0 : _l.forEach((it) => deduplicateName(it));
283
+ (_m = this.codeModel.schemas.ors) === null || _m === void 0 ? void 0 : _m.forEach((it) => deduplicateName(it));
254
284
  }
255
285
  resolveSchemaUsage(schema) {
256
286
  if (schema instanceof ObjectSchema ||
@@ -273,6 +303,9 @@ export class CodeModelBuilder {
273
303
  var _a;
274
304
  const clients = listClients(this.sdkContext);
275
305
  for (const client of clients) {
306
+ if (client.arm) {
307
+ this.codeModel.arm = true;
308
+ }
276
309
  const codeModelClient = new CodeModelClient(client.name, this.getDoc(client.type), {
277
310
  summary: this.getSummary(client.type),
278
311
  // at present, use global security definition
@@ -402,7 +435,7 @@ export class CodeModelBuilder {
402
435
  });
403
436
  codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
404
437
  const convenienceApiName = this.getConvenienceApiName(operation);
405
- let generateConvenienceApi = !!convenienceApiName;
438
+ let generateConvenienceApi = Boolean(convenienceApiName);
406
439
  let apiComment = undefined;
407
440
  if (generateConvenienceApi) {
408
441
  // check if the convenience API need to be disabled for some special cases
@@ -427,15 +460,17 @@ export class CodeModelBuilder {
427
460
  apiComment = `Convenience API is not generated, as operation '${op.operation.name}' is multiple content-type`;
428
461
  this.logWarning(apiComment);
429
462
  }
430
- else {
431
- const union = operationRefersUnion(this.program, op, this.typeUnionRefCache);
432
- if (union) {
433
- // and Union
434
- generateConvenienceApi = false;
435
- apiComment = `Convenience API is not generated, as operation '${op.operation.name}' refers Union '${getUnionName(union, this.typeNameOptions)}'`;
436
- this.logWarning(apiComment);
437
- }
438
- }
463
+ // else {
464
+ // const union = operationRefersUnion(this.program, op, this.typeUnionRefCache);
465
+ // if (union) {
466
+ // // and Union
467
+ // generateConvenienceApi = false;
468
+ // apiComment = `Convenience API is not generated, as operation '${
469
+ // op.operation.name
470
+ // }' refers Union '${getUnionDescription(union, this.typeNameOptions)}'`;
471
+ // this.logWarning(apiComment);
472
+ // }
473
+ // }
439
474
  }
440
475
  if (generateConvenienceApi && convenienceApiName) {
441
476
  codeModelOperation.convenienceApi = new ConvenienceApi(convenienceApiName);
@@ -497,7 +532,7 @@ export class CodeModelBuilder {
497
532
  // check for paged
498
533
  this.processRouteForPaged(codeModelOperation, op.responses);
499
534
  // check for long-running operation
500
- this.processRouteForLongRunning(codeModelOperation, op.responses, lroMetadata);
535
+ this.processRouteForLongRunning(codeModelOperation, operation, op.responses, lroMetadata);
501
536
  operationGroup.addOperation(codeModelOperation);
502
537
  return codeModelOperation;
503
538
  }
@@ -563,7 +598,8 @@ export class CodeModelBuilder {
563
598
  }
564
599
  // finalSchema
565
600
  if (verb !== "delete" && lroMetadata.logicalResult) {
566
- const finalType = this.findResponseBody(lroMetadata.logicalResult);
601
+ const finalResult = useNewPollStrategy ? lroMetadata.logicalResult : lroMetadata.envelopeResult;
602
+ const finalType = this.findResponseBody(finalResult);
567
603
  finalSchema = this.processSchema(finalType, "finalResult");
568
604
  }
569
605
  // track usage
@@ -590,8 +626,8 @@ export class CodeModelBuilder {
590
626
  }
591
627
  return new LongRunningMetadata(false);
592
628
  }
593
- processRouteForLongRunning(op, responses, lroMetadata) {
594
- var _a, _b;
629
+ processRouteForLongRunning(op, operation, responses, lroMetadata) {
630
+ var _a, _b, _c;
595
631
  if (lroMetadata.longRunning) {
596
632
  op.extensions = (_a = op.extensions) !== null && _a !== void 0 ? _a : {};
597
633
  op.extensions["x-ms-long-running-operation"] = true;
@@ -608,6 +644,10 @@ export class CodeModelBuilder {
608
644
  }
609
645
  }
610
646
  }
647
+ if (this.isArmLongRunningOperation(this.program, operation)) {
648
+ op.extensions = (_c = op.extensions) !== null && _c !== void 0 ? _c : {};
649
+ op.extensions["x-ms-long-running-operation"] = true;
650
+ }
611
651
  }
612
652
  processParameter(op, param, clientContext) {
613
653
  var _a;
@@ -1186,7 +1226,7 @@ export class CodeModelBuilder {
1186
1226
  case "Enum":
1187
1227
  return this.processChoiceSchema(type, this.getName(type), isFixed(this.program, type));
1188
1228
  case "Union":
1189
- return this.processUnionSchema(type, nameHint);
1229
+ return this.processUnionSchema(type, this.getName(type, nameHint));
1190
1230
  case "ModelProperty": {
1191
1231
  let schema = undefined;
1192
1232
  const knownValues = getKnownValues(this.program, type);
@@ -1195,7 +1235,8 @@ export class CodeModelBuilder {
1195
1235
  schema = this.processChoiceSchema(knownValues, this.getName(knownValues), false);
1196
1236
  }
1197
1237
  else {
1198
- schema = this.processSchema(type.type, nameHint + "Model");
1238
+ const schemaNameHint = pascalCase(getModelNameForProperty(type)) + pascalCase(nameHint);
1239
+ schema = this.processSchema(type.type, schemaNameHint);
1199
1240
  }
1200
1241
  return this.applyModelPropertyDecorators(type, nameHint, schema);
1201
1242
  }
@@ -1244,6 +1285,8 @@ export class CodeModelBuilder {
1244
1285
  return this.processDurationSchema(type, nameHint);
1245
1286
  case "url":
1246
1287
  return this.processUrlSchema(type, nameHint);
1288
+ case "decimal":
1289
+ return this.processNumberSchema(type, nameHint);
1247
1290
  }
1248
1291
  if (scalarName.startsWith("int") || scalarName.startsWith("uint") || scalarName === "safeint") {
1249
1292
  // integer
@@ -1354,7 +1397,11 @@ export class CodeModelBuilder {
1354
1397
  }
1355
1398
  processChoiceSchema(type, name, sealed) {
1356
1399
  const namespace = getNamespace(type);
1357
- const valueType = typeof type.members.values().next().value.value === "number" ? this.integerSchema : this.stringSchema;
1400
+ const valueType = typeof type.members.values().next().value.value === "number"
1401
+ ? isAllValueInteger(Array.from(type.members.values()).map((it) => it.value))
1402
+ ? this.integerSchema
1403
+ : this.doubleSchema
1404
+ : this.stringSchema;
1358
1405
  const choices = [];
1359
1406
  type.members.forEach((it) => { var _a; return choices.push(new ChoiceValue(it.name, this.getDoc(it), (_a = it.value) !== null && _a !== void 0 ? _a : it.name)); });
1360
1407
  if (sealed) {
@@ -1389,7 +1436,13 @@ export class CodeModelBuilder {
1389
1436
  }
1390
1437
  }
1391
1438
  processConstantSchemaForLiteral(type, name) {
1392
- const valueType = type.kind === "String" ? this.stringSchema : type.kind === "Boolean" ? this.booleanSchema : this.integerSchema;
1439
+ const valueType = type.kind === "String"
1440
+ ? this.stringSchema
1441
+ : type.kind === "Boolean"
1442
+ ? this.booleanSchema
1443
+ : isAllValueInteger([type.value])
1444
+ ? this.integerSchema
1445
+ : this.doubleSchema;
1393
1446
  return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
1394
1447
  summary: this.getSummary(type),
1395
1448
  valueType: valueType,
@@ -1398,7 +1451,7 @@ export class CodeModelBuilder {
1398
1451
  }
1399
1452
  processConstantSchemaForEnumMember(type, name) {
1400
1453
  var _a;
1401
- const valueType = this.processChoiceSchema(type.enum, this.getName(type.enum), isFixed(this.program, type.enum));
1454
+ const valueType = this.processSchema(type.enum, this.getName(type.enum));
1402
1455
  return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
1403
1456
  summary: this.getSummary(type),
1404
1457
  valueType: valueType,
@@ -1406,8 +1459,16 @@ export class CodeModelBuilder {
1406
1459
  }));
1407
1460
  }
1408
1461
  processChoiceSchemaForUnion(type, variants, name) {
1462
+ // variants is Literal
1463
+ variants = variants.filter((it) => it.type.kind === "String" || it.type.kind === "Number" || it.type.kind === "Boolean");
1409
1464
  const kind = variants[0].type.kind;
1410
- const valueType = kind === "String" ? this.stringSchema : kind === "Boolean" ? this.booleanSchema : this.integerSchema;
1465
+ const valueType = kind === "String"
1466
+ ? this.stringSchema
1467
+ : kind === "Boolean"
1468
+ ? this.booleanSchema
1469
+ : isAllValueInteger(variants.map((it) => it.type.value))
1470
+ ? this.integerSchema
1471
+ : this.doubleSchema;
1411
1472
  const choices = [];
1412
1473
  variants.forEach((it) => choices.push(new ChoiceValue(it.type.value.toString(), this.getDoc(it), it.type.value)));
1413
1474
  const namespace = getNamespace(type);
@@ -1681,13 +1742,15 @@ export class CodeModelBuilder {
1681
1742
  }
1682
1743
  // TODO: name from typespec-client-generator-core
1683
1744
  const namespace = getNamespace(type);
1684
- const unionSchema = new OrSchema(pascalCase(name) + "Base", this.getDoc(type), {
1745
+ const baseName = pascalCase(name) + "Model";
1746
+ this.logWarning(`Convert TypeSpec Union '${getUnionDescription(type, this.typeNameOptions)}' to Class '${baseName}'`);
1747
+ const unionSchema = new OrSchema(baseName + "Base", this.getDoc(type), {
1685
1748
  summary: this.getSummary(type),
1686
1749
  });
1687
1750
  unionSchema.anyOf = [];
1688
1751
  nonNullVariants.forEach((it) => {
1689
1752
  const variantName = this.getUnionVariantName(it.type, { depth: 0 });
1690
- const modelName = variantName + pascalCase(name);
1753
+ const modelName = variantName + baseName;
1691
1754
  const propertyName = "value";
1692
1755
  // these ObjectSchema is not added to codeModel.schemas
1693
1756
  const objectSchema = new ObjectSchema(modelName, this.getDoc(type), {
@@ -1760,6 +1823,12 @@ export class CodeModelBuilder {
1760
1823
  else {
1761
1824
  return pascalCase(type.name);
1762
1825
  }
1826
+ case "String":
1827
+ return pascalCase(type.value);
1828
+ case "Number":
1829
+ return pascalCase(type.valueAsString);
1830
+ case "Boolean":
1831
+ return pascalCase(type.value ? "True" : "False");
1763
1832
  default:
1764
1833
  throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
1765
1834
  }
@@ -1806,15 +1875,15 @@ export class CodeModelBuilder {
1806
1875
  target.templateMapper.args.length > 0) {
1807
1876
  const tspName = getTypeName(target, this.typeNameOptions);
1808
1877
  const newName = getNameForTemplate(target);
1809
- this.logWarning(`Rename TypeSpec model '${tspName}' to '${newName}'`);
1878
+ this.logWarning(`Rename TypeSpec Model '${tspName}' to '${newName}'`);
1810
1879
  return newName;
1811
1880
  }
1812
- if (!target.name && nameHint && this.options["namer"]) {
1881
+ if (!target.name && nameHint) {
1813
1882
  const newName = nameHint;
1814
- this.logWarning(`Rename anonymous TypeSpec model to '${newName}'`);
1883
+ this.logWarning(`Rename anonymous TypeSpec ${target.kind} to '${newName}'`);
1815
1884
  return newName;
1816
1885
  }
1817
- return target.name;
1886
+ return target.name || "";
1818
1887
  }
1819
1888
  getSerializedName(target) {
1820
1889
  // First get projected name, if not found, return target.name
@@ -1876,6 +1945,10 @@ export class CodeModelBuilder {
1876
1945
  return (this._integerSchema ||
1877
1946
  (this._integerSchema = this.codeModel.schemas.add(new NumberSchema("integer", "simple integer", SchemaType.Integer, 64))));
1878
1947
  }
1948
+ get doubleSchema() {
1949
+ return (this._doubleSchema ||
1950
+ (this._doubleSchema = this.codeModel.schemas.add(new NumberSchema("double", "simple float", SchemaType.Number, 64))));
1951
+ }
1879
1952
  get booleanSchema() {
1880
1953
  return (this._booleanSchema ||
1881
1954
  (this._booleanSchema = this.codeModel.schemas.add(new BooleanSchema("boolean", "simple boolean"))));
@@ -1886,7 +1959,7 @@ export class CodeModelBuilder {
1886
1959
  }
1887
1960
  get pollResultSchema() {
1888
1961
  var _a;
1889
- return ((_a = this._pollResultSchema) !== null && _a !== void 0 ? _a : (this._pollResultSchema = createPollResultSchema(this.codeModel.schemas, this.stringSchema)));
1962
+ return ((_a = this._pollResultSchema) !== null && _a !== void 0 ? _a : (this._pollResultSchema = createPollOperationDetailsSchema(this.codeModel.schemas, this.stringSchema)));
1890
1963
  }
1891
1964
  createApiVersionParameter(serializedName, parameterLocation) {
1892
1965
  return new Parameter(serializedName, "Version parameter", this.codeModel.schemas.add(new ConstantSchema(serializedName, "API Version", {
@@ -1993,6 +2066,10 @@ export class CodeModelBuilder {
1993
2066
  this.trackSchemaUsage(schema.elementType, schemaUsage);
1994
2067
  }
1995
2068
  }
2069
+ isArmLongRunningOperation(program, op) {
2070
+ var _a;
2071
+ return this.codeModel.arm && Boolean((_a = getExtensions(program, op)) === null || _a === void 0 ? void 0 : _a.get("x-ms-long-running-operation"));
2072
+ }
1996
2073
  isSchemaUsageEmpty(schema) {
1997
2074
  if (schema instanceof ObjectSchema ||
1998
2075
  schema instanceof GroupSchema ||