@azure-tools/typespec-ts 0.42.1 → 0.43.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 (55) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +6 -7
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/lib.d.ts +10 -1
  6. package/dist/src/lib.d.ts.map +1 -1
  7. package/dist/src/lib.js +7 -1
  8. package/dist/src/lib.js.map +1 -1
  9. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  10. package/dist/src/modular/buildClientContext.js.map +1 -1
  11. package/dist/src/modular/emitModels.d.ts +1 -1
  12. package/dist/src/modular/emitModels.d.ts.map +1 -1
  13. package/dist/src/modular/emitModels.js +4 -4
  14. package/dist/src/modular/emitModels.js.map +1 -1
  15. package/dist/src/modular/helpers/clientHelpers.d.ts +4 -3
  16. package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
  17. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  18. package/dist/src/modular/helpers/operationHelpers.d.ts +5 -5
  19. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  20. package/dist/src/modular/helpers/operationHelpers.js +11 -14
  21. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  22. package/dist/src/modular/helpers/typeHelpers.d.ts +2 -2
  23. package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
  24. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  25. package/dist/src/modular/serialization/buildDeserializerFunction.js +2 -2
  26. package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -1
  27. package/dist/src/modular/serialization/buildSerializerFunction.js +15 -14
  28. package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
  29. package/dist/src/modular/type-expressions/get-type-expression.d.ts +2 -2
  30. package/dist/src/modular/type-expressions/get-type-expression.d.ts.map +1 -1
  31. package/dist/src/modular/type-expressions/get-type-expression.js.map +1 -1
  32. package/dist/src/transform/transformHelperFunctionDetails.d.ts +0 -2
  33. package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
  34. package/dist/src/transform/transformHelperFunctionDetails.js +11 -68
  35. package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
  36. package/dist/src/utils/operationUtil.d.ts +5 -0
  37. package/dist/src/utils/operationUtil.d.ts.map +1 -1
  38. package/dist/src/utils/operationUtil.js +91 -5
  39. package/dist/src/utils/operationUtil.js.map +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +24 -24
  42. package/src/index.ts +3 -8
  43. package/src/lib.ts +7 -1
  44. package/src/modular/buildClientContext.ts +8 -2
  45. package/src/modular/emitModels.ts +9 -7
  46. package/src/modular/helpers/clientHelpers.ts +18 -15
  47. package/src/modular/helpers/operationHelpers.ts +30 -28
  48. package/src/modular/helpers/typeHelpers.ts +4 -2
  49. package/src/modular/serialization/buildDeserializerFunction.ts +2 -2
  50. package/src/modular/serialization/buildSerializerFunction.ts +14 -13
  51. package/src/modular/type-expressions/get-type-expression.ts +2 -1
  52. package/src/transform/transformHelperFunctionDetails.ts +12 -76
  53. package/src/utils/operationUtil.ts +126 -6
  54. package/static/static-helpers/serialization/serialize-record.ts +1 -1
  55. package/static/static-helpers/urlTemplate.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-ts",
3
- "version": "0.42.1",
3
+ "version": "0.43.0",
4
4
  "description": "An experimental TypeSpec emitter for TypeScript RLC",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
@@ -18,15 +18,15 @@
18
18
  "license": "MIT",
19
19
  "devDependencies": {
20
20
  "@azure-rest/core-client": "^2.3.1",
21
- "@typespec/http-specs": "0.1.0-alpha.25-dev.0",
22
- "@typespec/spector": "0.1.0-alpha.16-dev.2",
23
- "@typespec/spec-api": "0.1.0-alpha.8-dev.0",
24
- "@typespec/tspd": "0.70.0",
25
- "@azure-tools/azure-http-specs": "0.1.0-alpha.24-dev.0",
26
- "@azure-tools/typespec-autorest": "^0.58.0",
27
- "@azure-tools/typespec-azure-core": "^0.58.0",
28
- "@azure-tools/typespec-azure-resource-manager": "^0.58.0",
29
- "@azure-tools/typespec-client-generator-core": "^0.58.0",
21
+ "@typespec/http-specs": "0.1.0-alpha.26-dev.0",
22
+ "@typespec/spector": "0.1.0-alpha.18-dev.0",
23
+ "@typespec/spec-api": "0.1.0-alpha.9-dev.0",
24
+ "@typespec/tspd": "0.72.1",
25
+ "@azure-tools/azure-http-specs": "0.1.0-alpha.26-dev.1",
26
+ "@azure-tools/typespec-autorest": "^0.59.0",
27
+ "@azure-tools/typespec-azure-core": "^0.59.0",
28
+ "@azure-tools/typespec-azure-resource-manager": "^0.59.0",
29
+ "@azure-tools/typespec-client-generator-core": "^0.59.0",
30
30
  "@azure/abort-controller": "^2.1.2",
31
31
  "@azure/core-auth": "^1.6.0",
32
32
  "@azure/core-lro": "^3.1.0",
@@ -41,12 +41,12 @@
41
41
  "@types/node": "^18.0.0",
42
42
  "@typescript-eslint/eslint-plugin": "^8.28.0",
43
43
  "@typescript-eslint/parser": "^8.28.0",
44
- "@typespec/compiler": "^1.2.1",
45
- "@typespec/http": "^1.2.1",
46
- "@typespec/openapi": "^1.2.1",
47
- "@typespec/rest": "^0.72.1",
44
+ "@typespec/compiler": "^1.3.0",
45
+ "@typespec/http": "^1.3.0",
46
+ "@typespec/openapi": "^1.3.0",
47
+ "@typespec/rest": "^0.73.0",
48
48
  "@typespec/ts-http-runtime": "^0.1.0",
49
- "@typespec/versioning": "^0.72.1",
49
+ "@typespec/versioning": "^0.73.0",
50
50
  "chai": "^4.3.6",
51
51
  "chalk": "^4.0.0",
52
52
  "cross-env": "^7.0.3",
@@ -68,16 +68,16 @@
68
68
  "js-yaml": "^4.1.0"
69
69
  },
70
70
  "peerDependencies": {
71
- "@azure-tools/typespec-azure-core": "^0.58.0",
72
- "@azure-tools/typespec-client-generator-core": "^0.58.0",
73
- "@typespec/compiler": "^1.2.1",
74
- "@typespec/http": "^1.2.1",
75
- "@typespec/rest": "^0.72.1",
76
- "@typespec/versioning": "^0.72.1",
77
- "@typespec/xml": "^0.72.1"
71
+ "@azure-tools/typespec-azure-core": "^0.59.0",
72
+ "@azure-tools/typespec-client-generator-core": "^0.59.0",
73
+ "@typespec/compiler": "^1.3.0",
74
+ "@typespec/http": "^1.3.0",
75
+ "@typespec/rest": "^0.73.0",
76
+ "@typespec/versioning": "^0.73.0",
77
+ "@typespec/xml": "^0.73.0"
78
78
  },
79
79
  "dependencies": {
80
- "@azure-tools/rlc-common": "^0.42.1",
80
+ "@azure-tools/rlc-common": "^0.43.0",
81
81
  "fs-extra": "^11.1.0",
82
82
  "lodash": "^4.17.21",
83
83
  "prettier": "^3.3.3",
@@ -146,7 +146,7 @@
146
146
  "stop-test-server": "npx tsp-spector server stop",
147
147
  "unit-test": "npm-run-all --parallel unit-test:rlc unit-test:modular",
148
148
  "unit-test:rlc": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --timeout 36000 './test/unit/**/*.spec.ts'",
149
- "unit-test:modular": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --no-timeout './test/modularUnit/**/*.spec.ts' --reporter-options maxDiffSize=20000",
149
+ "unit-test:modular": "cross-env TS_NODE_PROJECT=tsconfig.test.json NODE_OPTIONS='--max-old-space-size=8192' mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --no-timeout './test/modularUnit/**/*.spec.ts' --reporter-options maxDiffSize=20000",
150
150
  "regen-docs": "npm run build && tspd doc . --enable-experimental --output-dir ./website/src/content/docs/docs/emitters/clients/typespec-ts/reference --skip-js"
151
151
  }
152
152
  }
package/src/index.ts CHANGED
@@ -548,11 +548,9 @@ export async function createContextWithDefaultOptions(
548
548
  context: EmitContext<Record<string, any>>
549
549
  ): Promise<SdkContext> {
550
550
  const flattenUnionAsEnum =
551
- context.options["experimental-extensible-enums"] === undefined &&
552
- context.options["experimentalExtensibleEnums"] === undefined
551
+ context.options["experimental-extensible-enums"] === undefined
553
552
  ? isArm(context)
554
- : (context.options["experimental-extensible-enums"] ??
555
- context.options["experimentalExtensibleEnums"]);
553
+ : context.options["experimental-extensible-enums"];
556
554
  const tcgcSettings = {
557
555
  "generate-protocol-methods": true,
558
556
  "generate-convenience-methods": true,
@@ -579,10 +577,7 @@ export async function createContextWithDefaultOptions(
579
577
 
580
578
  // TODO: should be removed once tcgc issue is resolved https://github.com/Azure/typespec-azure/issues/1794
581
579
  function isArm(context: EmitContext<Record<string, any>>) {
582
- const packageName =
583
- (context?.options["package-details"] ??
584
- context?.options["packageDetails"] ??
585
- {})["name"] ?? "";
580
+ const packageName = (context?.options["package-details"] ?? {})["name"] ?? "";
586
581
  return packageName?.startsWith("@azure/arm-");
587
582
  }
588
583
 
package/src/lib.ts CHANGED
@@ -454,7 +454,13 @@ const libDef = {
454
454
  "no-paging-items-defined": {
455
455
  severity: "warning",
456
456
  messages: {
457
- default: paramMessage`Please specify @items property for the paging operation - ${"operationName"}.`
457
+ default: paramMessage`Operation '${"operationName"}' is marked with @list but does not have @pageItems defined.`
458
+ }
459
+ },
460
+ "un-supported-paging-cases": {
461
+ severity: "warning",
462
+ messages: {
463
+ default: paramMessage`Nested paging items in ${"operationName"} are not supported and will be ignored.`
458
464
  }
459
465
  },
460
466
  "decimal-to-number": {
@@ -26,8 +26,10 @@ import { useDependencies } from "../framework/hooks/useDependencies.js";
26
26
  import { buildEnumTypes, getApiVersionEnum } from "./emitModels.js";
27
27
  import {
28
28
  SdkClientType,
29
+ SdkCredentialParameter,
30
+ SdkEndpointParameter,
29
31
  SdkHttpParameter,
30
- SdkParameter,
32
+ SdkMethodParameter,
31
33
  SdkServiceOperation
32
34
  } from "@azure-tools/typespec-client-generator-core";
33
35
  import { getModularClientOptions } from "../utils/clientUtils.js";
@@ -283,7 +285,11 @@ export function buildClientContext(
283
285
 
284
286
  function getDocsWithKnownVersion(
285
287
  dpgContext: SdkContext,
286
- param: SdkParameter | SdkHttpParameter
288
+ param:
289
+ | SdkMethodParameter
290
+ | SdkEndpointParameter
291
+ | SdkCredentialParameter
292
+ | SdkHttpParameter
287
293
  ) {
288
294
  const docs = getDocsFromDescription(param.doc);
289
295
  if (param.name.toLowerCase() !== "apiversion") {
@@ -15,14 +15,13 @@ import {
15
15
  } from "@azure-tools/rlc-common";
16
16
  import {
17
17
  SdkArrayType,
18
- SdkBodyModelPropertyType,
18
+ SdkModelPropertyType,
19
19
  SdkClientType,
20
20
  SdkDictionaryType,
21
21
  SdkEnumType,
22
22
  SdkEnumValueType,
23
23
  SdkHttpOperation,
24
24
  SdkMethod,
25
- SdkModelPropertyType,
26
25
  SdkModelType,
27
26
  SdkNullableType,
28
27
  SdkServiceMethod,
@@ -504,7 +503,7 @@ function addExtendedDictInfo(
504
503
  : undefined;
505
504
  if (context.rlcOptions?.compatibilityMode) {
506
505
  const ancestors = getAllAncestors(model);
507
- const properties = getAllProperties(model, ancestors);
506
+ const properties = getAllProperties(context, model, ancestors);
508
507
  let anyType = true;
509
508
  if (!additionalPropertiesType) {
510
509
  // case 1: if additionalProperties is not defined, we should use any type
@@ -530,7 +529,7 @@ function addExtendedDictInfo(
530
529
  const additionalPropertiesType = model.additionalProperties
531
530
  ? getTypeExpression(context, model.additionalProperties)
532
531
  : undefined;
533
- const name = getAdditionalPropertiesName(model);
532
+ const name = getAdditionalPropertiesName(context, model);
534
533
  if (name !== "additionalProperties") {
535
534
  // report diagnostic for additionalProperties
536
535
  reportDiagnostic(context.program, {
@@ -554,9 +553,12 @@ function addExtendedDictInfo(
554
553
  }
555
554
  }
556
555
 
557
- export function getAdditionalPropertiesName(model: SdkModelType): string {
556
+ export function getAdditionalPropertiesName(
557
+ context: SdkContext,
558
+ model: SdkModelType
559
+ ): string {
558
560
  const ancestors = getAllAncestors(model);
559
- const properties = getAllProperties(model, ancestors);
561
+ const properties = getAllProperties(context, model, ancestors);
560
562
  const nameConflict = properties.find(
561
563
  (p) => p.name === "additionalProperties"
562
564
  );
@@ -712,7 +714,7 @@ function buildModelProperty(
712
714
  name: normalizedPropName,
713
715
  type: typeExpression,
714
716
  hasQuestionToken: property.optional,
715
- isReadonly: isReadOnly(property as SdkBodyModelPropertyType)
717
+ isReadonly: isReadOnly(property as SdkModelPropertyType)
716
718
  };
717
719
 
718
720
  if (property.doc) {
@@ -6,8 +6,10 @@ import {
6
6
  } from "ts-morph";
7
7
  import {
8
8
  SdkClientType,
9
+ SdkCredentialParameter,
10
+ SdkEndpointParameter,
9
11
  SdkHttpParameter,
10
- SdkParameter,
12
+ SdkMethodParameter,
11
13
  SdkServiceOperation
12
14
  } from "@azure-tools/typespec-client-generator-core";
13
15
 
@@ -32,6 +34,12 @@ interface ClientParameterOptions {
32
34
  apiVersionAsRequired?: boolean;
33
35
  }
34
36
 
37
+ type SdkParameter =
38
+ | SdkMethodParameter
39
+ | SdkEndpointParameter
40
+ | SdkCredentialParameter
41
+ | SdkHttpParameter;
42
+
35
43
  export function getClientParameters(
36
44
  client: SdkClientType<SdkServiceOperation>,
37
45
  dpgContext: SdkContext,
@@ -44,7 +52,7 @@ export function getClientParameters(
44
52
  apiVersionAsRequired: true
45
53
  }
46
54
  ) {
47
- const clientParams: (SdkParameter | SdkHttpParameter)[] = [];
55
+ const clientParams: SdkParameter[] = [];
48
56
  for (const property of client.clientInitialization.parameters) {
49
57
  if (
50
58
  property.type.kind === "union" &&
@@ -62,9 +70,9 @@ export function getClientParameters(
62
70
  }
63
71
  }
64
72
 
65
- const hasDefaultValue = (p: SdkParameter | SdkHttpParameter) =>
73
+ const hasDefaultValue = (p: SdkParameter) =>
66
74
  p.clientDefaultValue || p.__raw?.defaultValue || p.type.kind === "constant";
67
- const isRequired = (p: SdkParameter | SdkHttpParameter) =>
75
+ const isRequired = (p: SdkParameter) =>
68
76
  !p.optional &&
69
77
  ((!hasDefaultValue(p) &&
70
78
  !(
@@ -73,13 +81,10 @@ export function getClientParameters(
73
81
  hasDefaultValue(p.type.templateArguments[0])
74
82
  )) ||
75
83
  (options.apiVersionAsRequired && p.isApiVersionParam));
76
- const isOptional = (p: SdkParameter | SdkHttpParameter) =>
77
- p.optional || hasDefaultValue(p);
78
- const skipCredentials = (p: SdkParameter | SdkHttpParameter) =>
79
- p.kind !== "credential";
80
- const skipMethodParam = (p: SdkParameter | SdkHttpParameter) =>
81
- p.kind !== "method";
82
- const armSpecific = (p: SdkParameter | SdkHttpParameter) =>
84
+ const isOptional = (p: SdkParameter) => p.optional || hasDefaultValue(p);
85
+ const skipCredentials = (p: SdkParameter) => p.kind !== "credential";
86
+ const skipMethodParam = (p: SdkParameter) => p.kind !== "method";
87
+ const armSpecific = (p: SdkParameter) =>
83
88
  !(p.kind === "endpoint" && dpgContext.arm);
84
89
  const filters = [
85
90
  options.requiredOnly ? isRequired : undefined,
@@ -134,7 +139,7 @@ export function getClientParametersDeclaration(
134
139
 
135
140
  function getClientParameterTypeExpression(
136
141
  context: SdkContext,
137
- parameter: SdkParameter | SdkHttpParameter
142
+ parameter: SdkParameter
138
143
  ) {
139
144
  // Special handle to work around the fact that TCGC creates a union type for endpoint. The reason they do this
140
145
  // is to provide a way for users to either pass the value to fill in the template of the whole endpoint. Basically they are
@@ -151,9 +156,7 @@ function getClientParameterTypeExpression(
151
156
  return getTypeExpression(context, parameter.type);
152
157
  }
153
158
 
154
- export function getClientParameterName(
155
- parameter: SdkParameter | SdkHttpParameter
156
- ) {
159
+ export function getClientParameterName(parameter: SdkParameter) {
157
160
  // We have been calling this endpointParam, so special handling this here to make sure there are no unexpected side effects
158
161
  if (
159
162
  (parameter.type.kind === "union" &&
@@ -46,6 +46,7 @@ import {
46
46
  } from "../type-expressions/get-type-expression.js";
47
47
  import { SdkContext } from "../../utils/interfaces.js";
48
48
  import {
49
+ isHttpMetadata,
49
50
  isReadOnly,
50
51
  SdkBodyParameter,
51
52
  SdkClientType,
@@ -55,10 +56,10 @@ import {
55
56
  SdkLroPagingServiceMethod,
56
57
  SdkLroServiceMethod,
57
58
  SdkMethod,
59
+ SdkMethodParameter,
58
60
  SdkModelPropertyType,
59
61
  SdkModelType,
60
62
  SdkPagingServiceMethod,
61
- SdkServiceParameter,
62
63
  SdkType
63
64
  } from "@azure-tools/typespec-client-generator-core";
64
65
  import { isMetadata } from "@typespec/http";
@@ -153,7 +154,7 @@ export function getDeserializePrivateFunction(
153
154
  const response = operation.response;
154
155
  const restResponse = operation.operation.responses[0];
155
156
  let returnType;
156
- if (isLroOnly && operation.operation.verb.toLowerCase() !== "patch") {
157
+ if (isLroOnly) {
157
158
  returnType = buildLroReturnType(context, operation);
158
159
  } else if (response.type && restResponse) {
159
160
  returnType = {
@@ -686,7 +687,7 @@ function getHeaderAndBodyParameters(
686
687
 
687
688
  const parametersImplementation: Record<
688
689
  "header" | "body",
689
- { paramMap: string; param: SdkServiceParameter }[]
690
+ { paramMap: string; param: SdkHttpParameter }[]
690
691
  > = {
691
692
  header: [],
692
693
  body: []
@@ -744,7 +745,7 @@ function getHeaderAndBodyParameters(
744
745
  function buildHeaderParameter(
745
746
  program: Program,
746
747
  paramMap: string,
747
- param: SdkServiceParameter,
748
+ param: SdkHttpParameter,
748
749
  optionalParamName: string = "options"
749
750
  ): string {
750
751
  const paramName = param.name;
@@ -829,7 +830,7 @@ function getEncodingFormat(type: { format?: string }) {
829
830
  */
830
831
  export function getParameterMap(
831
832
  context: SdkContext,
832
- param: SdkServiceParameter,
833
+ param: SdkHttpParameter,
833
834
  optionalParamName: string = "options"
834
835
  ): string {
835
836
  if (isConstant(param.type)) {
@@ -854,7 +855,7 @@ export function getParameterMap(
854
855
 
855
856
  function getCollectionFormat(
856
857
  context: SdkContext,
857
- param: SdkServiceParameter,
858
+ param: SdkHttpParameter,
858
859
  optionalParamName: string = "options"
859
860
  ) {
860
861
  const serializedName = getPropertySerializedName(param);
@@ -887,7 +888,7 @@ function getCollectionFormat(
887
888
  )}${additionalParam}): undefined`;
888
889
  }
889
890
 
890
- function isContentType(param: SdkServiceParameter): boolean {
891
+ function isContentType(param: SdkHttpParameter): boolean {
891
892
  return (
892
893
  param.kind === "header" &&
893
894
  param.serializedName.toLowerCase() === "content-type"
@@ -895,7 +896,7 @@ function isContentType(param: SdkServiceParameter): boolean {
895
896
  }
896
897
 
897
898
  function getContentTypeValue(
898
- param: SdkServiceParameter,
899
+ param: SdkHttpParameter,
899
900
  optionalParamName: string = "options"
900
901
  ) {
901
902
  const defaultValue = param.clientDefaultValue;
@@ -914,11 +915,11 @@ function getContentTypeValue(
914
915
  }
915
916
  }
916
917
 
917
- function isRequired(param: SdkModelPropertyType) {
918
+ function isRequired(param: SdkHttpParameter) {
918
919
  return !param.optional;
919
920
  }
920
921
 
921
- function getRequired(context: SdkContext, param: SdkModelPropertyType) {
922
+ function getRequired(context: SdkContext, param: SdkHttpParameter) {
922
923
  const serializedName = getPropertySerializedName(param);
923
924
  const clientValue = `${param.onClient ? "context." : ""}${param.name}`;
924
925
  if (param.type.kind === "model") {
@@ -950,7 +951,7 @@ function isConstant(param: SdkType): param is SdkConstantType {
950
951
  return param.kind === "constant";
951
952
  }
952
953
 
953
- function isOptional(param: SdkModelPropertyType) {
954
+ function isOptional(param: SdkHttpParameter) {
954
955
  return Boolean(param.optional);
955
956
  }
956
957
 
@@ -1001,7 +1002,7 @@ function getOptionalForType(
1001
1002
  /**
1002
1003
  * Builds the assignment for when a property or parameter has a default value
1003
1004
  */
1004
- function getDefaultValue(param: SdkServiceParameter) {
1005
+ function getDefaultValue(param: SdkHttpParameter) {
1005
1006
  return param.clientDefaultValue;
1006
1007
  }
1007
1008
 
@@ -1043,7 +1044,7 @@ function getQueryParameters(
1043
1044
  );
1044
1045
  const parametersImplementation: Record<
1045
1046
  "query",
1046
- { paramMap: string; param: SdkServiceParameter }[]
1047
+ { paramMap: string; param: SdkHttpParameter }[]
1047
1048
  > = {
1048
1049
  query: []
1049
1050
  };
@@ -1079,7 +1080,7 @@ function escapeUriTemplateParamName(name: string) {
1079
1080
  }
1080
1081
 
1081
1082
  function getPathParamExpr(
1082
- param: SdkModelPropertyType,
1083
+ param: SdkMethodParameter | SdkModelPropertyType,
1083
1084
  defaultValue?: string,
1084
1085
  optionalParamName: string = "options"
1085
1086
  ) {
@@ -1154,7 +1155,7 @@ export function getRequestModelProperties(
1154
1155
  const props: [string, string][] = [];
1155
1156
  const allParents = getAllAncestors(modelPropertyType);
1156
1157
  const properties: SdkModelPropertyType[] =
1157
- getAllProperties(modelPropertyType, allParents) ?? [];
1158
+ getAllProperties(context, modelPropertyType, allParents) ?? [];
1158
1159
  if (properties.length <= 0) {
1159
1160
  return [];
1160
1161
  }
@@ -1191,14 +1192,14 @@ export function getRequestModelMapping(
1191
1192
  ).map(([name, value]) => `"${name}": ${value}`);
1192
1193
  }
1193
1194
 
1194
- function getPropertySerializedName(property: SdkModelPropertyType) {
1195
- return property.kind !== "credential" &&
1196
- property.kind !== "method" &&
1197
- property.kind !== "endpoint" &&
1198
- property.kind !== "responseheader"
1199
- ? // eslint-disable-next-line
1200
- property.serializedName
1201
- : property.name;
1195
+ function getPropertySerializedName(
1196
+ property: SdkHttpParameter | SdkModelPropertyType
1197
+ ) {
1198
+ return (
1199
+ (property.kind === "property"
1200
+ ? property.serializationOptions.json?.name
1201
+ : property.serializedName) ?? property.name
1202
+ );
1202
1203
  }
1203
1204
 
1204
1205
  /**
@@ -1212,7 +1213,7 @@ export function getResponseMapping(
1212
1213
  ) {
1213
1214
  const allParents = type.kind === "model" ? getAllAncestors(type) : [];
1214
1215
  const properties =
1215
- type.kind === "model" ? getAllProperties(type, allParents) : [];
1216
+ type.kind === "model" ? getAllProperties(context, type, allParents) : [];
1216
1217
  const props: string[] = [];
1217
1218
  for (const property of properties) {
1218
1219
  if (isMetadata(context.program, property.__raw!)) {
@@ -1481,6 +1482,7 @@ export function isPagingOnlyOperation(
1481
1482
  }
1482
1483
 
1483
1484
  export function getAllProperties(
1485
+ context: SdkContext,
1484
1486
  type: SdkType,
1485
1487
  parents?: SdkType[]
1486
1488
  ): SdkModelPropertyType[] {
@@ -1489,14 +1491,14 @@ export function getAllProperties(
1489
1491
  return [];
1490
1492
  }
1491
1493
  parents?.forEach((p) => {
1492
- getAllProperties(p).forEach((prop) => {
1494
+ getAllProperties(context, p).forEach((prop) => {
1493
1495
  propertiesMap.set(prop.name, prop);
1494
1496
  });
1495
1497
  });
1496
1498
  if (type.kind === "model" && type.properties) {
1497
1499
  type.properties
1498
1500
  .filter((p) => {
1499
- return p.kind === "property";
1501
+ return p.kind === "property" && !isHttpMetadata(context, p);
1500
1502
  })
1501
1503
  .forEach((p) => {
1502
1504
  propertiesMap.set(p.name, p);
@@ -1517,7 +1519,7 @@ export function getAllAncestors(type: SdkType): SdkType[] {
1517
1519
 
1518
1520
  export function getPropertySerializationPrefix(
1519
1521
  context: SdkContext,
1520
- property: SdkServiceParameter | SdkModelPropertyType,
1522
+ property: SdkHttpParameter | SdkModelPropertyType,
1521
1523
  propertyPath?: string
1522
1524
  ) {
1523
1525
  const propertyFullName = getPropertyFullName(context, property, propertyPath);
@@ -1530,7 +1532,7 @@ export function getPropertySerializationPrefix(
1530
1532
 
1531
1533
  export function getPropertyFullName(
1532
1534
  context: SdkContext,
1533
- property: SdkServiceParameter | SdkModelPropertyType,
1535
+ property: SdkHttpParameter | SdkModelPropertyType,
1534
1536
  propertyPath?: string
1535
1537
  ) {
1536
1538
  const normalizedPropertyName = normalizeModelPropertyName(context, property)
@@ -1,7 +1,9 @@
1
1
  import { NameType, normalizeName } from "@azure-tools/rlc-common";
2
2
  import {
3
3
  SdkBodyParameter,
4
- SdkModelPropertyType,
4
+ SdkCredentialParameter,
5
+ SdkEndpointParameter,
6
+ SdkMethodParameter,
5
7
  SdkType
6
8
  } from "@azure-tools/typespec-client-generator-core";
7
9
 
@@ -71,7 +73,7 @@ export function isDateTimeTypeKind(kind: string): boolean {
71
73
  }
72
74
 
73
75
  export function isCredentialType(
74
- type: SdkType | SdkModelPropertyType
76
+ type: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter
75
77
  ): boolean {
76
78
  return type.kind === "credential";
77
79
  }
@@ -366,7 +366,7 @@ function getAdditionalPropertiesStatement(
366
366
  return undefined;
367
367
  }
368
368
  const allParents = getAllAncestors(type);
369
- const properties = getAllProperties(type, allParents);
369
+ const properties = getAllProperties(context, type, allParents);
370
370
  const excludeProperties = properties
371
371
  .filter((p) => !!p.name)
372
372
  .map((p) => `"${p.name}"`);
@@ -383,7 +383,7 @@ function getAdditionalPropertiesStatement(
383
383
  }
384
384
  return context.rlcOptions?.compatibilityMode === true
385
385
  ? "...item,"
386
- : `${getAdditionalPropertiesName(type)}: ${resolveReference(SerializationHelpers.serializeRecord)}(${params.join(",")}),`;
386
+ : `${getAdditionalPropertiesName(context, type)}: ${resolveReference(SerializationHelpers.serializeRecord)}(${params.join(",")}),`;
387
387
  }
388
388
 
389
389
  function buildDictTypeDeserializer(
@@ -345,7 +345,7 @@ function buildModelTypeSerializer(
345
345
  // TODO: cleaner abstraction, quite a bit of duplication with the non-MFD stuff here
346
346
  const parts: string[] = [];
347
347
 
348
- const properties = getAllProperties(type, getAllAncestors(type));
348
+ const properties = getAllProperties(context, type, getAllAncestors(type));
349
349
  for (const property of properties) {
350
350
  if (property.kind !== "property") {
351
351
  continue;
@@ -354,35 +354,36 @@ function buildModelTypeSerializer(
354
354
 
355
355
  let partDefinition: string;
356
356
  // eslint-disable-next-line
357
- if (property.isMultipartFileInput) {
357
+ const multipart = property.serializationOptions.multipart;
358
+ if (multipart?.isFilePart) {
358
359
  const createFilePartDescriptorDefinition = resolveReference(
359
360
  MultipartHelpers.createFilePartDescriptor
360
361
  );
361
362
  // eslint-disable-next-line
362
- const itemPath = property.multipartOptions?.isMulti
363
+ const itemPath = multipart.isMulti
363
364
  ? "x"
364
365
  : getPropertyFullName(context, property, "item");
365
366
  /* eslint-disable */
366
- partDefinition = `${createFilePartDescriptorDefinition}("${property.serializedName}", ${itemPath}, )`;
367
+ partDefinition = `${createFilePartDescriptorDefinition}("${multipart.name}", ${itemPath}, )`;
367
368
 
368
369
  // If the TypeSpec doesn't specify a default content type, TCGC will infer a default of "*/*".
369
370
  // In this case, we actually want the content type to be left unset so that Core will take care of
370
371
  // setting the content type correctly.
371
372
  // eslint-disable
372
373
  const contentType =
373
- property.multipartOptions?.defaultContentTypes?.[0] === "*/*"
374
+ multipart.defaultContentTypes?.[0] === "*/*"
374
375
  ? undefined
375
- : property.multipartOptions?.defaultContentTypes?.[0];
376
+ : multipart.defaultContentTypes?.[0];
376
377
 
377
- if (property.multipartOptions?.isMulti) {
378
- partDefinition = `...(item["${property.serializedName}"].map((x: unknown) => ${createFilePartDescriptorDefinition}("${property.serializedName}", x${contentType ? `,"${contentType}"` : ""})))`;
378
+ if (multipart.isMulti) {
379
+ partDefinition = `...(item["${multipart.name}"].map((x: unknown) => ${createFilePartDescriptorDefinition}("${multipart.name}", x${contentType ? `,"${contentType}"` : ""})))`;
379
380
  } else {
380
- partDefinition = `${createFilePartDescriptorDefinition}("${property.serializedName}", item["${property.serializedName}"]${contentType ? `, "${contentType}"` : ""})`;
381
+ partDefinition = `${createFilePartDescriptorDefinition}("${multipart.name}", item["${multipart.name}"]${contentType ? `, "${contentType}"` : ""})`;
381
382
  }
382
- } else if (property.multipartOptions?.isMulti) {
383
- partDefinition = `...((${expr}).map((x: unknown) => ({ name: "${property.serializedName}", body: x })))`;
383
+ } else if (multipart?.isMulti) {
384
+ partDefinition = `...((${expr}).map((x: unknown) => ({ name: "${multipart?.name}", body: x })))`;
384
385
  } else {
385
- partDefinition = `{ name: "${property.serializedName}", body: (${expr}) }`;
386
+ partDefinition = `{ name: "${multipart?.name}", body: (${expr}) }`;
386
387
  }
387
388
  /* eslint-disable */
388
389
  if (property.optional) {
@@ -441,7 +442,7 @@ function getAdditionalPropertiesStatement(
441
442
  false,
442
443
  true
443
444
  );
444
- const params = [`item.${getAdditionalPropertiesName(type)}`];
445
+ const params = [`item.${getAdditionalPropertiesName(context, type)}`];
445
446
  if (typeof deserializerFunction === "string") {
446
447
  params.push("undefined");
447
448
  params.push(deserializerFunction);
@@ -1,4 +1,5 @@
1
1
  import {
2
+ SdkHttpParameter,
2
3
  SdkModelPropertyType,
3
4
  SdkType
4
5
  } from "@azure-tools/typespec-client-generator-core";
@@ -16,7 +17,7 @@ export interface EmitTypeOptions {
16
17
 
17
18
  export function normalizeModelPropertyName(
18
19
  context: SdkContext,
19
- property: SdkModelPropertyType
20
+ property: SdkModelPropertyType | SdkHttpParameter
20
21
  ): string {
21
22
  const normalizedPropName = normalizeName(property.name, NameType.Property);
22
23
  return context.rlcOptions?.ignorePropertyNameNormalize