@azure-tools/typespec-java 0.9.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.
Files changed (37) hide show
  1. package/dist/src/code-model-builder.d.ts +4 -1
  2. package/dist/src/code-model-builder.d.ts.map +1 -1
  3. package/dist/src/code-model-builder.js +150 -54
  4. package/dist/src/code-model-builder.js.map +1 -1
  5. package/dist/src/common/code-model.d.ts +1 -0
  6. package/dist/src/common/code-model.d.ts.map +1 -1
  7. package/dist/src/common/code-model.js.map +1 -1
  8. package/dist/src/emitter.d.ts +5 -2
  9. package/dist/src/emitter.d.ts.map +1 -1
  10. package/dist/src/emitter.js +11 -2
  11. package/dist/src/emitter.js.map +1 -1
  12. package/dist/src/external-schemas.d.ts +1 -1
  13. package/dist/src/external-schemas.d.ts.map +1 -1
  14. package/dist/src/external-schemas.js +13 -8
  15. package/dist/src/external-schemas.js.map +1 -1
  16. package/dist/src/operation-utils.d.ts.map +1 -1
  17. package/dist/src/operation-utils.js +8 -1
  18. package/dist/src/operation-utils.js.map +1 -1
  19. package/dist/src/prenamer/formatter.d.ts +11 -0
  20. package/dist/src/prenamer/formatter.d.ts.map +1 -0
  21. package/dist/src/prenamer/formatter.js +124 -0
  22. package/dist/src/prenamer/formatter.js.map +1 -0
  23. package/dist/src/prenamer/naming-utils.d.ts +1 -1
  24. package/dist/src/prenamer/naming-utils.d.ts.map +1 -1
  25. package/dist/src/prenamer/naming-utils.js +2 -1
  26. package/dist/src/prenamer/naming-utils.js.map +1 -1
  27. package/dist/src/prenamer/prenamer.d.ts +1 -1
  28. package/dist/src/prenamer/prenamer.d.ts.map +1 -1
  29. package/dist/src/prenamer/prenamer.js +2 -1
  30. package/dist/src/prenamer/prenamer.js.map +1 -1
  31. package/dist/src/type-utils.d.ts +4 -2
  32. package/dist/src/type-utils.d.ts.map +1 -1
  33. package/dist/src/type-utils.js +31 -2
  34. package/dist/src/type-utils.js.map +1 -1
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +16 -16
  37. package/target/azure-typespec-extension-jar-with-dependencies.jar +0 -0
@@ -33,7 +33,7 @@ export declare class CodeModelBuilder {
33
33
  private processParameterBody;
34
34
  private findResponseBody;
35
35
  private processResponse;
36
- private getStatusCode;
36
+ private getStatusCodes;
37
37
  private getResponseDescription;
38
38
  private processSchema;
39
39
  private processSchemaImpl;
@@ -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,CA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AAO,CAAC,OAAO;IAyCf,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,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
  }
@@ -195,6 +200,7 @@ export class CodeModelBuilder {
195
200
  }
196
201
  else {
197
202
  // TODO: deprecate "internal"
203
+ // eslint-disable-next-line deprecation/deprecation
198
204
  return isInternal(context, operation);
199
205
  }
200
206
  }
@@ -206,11 +212,14 @@ export class CodeModelBuilder {
206
212
  // lambda to mark model as public
207
213
  const modelAsPublic = (model) => {
208
214
  // check it does not contain Union
209
- const union = unionReferredByType(this.program, model, this.typeUnionRefCache);
210
- if (union) {
211
- const errorMsg = `Model '${getTypeName(model, this.typeNameOptions)}' cannot be set as access=public, as it refers Union '${getUnionName(union, this.typeNameOptions)}'`;
212
- throw new Error(errorMsg);
213
- }
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
+ // }
214
223
  const schema = this.processSchema(model, model.name);
215
224
  this.trackSchemaUsage(schema, {
216
225
  usage: [SchemaContext.Public],
@@ -241,7 +250,7 @@ export class CodeModelBuilder {
241
250
  }
242
251
  }
243
252
  processSchemaUsage() {
244
- var _a, _b, _c, _d, _e, _f, _g;
253
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
245
254
  (_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => this.propagateSchemaUsage(it));
246
255
  // post process for schema usage
247
256
  (_b = this.codeModel.schemas.objects) === null || _b === void 0 ? void 0 : _b.forEach((it) => this.resolveSchemaUsage(it));
@@ -250,6 +259,28 @@ export class CodeModelBuilder {
250
259
  (_e = this.codeModel.schemas.sealedChoices) === null || _e === void 0 ? void 0 : _e.forEach((it) => this.resolveSchemaUsage(it));
251
260
  (_f = this.codeModel.schemas.ors) === null || _f === void 0 ? void 0 : _f.forEach((it) => this.resolveSchemaUsage(it));
252
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));
253
284
  }
254
285
  resolveSchemaUsage(schema) {
255
286
  if (schema instanceof ObjectSchema ||
@@ -272,6 +303,9 @@ export class CodeModelBuilder {
272
303
  var _a;
273
304
  const clients = listClients(this.sdkContext);
274
305
  for (const client of clients) {
306
+ if (client.arm) {
307
+ this.codeModel.arm = true;
308
+ }
275
309
  const codeModelClient = new CodeModelClient(client.name, this.getDoc(client.type), {
276
310
  summary: this.getSummary(client.type),
277
311
  // at present, use global security definition
@@ -401,7 +435,7 @@ export class CodeModelBuilder {
401
435
  });
402
436
  codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
403
437
  const convenienceApiName = this.getConvenienceApiName(operation);
404
- let generateConvenienceApi = !!convenienceApiName;
438
+ let generateConvenienceApi = Boolean(convenienceApiName);
405
439
  let apiComment = undefined;
406
440
  if (generateConvenienceApi) {
407
441
  // check if the convenience API need to be disabled for some special cases
@@ -426,15 +460,17 @@ export class CodeModelBuilder {
426
460
  apiComment = `Convenience API is not generated, as operation '${op.operation.name}' is multiple content-type`;
427
461
  this.logWarning(apiComment);
428
462
  }
429
- else {
430
- const union = operationRefersUnion(this.program, op, this.typeUnionRefCache);
431
- if (union) {
432
- // and Union
433
- generateConvenienceApi = false;
434
- apiComment = `Convenience API is not generated, as operation '${op.operation.name}' refers Union '${getUnionName(union, this.typeNameOptions)}'`;
435
- this.logWarning(apiComment);
436
- }
437
- }
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
+ // }
438
474
  }
439
475
  if (generateConvenienceApi && convenienceApiName) {
440
476
  codeModelOperation.convenienceApi = new ConvenienceApi(convenienceApiName);
@@ -496,7 +532,7 @@ export class CodeModelBuilder {
496
532
  // check for paged
497
533
  this.processRouteForPaged(codeModelOperation, op.responses);
498
534
  // check for long-running operation
499
- this.processRouteForLongRunning(codeModelOperation, op.responses, lroMetadata);
535
+ this.processRouteForLongRunning(codeModelOperation, operation, op.responses, lroMetadata);
500
536
  operationGroup.addOperation(codeModelOperation);
501
537
  return codeModelOperation;
502
538
  }
@@ -562,7 +598,8 @@ export class CodeModelBuilder {
562
598
  }
563
599
  // finalSchema
564
600
  if (verb !== "delete" && lroMetadata.logicalResult) {
565
- const finalType = this.findResponseBody(lroMetadata.logicalResult);
601
+ const finalResult = useNewPollStrategy ? lroMetadata.logicalResult : lroMetadata.envelopeResult;
602
+ const finalType = this.findResponseBody(finalResult);
566
603
  finalSchema = this.processSchema(finalType, "finalResult");
567
604
  }
568
605
  // track usage
@@ -589,8 +626,8 @@ export class CodeModelBuilder {
589
626
  }
590
627
  return new LongRunningMetadata(false);
591
628
  }
592
- processRouteForLongRunning(op, responses, lroMetadata) {
593
- var _a, _b;
629
+ processRouteForLongRunning(op, operation, responses, lroMetadata) {
630
+ var _a, _b, _c;
594
631
  if (lroMetadata.longRunning) {
595
632
  op.extensions = (_a = op.extensions) !== null && _a !== void 0 ? _a : {};
596
633
  op.extensions["x-ms-long-running-operation"] = true;
@@ -607,6 +644,10 @@ export class CodeModelBuilder {
607
644
  }
608
645
  }
609
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
+ }
610
651
  }
611
652
  processParameter(op, param, clientContext) {
612
653
  var _a;
@@ -1028,7 +1069,7 @@ export class CodeModelBuilder {
1028
1069
  response = new BinaryResponse({
1029
1070
  protocol: {
1030
1071
  http: {
1031
- statusCodes: [this.getStatusCode(resp.statusCode)],
1072
+ statusCodes: this.getStatusCodes(resp.statusCodes),
1032
1073
  headers: headers,
1033
1074
  mediaTypes: responseBody.contentTypes,
1034
1075
  knownMediaType: "binary",
@@ -1085,13 +1126,13 @@ export class CodeModelBuilder {
1085
1126
  schema = op.lroMetadata.pollResultType;
1086
1127
  }
1087
1128
  else {
1088
- schema = this.processSchema(bodyType, "response");
1129
+ schema = this.processSchema(bodyType, op.language.default.name + "Response");
1089
1130
  }
1090
1131
  }
1091
1132
  response = new SchemaResponse(schema, {
1092
1133
  protocol: {
1093
1134
  http: {
1094
- statusCodes: [this.getStatusCode(resp.statusCode)],
1135
+ statusCodes: this.getStatusCodes(resp.statusCodes),
1095
1136
  headers: headers,
1096
1137
  mediaTypes: responseBody.contentTypes,
1097
1138
  },
@@ -1110,7 +1151,7 @@ export class CodeModelBuilder {
1110
1151
  response = new Response({
1111
1152
  protocol: {
1112
1153
  http: {
1113
- statusCodes: [this.getStatusCode(resp.statusCode)],
1154
+ statusCodes: this.getStatusCodes(resp.statusCodes),
1114
1155
  headers: headers,
1115
1156
  },
1116
1157
  },
@@ -1122,7 +1163,7 @@ export class CodeModelBuilder {
1122
1163
  },
1123
1164
  });
1124
1165
  }
1125
- if (resp.statusCode === "*" || (bodyType && isErrorModel(this.program, bodyType))) {
1166
+ if (resp.statusCodes === "*" || (bodyType && isErrorModel(this.program, bodyType))) {
1126
1167
  // "*", or the model is @error
1127
1168
  op.addException(response);
1128
1169
  if (response instanceof SchemaResponse) {
@@ -1142,12 +1183,25 @@ export class CodeModelBuilder {
1142
1183
  }
1143
1184
  }
1144
1185
  }
1145
- getStatusCode(statusCode) {
1146
- return statusCode === "*" ? "default" : statusCode;
1186
+ getStatusCodes(statusCodes) {
1187
+ if (statusCodes === "*") {
1188
+ return ["default"];
1189
+ }
1190
+ else if (typeof statusCodes === "number") {
1191
+ return [statusCodes.toString()];
1192
+ }
1193
+ else {
1194
+ // HttpStatusCodeRange
1195
+ // azure-core does not support "status code range", hence here we expand the range to array of status codes
1196
+ return Array(statusCodes.end - statusCodes.start + 1)
1197
+ .fill(statusCodes.start)
1198
+ .map((it, index) => it + index)
1199
+ .map((it) => it.toString());
1200
+ }
1147
1201
  }
1148
1202
  getResponseDescription(resp) {
1149
1203
  return (resp.description ||
1150
- (resp.statusCode === "*" ? "An unexpected error response" : getStatusCodeDescription(resp.statusCode)) ||
1204
+ (resp.statusCodes === "*" ? "An unexpected error response" : getStatusCodeDescription(resp.statusCodes)) ||
1151
1205
  "");
1152
1206
  }
1153
1207
  processSchema(type, nameHint) {
@@ -1172,7 +1226,7 @@ export class CodeModelBuilder {
1172
1226
  case "Enum":
1173
1227
  return this.processChoiceSchema(type, this.getName(type), isFixed(this.program, type));
1174
1228
  case "Union":
1175
- return this.processUnionSchema(type, nameHint);
1229
+ return this.processUnionSchema(type, this.getName(type, nameHint));
1176
1230
  case "ModelProperty": {
1177
1231
  let schema = undefined;
1178
1232
  const knownValues = getKnownValues(this.program, type);
@@ -1181,7 +1235,8 @@ export class CodeModelBuilder {
1181
1235
  schema = this.processChoiceSchema(knownValues, this.getName(knownValues), false);
1182
1236
  }
1183
1237
  else {
1184
- schema = this.processSchema(type.type, nameHint);
1238
+ const schemaNameHint = pascalCase(getModelNameForProperty(type)) + pascalCase(nameHint);
1239
+ schema = this.processSchema(type.type, schemaNameHint);
1185
1240
  }
1186
1241
  return this.applyModelPropertyDecorators(type, nameHint, schema);
1187
1242
  }
@@ -1196,7 +1251,7 @@ export class CodeModelBuilder {
1196
1251
  return this.processDictionarySchema(type, nameHint);
1197
1252
  }
1198
1253
  else {
1199
- return this.processObjectSchema(type, this.getName(type));
1254
+ return this.processObjectSchema(type, this.getName(type, nameHint));
1200
1255
  }
1201
1256
  case "EnumMember":
1202
1257
  // e.g. "type: TypeEnum.EnumValue1"
@@ -1230,6 +1285,8 @@ export class CodeModelBuilder {
1230
1285
  return this.processDurationSchema(type, nameHint);
1231
1286
  case "url":
1232
1287
  return this.processUrlSchema(type, nameHint);
1288
+ case "decimal":
1289
+ return this.processNumberSchema(type, nameHint);
1233
1290
  }
1234
1291
  if (scalarName.startsWith("int") || scalarName.startsWith("uint") || scalarName === "safeint") {
1235
1292
  // integer
@@ -1340,7 +1397,11 @@ export class CodeModelBuilder {
1340
1397
  }
1341
1398
  processChoiceSchema(type, name, sealed) {
1342
1399
  const namespace = getNamespace(type);
1343
- 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;
1344
1405
  const choices = [];
1345
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)); });
1346
1407
  if (sealed) {
@@ -1375,7 +1436,13 @@ export class CodeModelBuilder {
1375
1436
  }
1376
1437
  }
1377
1438
  processConstantSchemaForLiteral(type, name) {
1378
- 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;
1379
1446
  return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
1380
1447
  summary: this.getSummary(type),
1381
1448
  valueType: valueType,
@@ -1384,7 +1451,7 @@ export class CodeModelBuilder {
1384
1451
  }
1385
1452
  processConstantSchemaForEnumMember(type, name) {
1386
1453
  var _a;
1387
- 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));
1388
1455
  return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
1389
1456
  summary: this.getSummary(type),
1390
1457
  valueType: valueType,
@@ -1392,8 +1459,16 @@ export class CodeModelBuilder {
1392
1459
  }));
1393
1460
  }
1394
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");
1395
1464
  const kind = variants[0].type.kind;
1396
- 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;
1397
1472
  const choices = [];
1398
1473
  variants.forEach((it) => choices.push(new ChoiceValue(it.type.value.toString(), this.getDoc(it), it.type.value)));
1399
1474
  const namespace = getNamespace(type);
@@ -1667,13 +1742,15 @@ export class CodeModelBuilder {
1667
1742
  }
1668
1743
  // TODO: name from typespec-client-generator-core
1669
1744
  const namespace = getNamespace(type);
1670
- const unionSchema = new OrSchema(pascalCase(name) + "ModelBase", 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), {
1671
1748
  summary: this.getSummary(type),
1672
1749
  });
1673
1750
  unionSchema.anyOf = [];
1674
1751
  nonNullVariants.forEach((it) => {
1675
1752
  const variantName = this.getUnionVariantName(it.type, { depth: 0 });
1676
- const modelName = variantName + pascalCase(name) + "Model";
1753
+ const modelName = variantName + baseName;
1677
1754
  const propertyName = "value";
1678
1755
  // these ObjectSchema is not added to codeModel.schemas
1679
1756
  const objectSchema = new ObjectSchema(modelName, this.getDoc(type), {
@@ -1746,6 +1823,12 @@ export class CodeModelBuilder {
1746
1823
  else {
1747
1824
  return pascalCase(type.name);
1748
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");
1749
1832
  default:
1750
1833
  throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
1751
1834
  }
@@ -1771,7 +1854,7 @@ export class CodeModelBuilder {
1771
1854
  getSummary(target) {
1772
1855
  return getSummary(this.program, target);
1773
1856
  }
1774
- getName(target) {
1857
+ getName(target, nameHint = undefined) {
1775
1858
  // TODO: once getLibraryName API in typespec-client-generator-core can get projected name from language and client, as well as can handle template case, use getLibraryName API
1776
1859
  const languageProjectedName = getProjectedName(this.program, target, "java");
1777
1860
  if (languageProjectedName) {
@@ -1792,10 +1875,15 @@ export class CodeModelBuilder {
1792
1875
  target.templateMapper.args.length > 0) {
1793
1876
  const tspName = getTypeName(target, this.typeNameOptions);
1794
1877
  const newName = getNameForTemplate(target);
1795
- this.logWarning(`Rename TypeSpec model '${tspName}' to '${newName}'`);
1878
+ this.logWarning(`Rename TypeSpec Model '${tspName}' to '${newName}'`);
1796
1879
  return newName;
1797
1880
  }
1798
- return target.name;
1881
+ if (!target.name && nameHint) {
1882
+ const newName = nameHint;
1883
+ this.logWarning(`Rename anonymous TypeSpec ${target.kind} to '${newName}'`);
1884
+ return newName;
1885
+ }
1886
+ return target.name || "";
1799
1887
  }
1800
1888
  getSerializedName(target) {
1801
1889
  // First get projected name, if not found, return target.name
@@ -1857,6 +1945,10 @@ export class CodeModelBuilder {
1857
1945
  return (this._integerSchema ||
1858
1946
  (this._integerSchema = this.codeModel.schemas.add(new NumberSchema("integer", "simple integer", SchemaType.Integer, 64))));
1859
1947
  }
1948
+ get doubleSchema() {
1949
+ return (this._doubleSchema ||
1950
+ (this._doubleSchema = this.codeModel.schemas.add(new NumberSchema("double", "simple float", SchemaType.Number, 64))));
1951
+ }
1860
1952
  get booleanSchema() {
1861
1953
  return (this._booleanSchema ||
1862
1954
  (this._booleanSchema = this.codeModel.schemas.add(new BooleanSchema("boolean", "simple boolean"))));
@@ -1867,7 +1959,7 @@ export class CodeModelBuilder {
1867
1959
  }
1868
1960
  get pollResultSchema() {
1869
1961
  var _a;
1870
- 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)));
1871
1963
  }
1872
1964
  createApiVersionParameter(serializedName, parameterLocation) {
1873
1965
  return new Parameter(serializedName, "Version parameter", this.codeModel.schemas.add(new ConstantSchema(serializedName, "API Version", {
@@ -1974,6 +2066,10 @@ export class CodeModelBuilder {
1974
2066
  this.trackSchemaUsage(schema.elementType, schemaUsage);
1975
2067
  }
1976
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
+ }
1977
2073
  isSchemaUsageEmpty(schema) {
1978
2074
  if (schema instanceof ObjectSchema ||
1979
2075
  schema instanceof GroupSchema ||