@azure-tools/typespec-ts 0.23.0 → 0.25.0-alpha.20240311.1

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 (74) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +10 -10
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/lib.d.ts +5 -2
  6. package/dist/src/lib.d.ts.map +1 -1
  7. package/dist/src/lib.js +2 -1
  8. package/dist/src/lib.js.map +1 -1
  9. package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
  10. package/dist/src/modular/buildCodeModel.js +86 -45
  11. package/dist/src/modular/buildCodeModel.js.map +1 -1
  12. package/dist/src/modular/buildProjectFiles.js +11 -12
  13. package/dist/src/modular/buildProjectFiles.js.map +1 -1
  14. package/dist/src/modular/emitModels.d.ts.map +1 -1
  15. package/dist/src/modular/emitModels.js +3 -6
  16. package/dist/src/modular/emitModels.js.map +1 -1
  17. package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
  18. package/dist/src/modular/helpers/classicalOperationHelpers.js +8 -2
  19. package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
  20. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  21. package/dist/src/modular/helpers/operationHelpers.js +22 -5
  22. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  23. package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
  24. package/dist/src/modular/helpers/typeHelpers.js +11 -5
  25. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  26. package/dist/src/transform/transform.d.ts.map +1 -1
  27. package/dist/src/transform/transform.js +2 -2
  28. package/dist/src/transform/transform.js.map +1 -1
  29. package/dist/src/transform/transformApiVersionInfo.js +2 -2
  30. package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
  31. package/dist/src/transform/transformHelperFunctionDetails.d.ts +2 -2
  32. package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
  33. package/dist/src/transform/transformHelperFunctionDetails.js +3 -3
  34. package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
  35. package/dist/src/transform/transformParameters.js +1 -1
  36. package/dist/src/transform/transformParameters.js.map +1 -1
  37. package/dist/src/transform/transformPaths.js +5 -5
  38. package/dist/src/transform/transformPaths.js.map +1 -1
  39. package/dist/src/transform/transformResponses.js +2 -2
  40. package/dist/src/transform/transformResponses.js.map +1 -1
  41. package/dist/src/transform/transfromRLCOptions.d.ts +3 -2
  42. package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
  43. package/dist/src/transform/transfromRLCOptions.js +30 -10
  44. package/dist/src/transform/transfromRLCOptions.js.map +1 -1
  45. package/dist/src/utils/emitUtil.js +9 -9
  46. package/dist/src/utils/emitUtil.js.map +1 -1
  47. package/dist/src/utils/modelUtils.d.ts +2 -6
  48. package/dist/src/utils/modelUtils.d.ts.map +1 -1
  49. package/dist/src/utils/modelUtils.js +54 -39
  50. package/dist/src/utils/modelUtils.js.map +1 -1
  51. package/dist/src/utils/operationUtil.d.ts +2 -2
  52. package/dist/src/utils/operationUtil.d.ts.map +1 -1
  53. package/dist/src/utils/operationUtil.js +10 -10
  54. package/dist/src/utils/operationUtil.js.map +1 -1
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +17 -17
  57. package/src/index.ts +6 -5
  58. package/src/lib.ts +7 -2
  59. package/src/modular/buildCodeModel.ts +89 -48
  60. package/src/modular/buildProjectFiles.ts +13 -13
  61. package/src/modular/emitModels.ts +3 -6
  62. package/src/modular/helpers/classicalOperationHelpers.ts +9 -2
  63. package/src/modular/helpers/operationHelpers.ts +28 -9
  64. package/src/modular/helpers/typeHelpers.ts +12 -6
  65. package/src/transform/transform.ts +6 -2
  66. package/src/transform/transformApiVersionInfo.ts +2 -2
  67. package/src/transform/transformHelperFunctionDetails.ts +4 -4
  68. package/src/transform/transformParameters.ts +1 -1
  69. package/src/transform/transformPaths.ts +5 -5
  70. package/src/transform/transformResponses.ts +2 -2
  71. package/src/transform/transfromRLCOptions.ts +49 -22
  72. package/src/utils/emitUtil.ts +7 -7
  73. package/src/utils/modelUtils.ts +51 -44
  74. package/src/utils/operationUtil.ts +11 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-ts",
3
- "version": "0.23.0",
3
+ "version": "0.25.0-alpha.20240311.1",
4
4
  "description": "An experimental TypeSpec emitter for TypeScript RLC",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
@@ -21,9 +21,9 @@
21
21
  "ts-node": "~10.9.1",
22
22
  "typescript": "~5.2.0",
23
23
  "prettier": "^3.1.0",
24
- "@azure-tools/cadl-ranch-specs": "^0.30.0",
25
- "@azure-tools/cadl-ranch-expect": "^0.13.0",
26
- "@azure-tools/cadl-ranch": "^0.12.0",
24
+ "@azure-tools/cadl-ranch-specs": "^0.31.2",
25
+ "@azure-tools/cadl-ranch-expect": "^0.13.2",
26
+ "@azure-tools/cadl-ranch": "^0.12.4",
27
27
  "chalk": "^4.0.0",
28
28
  "@azure-rest/core-client": "^1.2.0",
29
29
  "@azure/core-auth": "^1.6.0",
@@ -35,25 +35,25 @@
35
35
  "@azure/core-util": "^1.4.0",
36
36
  "eslint-plugin-require-extensions": "0.1.3",
37
37
  "@typespec/ts-http-runtime": "1.0.0-alpha.20240226.9",
38
- "@azure-tools/typespec-azure-core": ">=0.39.0 <1.0.0",
39
- "@azure-tools/typespec-client-generator-core": ">=0.39.0 <1.0.0",
40
- "@typespec/compiler": ">=0.53.0 <1.0.0",
41
- "@typespec/http": ">=0.53.0 <1.0.0",
42
- "@typespec/rest": ">=0.53.0 <1.0.0",
43
- "@typespec/versioning": ">=0.53.0 <1.0.0"
38
+ "@azure-tools/typespec-azure-core": ">=0.40.0 <1.0.0",
39
+ "@azure-tools/typespec-client-generator-core": "0.40.0",
40
+ "@typespec/compiler": ">=0.54.0 <1.0.0",
41
+ "@typespec/http": ">=0.54.0 <1.0.0",
42
+ "@typespec/rest": ">=0.54.0 <1.0.0",
43
+ "@typespec/versioning": ">=0.54.0 <1.0.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "@azure-tools/typespec-azure-core": ">=0.39.0 <1.0.0",
47
- "@azure-tools/typespec-client-generator-core": ">=0.39.0 <1.0.0",
48
- "@typespec/compiler": ">=0.53.0 <1.0.0",
49
- "@typespec/http": ">=0.53.0 <1.0.0",
50
- "@typespec/rest": ">=0.53.0 <1.0.0",
51
- "@typespec/versioning": ">=0.53.0 <1.0.0"
46
+ "@azure-tools/typespec-azure-core": ">=0.40.0 <1.0.0",
47
+ "@azure-tools/typespec-client-generator-core": "0.40.0",
48
+ "@typespec/compiler": ">=0.54.0 <1.0.0",
49
+ "@typespec/http": ">=0.54.0 <1.0.0",
50
+ "@typespec/rest": ">=0.54.0 <1.0.0",
51
+ "@typespec/versioning": ">=0.54.0 <1.0.0"
52
52
  },
53
53
  "dependencies": {
54
54
  "prettier": "^3.1.0",
55
55
  "tslib": "^2.3.1",
56
- "@azure-tools/rlc-common": "^0.23.0",
56
+ "@azure-tools/rlc-common": "^0.24.0",
57
57
  "ts-morph": "^15.1.0",
58
58
  "fs-extra": "^11.1.0"
59
59
  },
package/src/index.ts CHANGED
@@ -59,13 +59,14 @@ import {
59
59
  buildPagingTypes,
60
60
  buildPagingHelpers as buildModularPagingHelpers
61
61
  } from "./modular/buildPagingFiles.js";
62
+ import { EmitterOptions } from "./lib.js";
62
63
 
63
64
  export * from "./lib.js";
64
65
 
65
66
  export async function $onEmit(context: EmitContext) {
66
67
  /** Shared status */
67
68
  const program: Program = context.program;
68
- const emitterOptions: RLCOptions = context.options;
69
+ const emitterOptions: EmitterOptions = context.options;
69
70
  const dpgContext = createSdkContext(
70
71
  context,
71
72
  "@azure-tools/typespec-ts"
@@ -100,7 +101,7 @@ export async function $onEmit(context: EmitContext) {
100
101
  options.generateTest === true ||
101
102
  (options.generateTest === undefined &&
102
103
  !hasTestFolder &&
103
- options.branded);
104
+ options.flavor === "azure");
104
105
  dpgContext.rlcOptions = options;
105
106
  }
106
107
 
@@ -248,7 +249,7 @@ export async function $onEmit(context: EmitContext) {
248
249
  }
249
250
  const rlcClient: RLCModel = rlcCodeModels[0];
250
251
  const option = dpgContext.rlcOptions!;
251
- const isBranded = option.branded ?? true;
252
+ const isAzureFlavor = option.flavor === "azure";
252
253
  // Generate metadata
253
254
  const hasPackageFile = await existsSync(
254
255
  join(dpgContext.generationPathDetail?.metadataDir ?? "", "package.json")
@@ -262,7 +263,7 @@ export async function $onEmit(context: EmitContext) {
262
263
  buildApiExtractorConfig,
263
264
  buildReadmeFile
264
265
  ];
265
- if (isBranded) {
266
+ if (isAzureFlavor) {
266
267
  commonBuilders.push(buildEsLintConfig);
267
268
  }
268
269
  if (!option.isModularLibrary) {
@@ -300,7 +301,7 @@ export async function $onEmit(context: EmitContext) {
300
301
  }
301
302
 
302
303
  // Generate test relevant files
303
- if (option.generateTest && isBranded) {
304
+ if (option.generateTest && isAzureFlavor) {
304
305
  await emitContentByBuilder(
305
306
  program,
306
307
  [
package/src/lib.ts CHANGED
@@ -9,7 +9,11 @@ import {
9
9
  import { RLCOptions } from "@azure-tools/rlc-common";
10
10
  import { Options } from "prettier";
11
11
 
12
- export const RLCOptionsSchema: JSONSchemaType<RLCOptions> = {
12
+ export interface EmitterOptions extends RLCOptions {
13
+ branded?: boolean;
14
+ }
15
+
16
+ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
13
17
  type: "object",
14
18
  additionalProperties: true,
15
19
  properties: {
@@ -77,7 +81,8 @@ export const RLCOptionsSchema: JSONSchemaType<RLCOptions> = {
77
81
  enableOperationGroup: { type: "boolean", nullable: true },
78
82
  enableModelNamespace: { type: "boolean", nullable: true },
79
83
  hierarchyClient: { type: "boolean", nullable: true },
80
- branded: { type: "boolean", nullable: true, default: true }
84
+ branded: { type: "boolean", nullable: true },
85
+ flavor: { type: "string", nullable: true }
81
86
  },
82
87
  required: []
83
88
  };
@@ -31,7 +31,6 @@ import {
31
31
  Union,
32
32
  Type,
33
33
  IntrinsicType,
34
- getProjectedName,
35
34
  isNullType,
36
35
  getEncode,
37
36
  isTemplateDeclarationOrInstance,
@@ -67,7 +66,9 @@ import {
67
66
  SdkBuiltInType,
68
67
  getSdkBuiltInType,
69
68
  getClientType,
70
- SdkEnumValueType
69
+ SdkEnumValueType,
70
+ getLibraryName,
71
+ getWireName
71
72
  } from "@azure-tools/typespec-client-generator-core";
72
73
  import {
73
74
  ModularCodeModel,
@@ -82,7 +83,7 @@ import {
82
83
  } from "./modularCodeModel.js";
83
84
  import {
84
85
  getBodyType,
85
- getEnrichedDefaultApiVersion,
86
+ getDefaultApiVersionString,
86
87
  isAzureCoreErrorType
87
88
  } from "../utils/modelUtils.js";
88
89
  import { camelToSnakeCase, toCamelCase } from "../utils/casingUtils.js";
@@ -251,20 +252,25 @@ function getEffectiveSchemaType(program: Program, type: Model | Union): Model {
251
252
  return !(headerInfo || queryInfo || pathInfo || statusCodeinfo);
252
253
  }
253
254
 
254
- let effective: Model;
255
+ // If type is an anonymous model, tries to find a named model that has the same properties
256
+ let effective: Model | undefined = undefined;
255
257
  if (type.kind === "Union") {
256
258
  const nonNullOptions = [...type.variants.values()]
257
259
  .map((x) => x.type)
258
260
  .filter((t) => !isNullType(t));
259
- if (nonNullOptions.length === 1 && nonNullOptions[0]?.kind === "Model") {
261
+ if (
262
+ nonNullOptions.length === 1 &&
263
+ nonNullOptions[0]?.kind === "Model" &&
264
+ nonNullOptions[0]?.name === ""
265
+ ) {
260
266
  effective = getEffectiveModelType(program, nonNullOptions[0]);
261
267
  }
262
268
  return type as any;
263
- } else {
269
+ } else if (type.name === "") {
264
270
  effective = getEffectiveModelType(program, type, isSchemaProperty);
265
271
  }
266
272
 
267
- if (effective.name) {
273
+ if (effective?.name) {
268
274
  return effective;
269
275
  }
270
276
  return type as Model;
@@ -398,29 +404,35 @@ type ParamBase = {
398
404
  description: string;
399
405
  addedOn: string | undefined;
400
406
  clientName: string;
407
+ restApiName: string;
401
408
  inOverload: boolean;
402
409
  format?: string;
403
410
  };
404
411
  function emitParamBase(
405
- program: Program,
412
+ context: SdkContext,
406
413
  parameter: ModelProperty | Type
407
414
  ): ParamBase {
408
415
  let optional: boolean;
409
416
  let name: string;
417
+ let restApiName: string;
410
418
  let description: string = "";
411
419
  let addedOn: string | undefined;
412
420
  let format: string | undefined;
413
421
 
422
+ const program = context.program;
423
+
414
424
  if (parameter.kind === "ModelProperty") {
415
- const newParameter = applyEncoding(program, parameter, parameter);
416
425
  optional = parameter.optional;
417
- name = parameter.name;
426
+ name = getLibraryName(context, parameter);
427
+ restApiName = getWireName(context, parameter);
418
428
  description = getDocStr(program, parameter);
419
429
  addedOn = getAddedOnVersion(program, parameter);
430
+ const newParameter = applyEncoding(program, parameter, parameter);
420
431
  format = newParameter.format;
421
432
  } else {
422
433
  optional = false;
423
434
  name = "body";
435
+ restApiName = "body";
424
436
  }
425
437
 
426
438
  return {
@@ -428,6 +440,7 @@ function emitParamBase(
428
440
  description,
429
441
  addedOn,
430
442
  clientName: applyCasing(name, { casing: CASING }),
443
+ restApiName,
431
444
  inOverload: false,
432
445
  format
433
446
  };
@@ -436,7 +449,6 @@ function emitParamBase(
436
449
  type BodyParameter = ParamBase & {
437
450
  contentTypes: string[];
438
451
  type: Type;
439
- restApiName: string;
440
452
  location: "body";
441
453
  // defaultContentType: string;
442
454
  isBinaryPayload: boolean;
@@ -448,7 +460,7 @@ function emitBodyParameter(
448
460
  ): BodyParameter {
449
461
  const params = httpOperation.parameters;
450
462
  const body = params.body!;
451
- const base = emitParamBase(context.program, body.parameter ?? body.type);
463
+ const base = emitParamBase(context, body.parameter ?? body.type);
452
464
  let contentTypes = body.contentTypes;
453
465
  if (contentTypes.length === 0) {
454
466
  contentTypes = ["application/json"];
@@ -461,7 +473,6 @@ function emitBodyParameter(
461
473
  return {
462
474
  contentTypes,
463
475
  type,
464
- restApiName: body.parameter?.name ?? "body",
465
476
  location: "body",
466
477
  ...base,
467
478
  isBinaryPayload: isBinaryPayload(context, body.type, contentTypes)
@@ -473,7 +484,7 @@ function emitParameter(
473
484
  parameter: HttpOperationParameter | HttpServerParameter,
474
485
  implementation: string
475
486
  ): Parameter {
476
- const base = emitParamBase(context.program, parameter.param);
487
+ const base = emitParamBase(context, parameter.param);
477
488
  let type = getType(context, parameter.param.type, {
478
489
  usage: UsageFlags.Input
479
490
  });
@@ -514,10 +525,7 @@ function emitParameter(
514
525
  clientDefaultValue = defaultApiVersion.value;
515
526
  }
516
527
  if (!clientDefaultValue) {
517
- clientDefaultValue = getEnrichedDefaultApiVersion(
518
- context.program,
519
- context
520
- );
528
+ clientDefaultValue = getDefaultApiVersionString(context.program, context);
521
529
  }
522
530
  }
523
531
  return { clientDefaultValue, ...base, ...paramMap };
@@ -640,9 +648,9 @@ function emitOperation(
640
648
  rlcModels: RLCModel,
641
649
  hierarchies: string[]
642
650
  ): HrlcOperation {
643
- const isBranded = rlcModels.options?.branded ?? true;
651
+ const isAzureFlavor = rlcModels.options?.flavor === "azure";
644
652
  // Skip to extract paging and lro information for non-branded clients.
645
- if (!isBranded) {
653
+ if (!isAzureFlavor) {
646
654
  return emitBasicOperation(
647
655
  context,
648
656
  operation,
@@ -810,10 +818,7 @@ function emitBasicOperation(
810
818
  context,
811
819
  sourceOperation
812
820
  );
813
- const sourceOperationName = getOperationName(
814
- context.program,
815
- sourceOperation
816
- );
821
+ const sourceOperationName = getOperationName(context, sourceOperation);
817
822
  const sourceRoutePath = ignoreDiagnostics(
818
823
  getHttpOperation(context.program, operation)
819
824
  ).path;
@@ -904,7 +909,9 @@ function emitBasicOperation(
904
909
  }
905
910
  }
906
911
 
907
- const name = applyCasing(operation.name, { casing: CASING });
912
+ const name = applyCasing(getLibraryName(context, operation), {
913
+ casing: CASING
914
+ });
908
915
 
909
916
  /** handle name collision between operation name and parameter signature */
910
917
  if (bodyParameter) {
@@ -946,7 +953,7 @@ function isReadOnly(program: Program, type: ModelProperty): boolean {
946
953
  // Only "read" should be readOnly
947
954
  const visibility = getVisibility(program, type);
948
955
  if (visibility) {
949
- return visibility.includes("read");
956
+ return visibility.includes("read") && visibility.length === 1;
950
957
  } else {
951
958
  return false;
952
959
  }
@@ -974,9 +981,8 @@ function emitProperty(
974
981
  }
975
982
 
976
983
  // const [clientName, jsonName] = getPropertyNames(context, property);
977
- const clientName = property.name;
978
- const jsonName =
979
- getProjectedName(context.program, property, "json") ?? property.name;
984
+ const clientName = getLibraryName(context, property);
985
+ const jsonName = getWireName(context, property);
980
986
 
981
987
  if (property.model) {
982
988
  getType(context, property.model, { usage });
@@ -1030,9 +1036,7 @@ function emitModel(
1030
1036
  }
1031
1037
  const effectiveName = getEffectiveSchemaType(context.program, type).name;
1032
1038
  const overridedModelName =
1033
- getProjectedName(context.program, type, "javascript") ??
1034
- getProjectedName(context.program, type, "client") ??
1035
- getFriendlyName(context.program, type);
1039
+ getLibraryName(context, type) ?? getFriendlyName(context.program, type);
1036
1040
  const fullNamespaceName =
1037
1041
  getModelNamespaceName(context, type.namespace!)
1038
1042
  .map((nsName) => {
@@ -1041,12 +1045,13 @@ function emitModel(
1041
1045
  .join("") +
1042
1046
  (effectiveName ? effectiveName : getName(context.program, type));
1043
1047
  let modelName =
1044
- overridedModelName ??
1045
- (context.rlcOptions?.enableModelNamespace
1046
- ? fullNamespaceName
1047
- : effectiveName
1048
- ? effectiveName
1049
- : getName(context.program, type));
1048
+ overridedModelName !== type.name
1049
+ ? overridedModelName
1050
+ : context.rlcOptions?.enableModelNamespace
1051
+ ? fullNamespaceName
1052
+ : effectiveName
1053
+ ? effectiveName
1054
+ : getName(context.program, type);
1050
1055
  if (
1051
1056
  !overridedModelName &&
1052
1057
  type.templateMapper &&
@@ -1097,7 +1102,8 @@ function enumName(name: string): string {
1097
1102
  return applyCasing(name, { casing: CASING }).toUpperCase();
1098
1103
  }
1099
1104
 
1100
- function emitEnum(program: Program, type: Enum): Record<string, any> {
1105
+ function emitEnum(context: SdkContext, type: Enum): Record<string, any> {
1106
+ const program = context.program;
1101
1107
  const enumValues = [];
1102
1108
  for (const m of type.members.values()) {
1103
1109
  enumValues.push({
@@ -1109,7 +1115,9 @@ function emitEnum(program: Program, type: Enum): Record<string, any> {
1109
1115
 
1110
1116
  return {
1111
1117
  type: "enum",
1112
- name: type.name,
1118
+ name: getLibraryName(context, type)
1119
+ ? getLibraryName(context, type)
1120
+ : type.name,
1113
1121
  description: getDocStr(program, type),
1114
1122
  valueType: { type: enumMemberType(type.members.values().next().value) },
1115
1123
  values: enumValues,
@@ -1373,18 +1381,45 @@ function mapTypeSpecType(
1373
1381
  }
1374
1382
  }
1375
1383
 
1384
+ function isExtensibleEnum(context: SdkContext, type: Enum): boolean {
1385
+ if (isFixed(context.program, type)) {
1386
+ return false;
1387
+ }
1388
+
1389
+ if (context.rlcOptions?.flavor === "azure") {
1390
+ return true;
1391
+ }
1392
+
1393
+ return false;
1394
+ }
1395
+
1376
1396
  function emitUnion(
1377
1397
  context: SdkContext,
1378
1398
  type: Union,
1379
1399
  usage: UsageFlags
1380
1400
  ): Record<string, any> {
1401
+ let isVariantExtensible = false;
1402
+
1403
+ /**
1404
+ * This is a temporary workaround to handle TCGC reporting incorrect isFixed for Unions with Enum variants
1405
+ */
1406
+ for (const [_, variant] of type.variants) {
1407
+ if (variant.type.kind === "Enum") {
1408
+ if (isExtensibleEnum(context, variant.type)) {
1409
+ isVariantExtensible = true;
1410
+ break;
1411
+ }
1412
+ }
1413
+ }
1381
1414
  const sdkType = getSdkUnion(context, type);
1382
1415
  const nonNullOptions = getNonNullOptions(type);
1383
1416
  if (sdkType === undefined) {
1384
1417
  throw Error("Should not have an empty union");
1385
1418
  }
1386
1419
  if (sdkType.kind === "union") {
1387
- const unionName = type.name;
1420
+ const unionName = getLibraryName(context, type)
1421
+ ? getLibraryName(context, type)
1422
+ : type.name;
1388
1423
  const discriminatorPropertyName = getDiscriminator(context.program, type)
1389
1424
  ?.propertyName;
1390
1425
  const variantTypes = sdkType.values.map((x) => {
@@ -1415,14 +1450,16 @@ function emitUnion(
1415
1450
  };
1416
1451
  } else if (sdkType.kind === "enum") {
1417
1452
  return {
1418
- name: sdkType.name,
1453
+ name: getLibraryName(context, type)
1454
+ ? getLibraryName(context, type)
1455
+ : type.name ?? sdkType.name,
1419
1456
  nullable: sdkType.nullable,
1420
1457
  description: sdkType.description || `Type of ${sdkType.name}`,
1421
1458
  internal: true,
1422
1459
  type: sdkType.kind,
1423
1460
  valueType: emitSimpleType(context, sdkType.valueType as SdkBuiltInType),
1424
1461
  values: sdkType.values.map((x) => emitEnumMember(context, x)),
1425
- isFixed: sdkType.isFixed,
1462
+ isFixed: isVariantExtensible ? false : sdkType.isFixed,
1426
1463
  xmlMetadata: {},
1427
1464
  usage
1428
1465
  };
@@ -1536,9 +1573,9 @@ function emitType(
1536
1573
  case "Union":
1537
1574
  return emitUnion(context, type, usage);
1538
1575
  case "UnionVariant":
1539
- return {};
1576
+ return emitType(context, type.type, usage);
1540
1577
  case "Enum":
1541
- return emitEnum(context.program, type);
1578
+ return emitEnum(context, type);
1542
1579
  case "EnumMember":
1543
1580
  return emitEnumMember(context, type);
1544
1581
  default:
@@ -1565,10 +1602,11 @@ function emitOperationGroups(
1565
1602
  }
1566
1603
  for (const operationGroup of listOperationGroups(context, client, true)) {
1567
1604
  const operations: HrlcOperation[] = [];
1605
+ const overrideName = getLibraryName(context, operationGroup.type);
1568
1606
  const name =
1569
1607
  context.rlcOptions?.hierarchyClient ||
1570
1608
  context.rlcOptions?.enableOperationGroup
1571
- ? operationGroup.type.name
1609
+ ? overrideName ?? operationGroup.type.name
1572
1610
  : "";
1573
1611
  const hierarchies =
1574
1612
  context.rlcOptions?.hierarchyClient ||
@@ -1815,7 +1853,10 @@ function emitClients(
1815
1853
  const clients = listClients(context);
1816
1854
  const retval: HrlcClient[] = [];
1817
1855
  for (const client of clients) {
1818
- const clientName = client.name.replace("Client", "");
1856
+ const clientName = getLibraryName(context, client.type).replace(
1857
+ "Client",
1858
+ ""
1859
+ );
1819
1860
  if (getNamespace(context, client.name) !== namespace) {
1820
1861
  continue;
1821
1862
  }
@@ -1885,7 +1926,7 @@ export function emitCodeModel(
1885
1926
  clients: [],
1886
1927
  types: [],
1887
1928
  project,
1888
- runtimeImports: buildRuntimeImports(dpgContext.rlcOptions?.branded ?? true)
1929
+ runtimeImports: buildRuntimeImports(dpgContext.rlcOptions?.flavor)
1889
1930
  };
1890
1931
 
1891
1932
  typesMap.clear();
@@ -86,14 +86,14 @@ function buildExportsForMultiClient(
86
86
 
87
87
  // Prepare package info without scripts and devDependencies and dependencies ect
88
88
  function initPackageInfo(codeModel: ModularCodeModel) {
89
- const { packageDetails, generateTest, branded } = codeModel.options;
89
+ const { packageDetails, generateTest, flavor } = codeModel.options;
90
90
  const description = packageDetails!.description
91
91
  ? packageDetails!.description
92
92
  : `A generated SDK for ${codeModel.clients[0]?.name}.`;
93
93
  const packageInfo = {
94
94
  name: `${packageDetails!.name}`,
95
95
  "sdk-type": "client",
96
- ...(branded
96
+ ...(flavor === "azure"
97
97
  ? {
98
98
  author: "Microsoft Corporation"
99
99
  }
@@ -102,7 +102,7 @@ function initPackageInfo(codeModel: ModularCodeModel) {
102
102
  description,
103
103
  keywords: [
104
104
  "node",
105
- ...(branded ? ["azure", "cloud"] : []),
105
+ ...(flavor === "azure" ? ["azure", "cloud"] : []),
106
106
  "typescript",
107
107
  "browser",
108
108
  "isomorphic"
@@ -127,7 +127,7 @@ function initPackageInfo(codeModel: ModularCodeModel) {
127
127
  import: "./dist-esm/src/models/index.js"
128
128
  }
129
129
  },
130
- ...(branded
130
+ ...(flavor === "azure"
131
131
  ? {
132
132
  repository: "github:Azure/azure-sdk-for-js",
133
133
  bugs: {
@@ -137,7 +137,7 @@ function initPackageInfo(codeModel: ModularCodeModel) {
137
137
  : {}),
138
138
  files: [
139
139
  "dist/",
140
- generateTest && branded ? "dist-esm/src/" : "dist-esm/",
140
+ generateTest && flavor === "azure" ? "dist-esm/src/" : "dist-esm/",
141
141
  `types/${packageDetails!.nameWithoutScope}.d.ts`,
142
142
  "README.md",
143
143
  "LICENSE",
@@ -163,10 +163,10 @@ export function emitPackage(
163
163
  overwrite: true
164
164
  }
165
165
  );
166
- const branded = codeModel.options.branded ?? true;
167
- const packageInfo = branded
168
- ? emitBrandedPackage(codeModel)
169
- : emitNonBrandedPackage(codeModel);
166
+ const packageInfo =
167
+ codeModel.options?.flavor === "azure"
168
+ ? emitBrandedPackage(codeModel)
169
+ : emitNonBrandedPackage(codeModel);
170
170
  packageJsonFile.addStatements(JSON.stringify(packageInfo));
171
171
  return packageJsonFile;
172
172
  }
@@ -505,21 +505,21 @@ export function emitTsConfig(
505
505
 
506
506
  const { packageDetails, azureSdkForJs } = codeModel.options || {};
507
507
  const { generateTest, generateSample } = codeModel.options || {};
508
- const isBranded = codeModel.options?.branded ?? true;
508
+ const isAzureFlavor = codeModel.options?.flavor === "azure";
509
509
  // Take the undefined as true by default
510
510
  const clientPackageName = packageDetails!.name;
511
511
  const tsConfig = (
512
- !isBranded
512
+ !isAzureFlavor
513
513
  ? modularTsConfigNotInSDKRepo
514
514
  : azureSdkForJs
515
515
  ? modularTsConfigInSDKRepo
516
516
  : modularTsConfigNotInSDKRepo
517
517
  ) as any;
518
518
 
519
- if (generateTest && isBranded) {
519
+ if (generateTest && isAzureFlavor) {
520
520
  tsConfig.include.push("./test/**/*.ts");
521
521
  }
522
- if (generateSample && isBranded) {
522
+ if (generateSample && isAzureFlavor) {
523
523
  tsConfig.include.push("samples-dev/**/*.ts");
524
524
  tsConfig.compilerOptions["paths"] = {};
525
525
  tsConfig.compilerOptions["paths"][clientPackageName] = ["./src/index"];
@@ -132,7 +132,8 @@ export function buildModels(
132
132
  ): SourceFile | undefined {
133
133
  // We are generating both models and enums here
134
134
  const coreClientTypes = new Set<string>();
135
- const models = extractModels(codeModel);
135
+ // filter out the models/enums that are anonymous
136
+ const models = extractModels(codeModel).filter((m) => !!m.name);
136
137
  const aliases = extractAliases(codeModel);
137
138
  // Skip to generate models.ts if there is no any models
138
139
  if (models.length === 0 && aliases.length === 0) {
@@ -145,17 +146,13 @@ export function buildModels(
145
146
 
146
147
  for (const model of models) {
147
148
  if (model.type === "enum") {
148
- if (!model.name || modelsFile.getTypeAlias(model.name!)) {
149
+ if (modelsFile.getTypeAlias(model.name!)) {
149
150
  // If the enum is already defined, we don't need to do anything
150
- // If the enum is anonymous, we don't build any type alias for it
151
151
  continue;
152
152
  }
153
153
  const enumAlias = buildEnumModel(model);
154
154
  modelsFile.addTypeAlias(enumAlias);
155
155
  } else {
156
- if (!model.name) {
157
- continue;
158
- }
159
156
  const modelInterface = buildModelInterface(model, { coreClientTypes });
160
157
  model.type === "model"
161
158
  ? model.parents?.forEach((p) =>
@@ -78,7 +78,11 @@ export function getClassicalOperation(
78
78
  type: `(${d.parameters
79
79
  ?.filter((p) => p.name !== "context")
80
80
  .map(
81
- (p) => p.name + (p.name === "options" ? "?" : "") + ": " + p.type
81
+ (p) =>
82
+ p.name +
83
+ (p.name === "options" || p.hasQuestionToken ? "?" : "") +
84
+ ": " +
85
+ p.type
82
86
  )
83
87
  .join(",")}) => ${d.returnType}`
84
88
  });
@@ -116,7 +120,10 @@ export function getClassicalOperation(
116
120
  ?.filter((p) => p.name !== "context")
117
121
  .map(
118
122
  (p) =>
119
- p.name + (p.name === "options" ? "?" : "") + ": " + p.type
123
+ p.name +
124
+ (p.name === "options" || p.hasQuestionToken ? "?" : "") +
125
+ ": " +
126
+ p.type
120
127
  )
121
128
  .join(",")}) => ${d.name}(${[
122
129
  "context",