@azure-tools/typespec-ts 0.12.0-alpha.20230502.1 → 0.13.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 (135) hide show
  1. package/.rush/temp/operation/build/all.log +1 -0
  2. package/.rush/temp/operation/build/state.json +3 -0
  3. package/.rush/temp/package-deps_build.json +104 -78
  4. package/.rush/temp/shrinkwrap-deps.json +488 -471
  5. package/CHANGELOG.md +7 -0
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/index.js +2 -1
  8. package/dist/src/index.js.map +1 -1
  9. package/dist/src/modelUtils.d.ts +1 -1
  10. package/dist/src/modelUtils.d.ts.map +1 -1
  11. package/dist/src/modelUtils.js +79 -56
  12. package/dist/src/modelUtils.js.map +1 -1
  13. package/dist/src/operationUtil.d.ts.map +1 -1
  14. package/dist/src/operationUtil.js +7 -6
  15. package/dist/src/operationUtil.js.map +1 -1
  16. package/dist/src/transform/transform.d.ts.map +1 -1
  17. package/dist/src/transform/transform.js +3 -3
  18. package/dist/src/transform/transform.js.map +1 -1
  19. package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
  20. package/dist/src/transform/transformApiVersionInfo.js +3 -3
  21. package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
  22. package/dist/src/transform/transformParameters.d.ts.map +1 -1
  23. package/dist/src/transform/transformParameters.js +23 -29
  24. package/dist/src/transform/transformParameters.js.map +1 -1
  25. package/dist/src/transform/transformPaths.d.ts.map +1 -1
  26. package/dist/src/transform/transformPaths.js +5 -5
  27. package/dist/src/transform/transformPaths.js.map +1 -1
  28. package/dist/src/transform/transformResponses.js +6 -6
  29. package/dist/src/transform/transformResponses.js.map +1 -1
  30. package/dist/src/transform/transformSchemas.js +1 -1
  31. package/dist/src/transform/transformSchemas.js.map +1 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +41 -39
  34. package/src/index.ts +2 -0
  35. package/src/modelUtils.ts +143 -47
  36. package/src/operationUtil.ts +4 -3
  37. package/src/transform/transform.ts +10 -2
  38. package/src/transform/transformApiVersionInfo.ts +18 -3
  39. package/src/transform/transformParameters.ts +51 -16
  40. package/src/transform/transformPaths.ts +10 -5
  41. package/src/transform/transformResponses.ts +6 -4
  42. package/src/transform/transformSchemas.ts +1 -1
  43. package/test/integration/azurecore.spec.ts +51 -11
  44. package/test/integration/generated/arrays/itemTypes/src/arrayItemTypesClient.ts +5 -1
  45. package/test/integration/generated/arrays/itemTypes/src/logger.ts +5 -0
  46. package/test/integration/generated/authentication/apiKey/package.json +1 -1
  47. package/test/integration/generated/authentication/apiKey/src/authApiKeyClient.ts +6 -2
  48. package/test/integration/generated/authentication/apiKey/src/logger.ts +5 -0
  49. package/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts +6 -2
  50. package/test/integration/generated/authentication/oauth2/src/logger.ts +5 -0
  51. package/test/integration/generated/authentication/union/src/authUnionClient.ts +6 -2
  52. package/test/integration/generated/authentication/union/src/logger.ts +5 -0
  53. package/test/integration/generated/azure/core/package.json +1 -1
  54. package/test/integration/generated/azure/core/src/azureCoreClient.ts +5 -1
  55. package/test/integration/generated/azure/core/src/logger.ts +5 -0
  56. package/test/integration/generated/azure/core/src/outputModels.ts +7 -1
  57. package/test/integration/generated/azure/core-traits/package.json +1 -1
  58. package/test/integration/generated/azure/core-traits/src/azureCoreTraitsClient.ts +5 -1
  59. package/test/integration/generated/azure/core-traits/src/logger.ts +5 -0
  60. package/test/integration/generated/azure/core-traits/src/outputModels.ts +15 -0
  61. package/test/integration/generated/dictionary/package.json +1 -1
  62. package/test/integration/generated/dictionary/src/dictClient.ts +5 -1
  63. package/test/integration/generated/dictionary/src/logger.ts +5 -0
  64. package/test/integration/generated/enums/extensible/package.json +1 -1
  65. package/test/integration/generated/enums/extensible/src/logger.ts +5 -0
  66. package/test/integration/generated/enums/extensible/src/typeEnumExtensible.ts +5 -1
  67. package/test/integration/generated/enums/fixed/package.json +1 -1
  68. package/test/integration/generated/enums/fixed/src/logger.ts +5 -0
  69. package/test/integration/generated/enums/fixed/src/typeEnumFixed.ts +5 -1
  70. package/test/integration/generated/internal/src/clientDefinitions.ts +38 -12
  71. package/test/integration/generated/internal/src/index.ts +0 -1
  72. package/test/integration/generated/internal/src/internalClient.ts +5 -1
  73. package/test/integration/generated/internal/src/logger.ts +5 -0
  74. package/test/integration/generated/internal/src/outputModels.ts +9 -5
  75. package/test/integration/generated/internal/src/parameters.ts +32 -8
  76. package/test/integration/generated/internal/src/responses.ts +18 -5
  77. package/test/integration/generated/lro/lroCore/package.json +2 -2
  78. package/test/integration/generated/lro/lroCore/src/logger.ts +5 -0
  79. package/test/integration/generated/lro/lroCore/src/specsAzureCoreLroStandard.ts +5 -1
  80. package/test/integration/generated/lro/lroRPC/package.json +2 -2
  81. package/test/integration/generated/lro/lroRPC/src/logger.ts +5 -0
  82. package/test/integration/generated/lro/lroRPC/src/specsAzureCoreLroRpc.ts +5 -1
  83. package/test/integration/generated/models/inheritance/package.json +1 -1
  84. package/test/integration/generated/models/inheritance/src/logger.ts +5 -0
  85. package/test/integration/generated/models/inheritance/src/typeModelInheritance.ts +5 -1
  86. package/test/integration/generated/models/propertyNullable/package.json +1 -1
  87. package/test/integration/generated/models/propertyNullable/src/logger.ts +5 -0
  88. package/test/integration/generated/models/propertyNullable/src/typePropertyNullable.ts +5 -1
  89. package/test/integration/generated/models/propertyOptional/package.json +1 -1
  90. package/test/integration/generated/models/propertyOptional/src/logger.ts +5 -0
  91. package/test/integration/generated/models/propertyOptional/src/typePropertyOptional.ts +5 -1
  92. package/test/integration/generated/models/propertyTypes/package.json +1 -1
  93. package/test/integration/generated/models/propertyTypes/src/clientDefinitions.ts +68 -0
  94. package/test/integration/generated/models/propertyTypes/src/logger.ts +5 -0
  95. package/test/integration/generated/models/propertyTypes/src/models.ts +24 -0
  96. package/test/integration/generated/models/propertyTypes/src/outputModels.ts +24 -0
  97. package/test/integration/generated/models/propertyTypes/src/parameters.ts +40 -0
  98. package/test/integration/generated/models/propertyTypes/src/responses.ts +48 -0
  99. package/test/integration/generated/models/propertyTypes/src/typePropertyValueTypes.ts +5 -1
  100. package/test/integration/generated/models/usage/package.json +1 -1
  101. package/test/integration/generated/models/usage/src/logger.ts +5 -0
  102. package/test/integration/generated/models/usage/src/typeModelUsage.ts +5 -1
  103. package/test/integration/generated/models/visibility/package.json +1 -1
  104. package/test/integration/generated/models/visibility/src/logger.ts +5 -0
  105. package/test/integration/generated/models/visibility/src/typeModelVisibility.ts +5 -1
  106. package/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts +5 -1
  107. package/test/integration/generated/parameters/collection-format/src/logger.ts +5 -0
  108. package/test/integration/generated/parameters/spread/src/logger.ts +5 -0
  109. package/test/integration/generated/parameters/spread/src/parametersSpread.ts +5 -1
  110. package/test/integration/generated/projection/src/logger.ts +5 -0
  111. package/test/integration/generated/projection/src/projectionClient.ts +5 -1
  112. package/test/integration/generated/resiliency/srvDriven1/package.json +1 -1
  113. package/test/integration/generated/resiliency/srvDriven1/src/logger.ts +5 -0
  114. package/test/integration/generated/resiliency/srvDriven1/src/serviceDrivenOldClient.ts +6 -2
  115. package/test/integration/generated/resiliency/srvDriven2/package.json +1 -1
  116. package/test/integration/generated/resiliency/srvDriven2/src/logger.ts +5 -0
  117. package/test/integration/generated/resiliency/srvDriven2/src/serviceDrivenNewClient.ts +6 -2
  118. package/test/integration/generated/server/path/multiple/src/logger.ts +5 -0
  119. package/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts +6 -2
  120. package/test/integration/generated/server/path/single/src/logger.ts +5 -0
  121. package/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts +6 -2
  122. package/test/integration/generated/specialWords/src/logger.ts +5 -0
  123. package/test/integration/generated/specialWords/src/specialWordsClient.ts +5 -1
  124. package/test/integration/generated/unions/src/logger.ts +5 -0
  125. package/test/integration/generated/unions/src/unionsClient.ts +5 -1
  126. package/test/integration/internal.spec.ts +45 -12
  127. package/test/integration/modelPropertyType.spec.ts +16 -0
  128. package/test/integration/resiliencyDpgCustomization.spec.ts +85 -24
  129. package/test/unit/apiVersion.spec.ts +19 -7
  130. package/test/unit/clientFactoryGenerator.spec.ts +44 -16
  131. package/test/unit/modelsGenerator.spec.ts +212 -2
  132. package/test/unit/util/emitUtil.ts +13 -4
  133. package/test/unit/util/testUtil.ts +7 -2
  134. package/typespec-ts.build.log +0 -1
  135. package/test/integration/generated/internal/src/models.ts +0 -8
package/package.json CHANGED
@@ -1,28 +1,9 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-ts",
3
- "version": "0.12.0-alpha.20230502.1",
3
+ "version": "0.13.0",
4
4
  "description": "An experimental CADL emitter for TypeScript RLC",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
7
- "scripts": {
8
- "clean": "rimraf ./dist ./cadl-output",
9
- "build": "tsc -p .",
10
- "test": "npm run unit-test && npm run integration-test-ci",
11
- "lint": "eslint src --ext .ts --max-warnings=0",
12
- "lint:fix": "eslint src --fix --ext .ts",
13
- "format": "npm run -s prettier -- --write",
14
- "check-format": "npm run prettier -- --check",
15
- "prettier": "prettier --config ./.prettierrc src/**/*.ts",
16
- "check:tree": "ts-node ./test/commands/check-clean-tree.ts",
17
- "integration-test-ci": "npm run start-test-server & npm run copy:typespec && npm run generate-and-run",
18
- "start-test-server": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript.json",
19
- "copy:typespec": "rm -rf temp && mkdirp -p temp && cp -r ./node_modules/@azure-tools/cadl-ranch-specs/http ./temp",
20
- "generate-and-run": "npm run generate-cadl-only && npm run integration-test:alone && npm run stop-test-server",
21
- "generate-cadl-only": "ts-node ./test/commands/gen-cadl-ranch.ts",
22
- "integration-test:alone": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 4000 ./test/integration/*.spec.ts",
23
- "stop-test-server": "npx cadl-ranch server stop",
24
- "unit-test": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true './test/unit/**/*.spec.ts'"
25
- },
26
7
  "author": "Jose Heredia <joheredi@microsoft.com>",
27
8
  "license": "MIT",
28
9
  "devDependencies": {
@@ -33,7 +14,7 @@
33
14
  "@types/fs-extra": "^9.0.13",
34
15
  "@typescript-eslint/eslint-plugin": "^5.58.0",
35
16
  "@typescript-eslint/parser": "^5.58.0",
36
- "@typespec/http": "~0.43.1",
17
+ "@typespec/http": "~0.44.0",
37
18
  "chai": "^4.3.6",
38
19
  "mkdirp": "^2.1.2",
39
20
  "eslint": "^8.9.0",
@@ -42,31 +23,33 @@
42
23
  "ts-node": "^10.9.1",
43
24
  "typescript": "~5.0.0",
44
25
  "prettier": "~2.7.1",
45
- "@azure-tools/cadl-ranch-specs": "~0.14.2",
46
- "@typespec/versioning": "~0.43.0",
47
- "@azure-tools/cadl-ranch-expect": "^0.2.3",
48
- "@azure-tools/cadl-ranch": "~0.4.6",
26
+ "@azure-tools/cadl-ranch-specs": "~0.14.10",
27
+ "@typespec/versioning": "~0.44.0",
28
+ "@azure-tools/cadl-ranch-expect": "^0.3.0",
29
+ "@azure-tools/cadl-ranch": "~0.4.13",
49
30
  "chalk": "^4.0.0",
50
- "@azure-rest/core-client": "^1.1.2",
31
+ "@azure-rest/core-client": "^1.1.3",
51
32
  "@azure/core-auth": "^1.3.2",
52
33
  "cross-env": "^7.0.3",
53
34
  "@azure/core-paging": "^1.5.0",
54
- "@azure/core-lro": "^2.2.0",
55
- "@azure/core-rest-pipeline": "^1.9.2"
35
+ "@azure/core-lro": "^2.5.3",
36
+ "@azure/core-rest-pipeline": "^1.9.2",
37
+ "@azure/logger": "^1.0.4"
38
+ },
39
+ "peerDependencies": {
40
+ "@azure-tools/typespec-azure-core": ">=0.30.0 <1.0.0",
41
+ "@azure-tools/typespec-client-generator-core": ">=0.30.0 <1.0.0",
42
+ "@typespec/compiler": ">=0.44.0 <1.0.0",
43
+ "@typespec/http": ">=0.44.0 <1.0.0",
44
+ "@typespec/rest": ">=0.44.0 <1.0.0",
45
+ "@typespec/versioning": ">=0.44.0 <1.0.0"
56
46
  },
57
47
  "dependencies": {
58
- "@typespec/compiler": "~0.43.0",
59
- "@azure-tools/typespec-azure-core": "~0.29.0",
60
- "@typespec/rest": "~0.43.0",
61
48
  "prettier": "^2.6.1",
62
49
  "tslib": "^2.3.1",
63
- "@azure-tools/rlc-common": "^0.12.0",
50
+ "@azure-tools/rlc-common": "^0.13.0",
64
51
  "ts-morph": "^15.1.0",
65
- "@azure-tools/typespec-client-generator-core": "~0.29.0",
66
- "fs-extra": "^11.1.0",
67
- "@typespec/openapi": "0.43.0",
68
- "@typespec/openapi3": "0.43.0",
69
- "@azure-tools/typespec-autorest": "~0.29.0"
52
+ "fs-extra": "^11.1.0"
70
53
  },
71
54
  "mocha": {
72
55
  "extension": [
@@ -77,5 +60,24 @@
77
60
  "bugs": {
78
61
  "url": "https://github.com/Azure/autorest.typescript/issues"
79
62
  },
80
- "homepage": "https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts/"
81
- }
63
+ "homepage": "https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts/",
64
+ "scripts": {
65
+ "clean": "rimraf ./dist ./cadl-output",
66
+ "build": "tsc -p .",
67
+ "test": "npm run unit-test && npm run integration-test-ci",
68
+ "lint": "eslint src --ext .ts --max-warnings=0",
69
+ "lint:fix": "eslint src --fix --ext .ts",
70
+ "format": "npm run -s prettier -- --write",
71
+ "check-format": "npm run prettier -- --check",
72
+ "prettier": "prettier --config ./.prettierrc src/**/*.ts",
73
+ "check:tree": "ts-node ./test/commands/check-clean-tree.ts",
74
+ "integration-test-ci": "npm run start-test-server & npm run copy:typespec && npm run generate-and-run",
75
+ "start-test-server": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript.json",
76
+ "copy:typespec": "rm -rf temp && mkdirp -p temp && cp -r ./node_modules/@azure-tools/cadl-ranch-specs/http ./temp",
77
+ "generate-and-run": "npm run generate-cadl-only && npm run integration-test:alone && npm run stop-test-server",
78
+ "generate-cadl-only": "ts-node ./test/commands/gen-cadl-ranch.ts",
79
+ "integration-test:alone": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 4000 ./test/integration/*.spec.ts",
80
+ "stop-test-server": "npx cadl-ranch server stop",
81
+ "unit-test": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true './test/unit/**/*.spec.ts'"
82
+ }
83
+ }
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  buildSampleTest,
26
26
  buildReadmeFile,
27
27
  buildSerializeHelper,
28
+ buildLogger,
28
29
  RLCOptions
29
30
  } from "@azure-tools/rlc-common";
30
31
  import { transformRLCModel } from "./transform/transform.js";
@@ -71,6 +72,7 @@ export async function $onEmit(context: EmitContext) {
71
72
  await emitContentByBuilder(program, buildParameterTypes, rlcModels);
72
73
  await emitContentByBuilder(program, buildIsUnexpectedHelper, rlcModels);
73
74
  await emitContentByBuilder(program, buildIndexFile, rlcModels);
75
+ await emitContentByBuilder(program, buildLogger, rlcModels);
74
76
  await emitContentByBuilder(program, buildTopLevelIndex, rlcModels);
75
77
  await emitContentByBuilder(program, buildPaginateHelper, rlcModels);
76
78
  await emitContentByBuilder(program, buildPollingHelper, rlcModels);
package/src/modelUtils.ts CHANGED
@@ -39,7 +39,9 @@ import {
39
39
  NumericLiteral,
40
40
  Service,
41
41
  listServices,
42
- Program
42
+ Program,
43
+ getEncode,
44
+ EncodeData
43
45
  } from "@typespec/compiler";
44
46
  import { reportDiagnostic } from "./lib.js";
45
47
  import {
@@ -74,12 +76,15 @@ export function getBinaryType(usage: SchemaContext[]) {
74
76
 
75
77
  export function getSchemaForType(
76
78
  program: Program,
79
+ dpgContext: SdkContext,
77
80
  typeInput: Type,
78
81
  usage?: SchemaContext[],
79
- needRef?: boolean
82
+ needRef: boolean = false,
83
+ relevantProperty?: ModelProperty
80
84
  ) {
81
85
  const type = getEffectiveModelFromType(program, typeInput);
82
- const builtinType = mapCadlTypeToTypeScript(program, type, usage);
86
+
87
+ const builtinType = mapCadlTypeToTypeScript(program, dpgContext, type, usage);
83
88
  if (builtinType !== undefined) {
84
89
  // add in description elements for types derived from primitive types (SecureString, etc.)
85
90
  const doc = getDoc(program, type);
@@ -89,7 +94,13 @@ export function getSchemaForType(
89
94
  return builtinType;
90
95
  }
91
96
  if (type.kind === "Model") {
92
- const schema = getSchemaForModel(program, type, usage, needRef) as any;
97
+ const schema = getSchemaForModel(
98
+ program,
99
+ dpgContext,
100
+ type,
101
+ usage,
102
+ needRef
103
+ ) as any;
93
104
  if (usage && usage.includes(SchemaContext.Output)) {
94
105
  schema.outputTypeName = `${schema.name}Output`;
95
106
  schema.typeName = `${schema.name}`;
@@ -97,13 +108,13 @@ export function getSchemaForType(
97
108
  schema.usage = usage;
98
109
  return schema;
99
110
  } else if (type.kind === "Union") {
100
- return getSchemaForUnion(program, type, usage);
111
+ return getSchemaForUnion(program, dpgContext, type, usage);
101
112
  } else if (type.kind === "UnionVariant") {
102
- return getSchemaForUnionVariant(program, type, usage);
113
+ return getSchemaForUnionVariant(program, dpgContext, type, usage);
103
114
  } else if (type.kind === "Enum") {
104
115
  return getSchemaForEnum(program, type);
105
116
  } else if (type.kind === "Scalar") {
106
- return getSchemaForScalar(program, type);
117
+ return getSchemaForScalar(program, dpgContext, type, relevantProperty);
107
118
  }
108
119
  if (isUnknownType(type)) {
109
120
  const returnType: any = { type: "unknown" };
@@ -152,16 +163,22 @@ export function includeDerivedModel(model: Model): boolean {
152
163
  );
153
164
  }
154
165
 
155
- function getSchemaForScalar(program: Program, scalar: Scalar) {
156
- let result = getSchemaForStdScalar(program, scalar);
166
+ function getSchemaForScalar(
167
+ program: Program,
168
+ dpgContext: SdkContext,
169
+ scalar: Scalar,
170
+ relevantProperty?: ModelProperty
171
+ ) {
172
+ let result = getSchemaForStdScalar(program, scalar, relevantProperty);
157
173
  if (!result && scalar.baseScalar) {
158
- result = getSchemaForScalar(program, scalar.baseScalar);
174
+ result = getSchemaForScalar(program, dpgContext, scalar.baseScalar);
159
175
  }
160
176
  return applyIntrinsicDecorators(program, scalar, result);
161
177
  }
162
178
 
163
179
  function getSchemaForUnion(
164
180
  program: Program,
181
+ dpgContext: SdkContext,
165
182
  union: Union,
166
183
  usage?: SchemaContext[]
167
184
  ) {
@@ -170,7 +187,7 @@ function getSchemaForUnion(
170
187
 
171
188
  for (const variant of variants) {
172
189
  // We already know it's not a model type
173
- values.push(getSchemaForType(program, variant.type, usage));
190
+ values.push(getSchemaForType(program, dpgContext, variant.type, usage));
174
191
  }
175
192
 
176
193
  const schema: any = {};
@@ -202,10 +219,11 @@ function getSchemaForUnion(
202
219
 
203
220
  function getSchemaForUnionVariant(
204
221
  program: Program,
222
+ dpgContext: SdkContext,
205
223
  variant: UnionVariant,
206
224
  usage?: SchemaContext[]
207
225
  ): Schema {
208
- return getSchemaForType(program, variant, usage);
226
+ return getSchemaForType(program, dpgContext, variant, usage);
209
227
  }
210
228
 
211
229
  // An openapi "string" can be defined in several different ways in Cadl
@@ -323,26 +341,10 @@ function isSchemaProperty(program: Program, property: ModelProperty) {
323
341
  const statusCodeinfo = isStatusCode(program, property);
324
342
  return !(headerInfo || queryInfo || pathInfo || statusCodeinfo);
325
343
  }
326
- // function getDefaultValue(program: Program, type: Type): any {
327
- // switch (type.kind) {
328
- // case "String":
329
- // return type.value;
330
- // case "Number":
331
- // return type.value;
332
- // case "Boolean":
333
- // return type.value;
334
- // case "Tuple":
335
- // return type.values.map(item => getDefaultValue(program, item));
336
- // default:
337
- // reportDiagnostic(program, {
338
- // code: "invalid-default",
339
- // format: { type: type.kind },
340
- // target: type,
341
- // });
342
- // }
343
- // }
344
+
344
345
  function getSchemaForModel(
345
346
  program: Program,
347
+ dpgContext: SdkContext,
346
348
  model: Model,
347
349
  usage?: SchemaContext[],
348
350
  needRef?: boolean
@@ -413,8 +415,13 @@ function getSchemaForModel(
413
415
  }
414
416
  })
415
417
  .join("");
416
- modelSchema.alias = `Paged<${templateName}>`;
417
- modelSchema.outputAlias = `Paged<${templateName}Output>`;
418
+ if (
419
+ paged.itemsProperty.name === "value" &&
420
+ paged.nextLinkProperty?.name === "nextLink"
421
+ ) {
422
+ modelSchema.alias = `Paged<${templateName}>`;
423
+ modelSchema.outputAlias = `Paged<${templateName}Output>`;
424
+ }
418
425
  }
419
426
  }
420
427
  }
@@ -430,10 +437,23 @@ function getSchemaForModel(
430
437
  };
431
438
  }
432
439
  for (const child of derivedModels) {
433
- const childSchema = getSchemaForType(program, child, usage, true);
440
+ const childSchema = getSchemaForType(
441
+ program,
442
+ dpgContext,
443
+ child,
444
+ usage,
445
+ true
446
+ );
434
447
  for (const [name, prop] of child.properties) {
435
448
  if (name === discriminator?.propertyName) {
436
- const propSchema = getSchemaForType(program, prop.type, usage, true);
449
+ const propSchema = getSchemaForType(
450
+ program,
451
+ dpgContext,
452
+ prop.type,
453
+ usage,
454
+ true,
455
+ prop
456
+ );
437
457
  childSchema.discriminatorValue = propSchema.type.replace(/"/g, "");
438
458
  break;
439
459
  }
@@ -476,7 +496,14 @@ function getSchemaForModel(
476
496
  continue;
477
497
  }
478
498
 
479
- const propSchema = getSchemaForType(program, prop.type, usage, true);
499
+ const propSchema = getSchemaForType(
500
+ program,
501
+ dpgContext,
502
+ prop.type,
503
+ usage,
504
+ true,
505
+ prop
506
+ );
480
507
  if (propSchema === undefined) {
481
508
  continue;
482
509
  }
@@ -501,17 +528,18 @@ function getSchemaForModel(
501
528
  }
502
529
 
503
530
  // Apply decorators on the property to the type's schema
504
- const newPropSchema = applyIntrinsicDecorators(program, prop, propSchema);
531
+ const newPropSchema = applyIntrinsicDecorators(
532
+ program,
533
+
534
+ prop,
535
+ propSchema
536
+ );
505
537
  if (newPropSchema === undefined) {
506
538
  continue;
507
539
  }
508
540
  // Use the description from ModelProperty not devired from Model Type
509
541
  newPropSchema.description = propertyDescription;
510
542
 
511
- if (prop.default) {
512
- // modelSchema.properties[name]['default'] = getDefaultValue(program, prop.default);
513
- }
514
-
515
543
  // Should the property be marked as readOnly?
516
544
  const vis = getVisibility(program, prop);
517
545
  if (vis && vis.includes("read")) {
@@ -549,15 +577,24 @@ function getSchemaForModel(
549
577
  ) {
550
578
  // Take the base model schema but carry across the documentation property
551
579
  // that we set before
552
- const baseSchema = getSchemaForType(program, model.baseModel, usage);
580
+ const baseSchema = getSchemaForType(
581
+ program,
582
+ dpgContext,
583
+ model.baseModel,
584
+ usage
585
+ );
553
586
  modelSchema = {
554
587
  ...baseSchema,
555
588
  description: modelSchema.description
556
589
  };
557
590
  } else if (model.baseModel) {
558
591
  modelSchema.parents = {
559
- all: [getSchemaForType(program, model.baseModel, usage, true)],
560
- immediate: [getSchemaForType(program, model.baseModel, usage, true)]
592
+ all: [
593
+ getSchemaForType(program, dpgContext, model.baseModel, usage, true)
594
+ ],
595
+ immediate: [
596
+ getSchemaForType(program, dpgContext, model.baseModel, usage, true)
597
+ ]
561
598
  };
562
599
  }
563
600
  return modelSchema;
@@ -566,6 +603,7 @@ function getSchemaForModel(
566
603
  // OA schema is just a regular object schema.
567
604
  function mapCadlTypeToTypeScript(
568
605
  program: Program,
606
+ dpgContext: SdkContext,
569
607
  cadlType: Type,
570
608
  usage?: SchemaContext[]
571
609
  ): any {
@@ -577,7 +615,7 @@ function mapCadlTypeToTypeScript(
577
615
  case "Boolean":
578
616
  return { type: `${cadlType.value}` };
579
617
  case "Model":
580
- return mapCadlStdTypeToTypeScript(program, cadlType, usage);
618
+ return mapCadlStdTypeToTypeScript(program, dpgContext, cadlType, usage);
581
619
  }
582
620
  if (cadlType.kind === undefined) {
583
621
  if (typeof cadlType === "string") {
@@ -685,6 +723,7 @@ function getSchemaForEnum(program: Program, e: Enum) {
685
723
  */
686
724
  function mapCadlStdTypeToTypeScript(
687
725
  program: Program,
726
+ dpgContext: SdkContext,
688
727
  cadlType: Model,
689
728
  usage?: SchemaContext[]
690
729
  ): any | undefined {
@@ -696,6 +735,7 @@ function mapCadlStdTypeToTypeScript(
696
735
  if (name === "string") {
697
736
  const valueType = getSchemaForType(
698
737
  program,
738
+ dpgContext,
699
739
  indexer.value!,
700
740
  usage,
701
741
  true
@@ -727,7 +767,13 @@ function mapCadlStdTypeToTypeScript(
727
767
  } else if (name === "integer") {
728
768
  schema = {
729
769
  type: "array",
730
- items: getSchemaForType(program, indexer.value!, usage, true),
770
+ items: getSchemaForType(
771
+ program,
772
+ dpgContext,
773
+ indexer.value!,
774
+ usage,
775
+ true
776
+ ),
731
777
  description: getDoc(program, cadlType)
732
778
  };
733
779
  if (
@@ -779,10 +825,26 @@ function isUnionType(type: Type) {
779
825
  return type.kind === "Union";
780
826
  }
781
827
 
782
- function getSchemaForStdScalar(program: Program, cadlType: Scalar) {
828
+ function getSchemaForStdScalar(
829
+ program: Program,
830
+ cadlType: Scalar,
831
+ relevantProperty?: ModelProperty
832
+ ) {
783
833
  if (!program.checker.isStdType(cadlType)) {
784
834
  return undefined;
785
835
  }
836
+
837
+ /**
838
+ * lookup for @encode decorator
839
+ * if absent use typespec type (or default way of serializing that type)
840
+ * if present respect type provided in @encode
841
+ */
842
+ if (relevantProperty) {
843
+ const encodeData = getEncode(program, relevantProperty);
844
+ if (encodeData && isEncodeTypeEffective(cadlType, encodeData)) {
845
+ cadlType = encodeData.type;
846
+ }
847
+ }
786
848
  const name = cadlType.name;
787
849
  const description = getSummary(program, cadlType);
788
850
  switch (name) {
@@ -848,7 +910,9 @@ function getSchemaForStdScalar(program: Program, cadlType: Scalar) {
848
910
  format: "float"
849
911
  });
850
912
  case "string":
851
- return applyIntrinsicDecorators(program, cadlType, { type: "string" });
913
+ return applyIntrinsicDecorators(program, cadlType, {
914
+ type: "string"
915
+ });
852
916
  case "boolean":
853
917
  return { type: "boolean", description };
854
918
  case "plainDate":
@@ -867,6 +931,14 @@ function getSchemaForStdScalar(program: Program, cadlType: Scalar) {
867
931
  typeName: "Date | string",
868
932
  outputTypeName: "string"
869
933
  };
934
+ case "offsetDateTime":
935
+ return {
936
+ type: "string",
937
+ format: "date-time",
938
+ description,
939
+ typeName: "Date | string",
940
+ outputTypeName: "string"
941
+ };
870
942
  case "plainTime":
871
943
  return {
872
944
  type: "string",
@@ -880,6 +952,28 @@ function getSchemaForStdScalar(program: Program, cadlType: Scalar) {
880
952
  }
881
953
  }
882
954
 
955
+ function isEncodeTypeEffective(
956
+ type: Scalar,
957
+ encodeData: EncodeData | undefined
958
+ ) {
959
+ if (!encodeData) {
960
+ return false;
961
+ }
962
+ const datetimeTypes = [
963
+ "plaindate",
964
+ "utcdatetime",
965
+ "offsetdatetime",
966
+ "plaintime"
967
+ ];
968
+ if (
969
+ datetimeTypes.includes(type.name.toLowerCase()) &&
970
+ encodeData.type.name === "string"
971
+ ) {
972
+ return false;
973
+ }
974
+ return true;
975
+ }
976
+
883
977
  export function getTypeName(schema: Schema, usage?: SchemaContext[]): string {
884
978
  // TODO: Handle more cases
885
979
  return getPriorityName(schema, usage) ?? schema.type ?? "any";
@@ -935,6 +1029,7 @@ export function getFormattedPropertyDoc(
935
1029
 
936
1030
  export function getBodyType(
937
1031
  program: Program,
1032
+
938
1033
  route: HttpOperation
939
1034
  ): Type | undefined {
940
1035
  let bodyModel = route.parameters.bodyType;
@@ -950,6 +1045,7 @@ export function getBodyType(
950
1045
  if (responseBody) {
951
1046
  const bodyTypeInResponse = getEffectiveModelFromType(
952
1047
  program,
1048
+
953
1049
  responseBody.type
954
1050
  );
955
1051
  // response body type is reosurce type, and request body type (if templated) contains resource type
@@ -177,12 +177,13 @@ export function extractOperationLroDetail(
177
177
  ]
178
178
  };
179
179
  const metadata = getLroMetadata(program, operation.operation);
180
- precedence = metadata?.finalStep &&
180
+ precedence =
181
+ metadata?.finalStep &&
181
182
  metadata?.finalStep.target &&
182
183
  metadata.finalStep.kind === "pollingSuccessProperty" &&
183
184
  metadata?.finalStep?.target?.name === "result"
184
- ? OPERATION_LRO_HIGH_PRIORITY
185
- : OPERATION_LRO_LOW_PRIORITY;
185
+ ? OPERATION_LRO_HIGH_PRIORITY
186
+ : OPERATION_LRO_LOW_PRIORITY;
186
187
  }
187
188
 
188
189
  return {
@@ -16,6 +16,7 @@ import {
16
16
  RLCModel,
17
17
  RLCOptions,
18
18
  Schema,
19
+ SchemaContext,
19
20
  UrlInfo
20
21
  } from "@azure-tools/rlc-common";
21
22
  import { Program, getDoc } from "@typespec/compiler";
@@ -128,11 +129,18 @@ export function transformUrlInfo(
128
129
  const property = host?.[0]?.parameters.get(key);
129
130
  const type = property?.type;
130
131
 
131
- if (!type) {
132
+ if (!property || !type) {
132
133
  continue;
133
134
  }
134
135
 
135
- const schema = getSchemaForType(program, type);
136
+ const schema = getSchemaForType(
137
+ program,
138
+ dpgContext,
139
+ type,
140
+ [SchemaContext.Exception, SchemaContext.Input],
141
+ false,
142
+ property!
143
+ );
136
144
  urlParameters.push({
137
145
  name: key,
138
146
  type: getTypeName(schema),
@@ -10,7 +10,8 @@ import {
10
10
  ApiVersionInfo,
11
11
  UrlInfo,
12
12
  extractPathApiVersion,
13
- extractDefinedPosition
13
+ extractDefinedPosition,
14
+ SchemaContext
14
15
  } from "@azure-tools/rlc-common";
15
16
  import { getHttpOperation } from "@typespec/http";
16
17
  import {
@@ -71,7 +72,14 @@ function getOperationQueryApiVersion(
71
72
  (p) => p.type === "query" && isApiVersion(dpgContext, p)
72
73
  );
73
74
  params.map((p) => {
74
- const type = getSchemaForType(program, p.param.type);
75
+ const type = getSchemaForType(
76
+ program,
77
+ dpgContext,
78
+ p.param.type,
79
+ [SchemaContext.Exception, SchemaContext.Input],
80
+ false,
81
+ p.param
82
+ );
75
83
  const typeString = JSON.stringify(trimUsage(type));
76
84
  apiVersionTypes.add(typeString);
77
85
  });
@@ -87,7 +95,14 @@ function getOperationQueryApiVersion(
87
95
  (p) => p.type === "query" && isApiVersion(dpgContext, p)
88
96
  );
89
97
  params.map((p) => {
90
- const type = getSchemaForType(program, p.param.type);
98
+ const type = getSchemaForType(
99
+ program,
100
+ dpgContext,
101
+ p.param.type,
102
+ [SchemaContext.Exception, SchemaContext.Input],
103
+ false,
104
+ p.param
105
+ );
91
106
  const typeString = JSON.stringify(trimUsage(type));
92
107
  apiVersionTypes.add(typeString);
93
108
  });