@azure-tools/typespec-ts 0.13.0 → 0.13.1-alpha.20230609.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 (512) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +37 -1
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/modelUtils.d.ts +2 -0
  6. package/dist/src/modelUtils.d.ts.map +1 -1
  7. package/dist/src/modelUtils.js +82 -13
  8. package/dist/src/modelUtils.js.map +1 -1
  9. package/dist/src/modular/buildApiIndex.d.ts.map +1 -1
  10. package/dist/src/modular/buildApiIndex.js +1 -1
  11. package/dist/src/modular/buildApiIndex.js.map +1 -1
  12. package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
  13. package/dist/src/modular/buildClassicalClient.js +6 -6
  14. package/dist/src/modular/buildClassicalClient.js.map +1 -1
  15. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  16. package/dist/src/modular/buildClientContext.js +9 -3
  17. package/dist/src/modular/buildClientContext.js.map +1 -1
  18. package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
  19. package/dist/src/modular/buildCodeModel.js +190 -169
  20. package/dist/src/modular/buildCodeModel.js.map +1 -1
  21. package/dist/src/modular/buildOperations.d.ts.map +1 -1
  22. package/dist/src/modular/buildOperations.js +20 -2
  23. package/dist/src/modular/buildOperations.js.map +1 -1
  24. package/dist/src/modular/buildRootIndex.js +2 -2
  25. package/dist/src/modular/buildRootIndex.js.map +1 -1
  26. package/dist/src/modular/buildSharedTypes.d.ts.map +1 -1
  27. package/dist/src/modular/buildSharedTypes.js +8 -10
  28. package/dist/src/modular/buildSharedTypes.js.map +1 -1
  29. package/dist/src/modular/emitModels.d.ts.map +1 -1
  30. package/dist/src/modular/emitModels.js +19 -6
  31. package/dist/src/modular/emitModels.js.map +1 -1
  32. package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
  33. package/dist/src/modular/helpers/clientHelpers.js +2 -11
  34. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  35. package/dist/src/modular/helpers/credentialHelpers.js +1 -1
  36. package/dist/src/modular/helpers/credentialHelpers.js.map +1 -1
  37. package/dist/src/modular/helpers/fixmeHelpers.d.ts +2 -0
  38. package/dist/src/modular/helpers/fixmeHelpers.d.ts.map +1 -0
  39. package/dist/src/modular/helpers/fixmeHelpers.js +4 -0
  40. package/dist/src/modular/helpers/fixmeHelpers.js.map +1 -0
  41. package/dist/src/modular/helpers/namingHelpers.d.ts +10 -1
  42. package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
  43. package/dist/src/modular/helpers/namingHelpers.js +20 -0
  44. package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
  45. package/dist/src/modular/helpers/operationHelpers.d.ts +2 -0
  46. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  47. package/dist/src/modular/helpers/operationHelpers.js +117 -35
  48. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  49. package/dist/src/modular/helpers/parameterHelpers.js +1 -1
  50. package/dist/src/modular/helpers/parameterHelpers.js.map +1 -1
  51. package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
  52. package/dist/src/modular/helpers/typeHelpers.js +31 -12
  53. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  54. package/dist/src/modular/modularCodeModel.d.ts +2 -1
  55. package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
  56. package/dist/src/operationUtil.d.ts +1 -1
  57. package/dist/src/operationUtil.d.ts.map +1 -1
  58. package/dist/src/operationUtil.js +21 -3
  59. package/dist/src/operationUtil.js.map +1 -1
  60. package/dist/src/transform/transform.d.ts.map +1 -1
  61. package/dist/src/transform/transform.js +2 -2
  62. package/dist/src/transform/transform.js.map +1 -1
  63. package/dist/src/transform/transformApiVersionInfo.js +9 -0
  64. package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
  65. package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
  66. package/dist/src/transform/transformHelperFunctionDetails.js +27 -1
  67. package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
  68. package/dist/src/transform/transformParameters.d.ts +1 -0
  69. package/dist/src/transform/transformParameters.d.ts.map +1 -1
  70. package/dist/src/transform/transformParameters.js +36 -35
  71. package/dist/src/transform/transformParameters.js.map +1 -1
  72. package/dist/src/transform/transformPaths.d.ts.map +1 -1
  73. package/dist/src/transform/transformPaths.js +9 -0
  74. package/dist/src/transform/transformPaths.js.map +1 -1
  75. package/dist/src/transform/transformResponses.d.ts.map +1 -1
  76. package/dist/src/transform/transformResponses.js +10 -1
  77. package/dist/src/transform/transformResponses.js.map +1 -1
  78. package/dist/src/transform/transformSchemas.d.ts.map +1 -1
  79. package/dist/src/transform/transformSchemas.js +9 -0
  80. package/dist/src/transform/transformSchemas.js.map +1 -1
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +20 -15
  83. package/src/index.ts +47 -2
  84. package/src/modelUtils.ts +90 -15
  85. package/src/modular/buildApiIndex.ts +3 -1
  86. package/src/modular/buildClassicalClient.ts +8 -6
  87. package/src/modular/buildClientContext.ts +11 -3
  88. package/src/modular/buildCodeModel.ts +221 -196
  89. package/src/modular/buildOperations.ts +23 -1
  90. package/src/modular/buildRootIndex.ts +2 -2
  91. package/src/modular/buildSharedTypes.ts +8 -10
  92. package/src/modular/emitModels.ts +14 -0
  93. package/src/modular/helpers/clientHelpers.ts +3 -13
  94. package/src/modular/helpers/credentialHelpers.ts +1 -1
  95. package/src/modular/helpers/fixmeHelpers.ts +3 -0
  96. package/src/modular/helpers/namingHelpers.ts +35 -1
  97. package/src/modular/helpers/operationHelpers.ts +173 -66
  98. package/src/modular/helpers/parameterHelpers.ts +1 -1
  99. package/src/modular/helpers/typeHelpers.ts +33 -12
  100. package/src/modular/modularCodeModel.ts +3 -1
  101. package/src/operationUtil.ts +24 -3
  102. package/src/transform/transform.ts +4 -1
  103. package/src/transform/transformApiVersionInfo.ts +8 -0
  104. package/src/transform/transformHelperFunctionDetails.ts +25 -1
  105. package/src/transform/transformParameters.ts +52 -41
  106. package/src/transform/transformPaths.ts +8 -0
  107. package/src/transform/transformResponses.ts +9 -1
  108. package/src/transform/transformSchemas.ts +8 -0
  109. package/.eslintrc.json +0 -23
  110. package/.prettierignore +0 -1
  111. package/.prettierrc +0 -7
  112. package/.rush/temp/operation/build/all.log +0 -1
  113. package/.rush/temp/operation/build/state.json +0 -3
  114. package/.rush/temp/package-deps_build.json +0 -442
  115. package/.rush/temp/shrinkwrap-deps.json +0 -490
  116. package/CONTRIBUTING.md +0 -137
  117. package/test/commands/cadl-ranch-list.ts +0 -116
  118. package/test/commands/check-clean-tree.ts +0 -55
  119. package/test/commands/childProcessOnExit.ts +0 -16
  120. package/test/commands/gen-cadl-ranch.ts +0 -25
  121. package/test/commands/run.ts +0 -31
  122. package/test/integration/arrayItemTypes.spec.ts +0 -96
  123. package/test/integration/authApiKey.spec.ts +0 -38
  124. package/test/integration/authOauth2.spec.ts +0 -65
  125. package/test/integration/authUnion.spec.ts +0 -72
  126. package/test/integration/azurecore.spec.ts +0 -170
  127. package/test/integration/collectionFormat.spec.ts +0 -118
  128. package/test/integration/dictionary.spec.ts +0 -106
  129. package/test/integration/extensibleEnums.spec.ts +0 -61
  130. package/test/integration/fixedEnums.spec.ts +0 -52
  131. package/test/integration/generated/arrays/itemTypes/src/arrayItemTypesClient.ts +0 -35
  132. package/test/integration/generated/arrays/itemTypes/src/clientDefinitions.ts +0 -165
  133. package/test/integration/generated/arrays/itemTypes/src/index.ts +0 -13
  134. package/test/integration/generated/arrays/itemTypes/src/logger.ts +0 -5
  135. package/test/integration/generated/arrays/itemTypes/src/models.ts +0 -9
  136. package/test/integration/generated/arrays/itemTypes/src/outputModels.ts +0 -9
  137. package/test/integration/generated/arrays/itemTypes/src/parameters.ts +0 -86
  138. package/test/integration/generated/arrays/itemTypes/src/responses.ts +0 -115
  139. package/test/integration/generated/arrays/itemTypes/tspconfig.yaml +0 -15
  140. package/test/integration/generated/authentication/apiKey/.eslintrc.json +0 -11
  141. package/test/integration/generated/authentication/apiKey/README.md +0 -56
  142. package/test/integration/generated/authentication/apiKey/api-extractor.json +0 -18
  143. package/test/integration/generated/authentication/apiKey/karma.conf.js +0 -133
  144. package/test/integration/generated/authentication/apiKey/package.json +0 -103
  145. package/test/integration/generated/authentication/apiKey/rollup.config.js +0 -118
  146. package/test/integration/generated/authentication/apiKey/src/authApiKeyClient.ts +0 -45
  147. package/test/integration/generated/authentication/apiKey/src/clientDefinitions.ts +0 -33
  148. package/test/integration/generated/authentication/apiKey/src/index.ts +0 -12
  149. package/test/integration/generated/authentication/apiKey/src/logger.ts +0 -5
  150. package/test/integration/generated/authentication/apiKey/src/outputModels.ts +0 -6
  151. package/test/integration/generated/authentication/apiKey/src/parameters.ts +0 -7
  152. package/test/integration/generated/authentication/apiKey/src/responses.ts +0 -21
  153. package/test/integration/generated/authentication/apiKey/test/public/sampleTest.spec.ts +0 -23
  154. package/test/integration/generated/authentication/apiKey/test/public/utils/env.browser.ts +0 -2
  155. package/test/integration/generated/authentication/apiKey/test/public/utils/env.ts +0 -6
  156. package/test/integration/generated/authentication/apiKey/test/public/utils/recordedClient.ts +0 -29
  157. package/test/integration/generated/authentication/apiKey/tsconfig.json +0 -25
  158. package/test/integration/generated/authentication/apiKey/tspconfig.yaml +0 -13
  159. package/test/integration/generated/authentication/oauth2/karma.conf.js +0 -133
  160. package/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts +0 -45
  161. package/test/integration/generated/authentication/oauth2/src/clientDefinitions.ts +0 -33
  162. package/test/integration/generated/authentication/oauth2/src/index.ts +0 -12
  163. package/test/integration/generated/authentication/oauth2/src/logger.ts +0 -5
  164. package/test/integration/generated/authentication/oauth2/src/outputModels.ts +0 -6
  165. package/test/integration/generated/authentication/oauth2/src/parameters.ts +0 -7
  166. package/test/integration/generated/authentication/oauth2/src/responses.ts +0 -21
  167. package/test/integration/generated/authentication/oauth2/test/public/sampleTest.spec.ts +0 -23
  168. package/test/integration/generated/authentication/oauth2/test/public/utils/env.browser.ts +0 -2
  169. package/test/integration/generated/authentication/oauth2/test/public/utils/env.ts +0 -6
  170. package/test/integration/generated/authentication/oauth2/test/public/utils/recordedClient.ts +0 -29
  171. package/test/integration/generated/authentication/oauth2/tspconfig.yaml +0 -15
  172. package/test/integration/generated/authentication/union/karma.conf.js +0 -133
  173. package/test/integration/generated/authentication/union/src/authUnionClient.ts +0 -46
  174. package/test/integration/generated/authentication/union/src/clientDefinitions.ts +0 -27
  175. package/test/integration/generated/authentication/union/src/index.ts +0 -11
  176. package/test/integration/generated/authentication/union/src/logger.ts +0 -5
  177. package/test/integration/generated/authentication/union/src/parameters.ts +0 -7
  178. package/test/integration/generated/authentication/union/src/responses.ts +0 -14
  179. package/test/integration/generated/authentication/union/test/public/sampleTest.spec.ts +0 -23
  180. package/test/integration/generated/authentication/union/test/public/utils/env.browser.ts +0 -2
  181. package/test/integration/generated/authentication/union/test/public/utils/env.ts +0 -6
  182. package/test/integration/generated/authentication/union/test/public/utils/recordedClient.ts +0 -29
  183. package/test/integration/generated/authentication/union/tspconfig.yaml +0 -15
  184. package/test/integration/generated/azure/core/.eslintrc.json +0 -11
  185. package/test/integration/generated/azure/core/README.md +0 -56
  186. package/test/integration/generated/azure/core/api-extractor.json +0 -18
  187. package/test/integration/generated/azure/core/package.json +0 -81
  188. package/test/integration/generated/azure/core/rollup.config.js +0 -118
  189. package/test/integration/generated/azure/core/src/azureCoreClient.ts +0 -35
  190. package/test/integration/generated/azure/core/src/clientDefinitions.ts +0 -108
  191. package/test/integration/generated/azure/core/src/index.ts +0 -16
  192. package/test/integration/generated/azure/core/src/isUnexpected.ts +0 -178
  193. package/test/integration/generated/azure/core/src/logger.ts +0 -5
  194. package/test/integration/generated/azure/core/src/models.ts +0 -18
  195. package/test/integration/generated/azure/core/src/outputModels.ts +0 -38
  196. package/test/integration/generated/azure/core/src/paginateHelper.ts +0 -204
  197. package/test/integration/generated/azure/core/src/parameters.ts +0 -68
  198. package/test/integration/generated/azure/core/src/responses.ts +0 -158
  199. package/test/integration/generated/azure/core/src/serializeHelper.ts +0 -16
  200. package/test/integration/generated/azure/core/tsconfig.json +0 -25
  201. package/test/integration/generated/azure/core/tspconfig.yaml +0 -15
  202. package/test/integration/generated/azure/core-traits/.eslintrc.json +0 -11
  203. package/test/integration/generated/azure/core-traits/README.md +0 -56
  204. package/test/integration/generated/azure/core-traits/api-extractor.json +0 -18
  205. package/test/integration/generated/azure/core-traits/package.json +0 -80
  206. package/test/integration/generated/azure/core-traits/rollup.config.js +0 -118
  207. package/test/integration/generated/azure/core-traits/src/azureCoreTraitsClient.ts +0 -35
  208. package/test/integration/generated/azure/core-traits/src/clientDefinitions.ts +0 -22
  209. package/test/integration/generated/azure/core-traits/src/index.ts +0 -13
  210. package/test/integration/generated/azure/core-traits/src/isUnexpected.ts +0 -97
  211. package/test/integration/generated/azure/core-traits/src/logger.ts +0 -5
  212. package/test/integration/generated/azure/core-traits/src/outputModels.ts +0 -25
  213. package/test/integration/generated/azure/core-traits/src/parameters.ts +0 -26
  214. package/test/integration/generated/azure/core-traits/src/responses.ts +0 -32
  215. package/test/integration/generated/azure/core-traits/tsconfig.json +0 -25
  216. package/test/integration/generated/azure/core-traits/tspconfig.yaml +0 -15
  217. package/test/integration/generated/dictionary/.eslintrc.json +0 -11
  218. package/test/integration/generated/dictionary/README.md +0 -56
  219. package/test/integration/generated/dictionary/api-extractor.json +0 -18
  220. package/test/integration/generated/dictionary/package.json +0 -80
  221. package/test/integration/generated/dictionary/rollup.config.js +0 -118
  222. package/test/integration/generated/dictionary/src/clientDefinitions.ts +0 -180
  223. package/test/integration/generated/dictionary/src/dictClient.ts +0 -33
  224. package/test/integration/generated/dictionary/src/index.ts +0 -13
  225. package/test/integration/generated/dictionary/src/logger.ts +0 -5
  226. package/test/integration/generated/dictionary/src/models.ts +0 -9
  227. package/test/integration/generated/dictionary/src/outputModels.ts +0 -9
  228. package/test/integration/generated/dictionary/src/parameters.ts +0 -94
  229. package/test/integration/generated/dictionary/src/responses.ts +0 -126
  230. package/test/integration/generated/dictionary/tsconfig.json +0 -25
  231. package/test/integration/generated/dictionary/tspconfig.yaml +0 -15
  232. package/test/integration/generated/enums/extensible/.eslintrc.json +0 -11
  233. package/test/integration/generated/enums/extensible/README.md +0 -56
  234. package/test/integration/generated/enums/extensible/api-extractor.json +0 -18
  235. package/test/integration/generated/enums/extensible/package.json +0 -80
  236. package/test/integration/generated/enums/extensible/rollup.config.js +0 -118
  237. package/test/integration/generated/enums/extensible/src/clientDefinitions.ts +0 -45
  238. package/test/integration/generated/enums/extensible/src/index.ts +0 -11
  239. package/test/integration/generated/enums/extensible/src/logger.ts +0 -5
  240. package/test/integration/generated/enums/extensible/src/parameters.ts +0 -23
  241. package/test/integration/generated/enums/extensible/src/responses.ts +0 -26
  242. package/test/integration/generated/enums/extensible/src/typeEnumExtensible.ts +0 -35
  243. package/test/integration/generated/enums/extensible/tsconfig.json +0 -25
  244. package/test/integration/generated/enums/extensible/tspconfig.yaml +0 -14
  245. package/test/integration/generated/enums/fixed/.eslintrc.json +0 -11
  246. package/test/integration/generated/enums/fixed/README.md +0 -56
  247. package/test/integration/generated/enums/fixed/api-extractor.json +0 -18
  248. package/test/integration/generated/enums/fixed/package.json +0 -80
  249. package/test/integration/generated/enums/fixed/rollup.config.js +0 -118
  250. package/test/integration/generated/enums/fixed/src/clientDefinitions.ts +0 -43
  251. package/test/integration/generated/enums/fixed/src/index.ts +0 -11
  252. package/test/integration/generated/enums/fixed/src/logger.ts +0 -5
  253. package/test/integration/generated/enums/fixed/src/parameters.ts +0 -36
  254. package/test/integration/generated/enums/fixed/src/responses.ts +0 -27
  255. package/test/integration/generated/enums/fixed/src/typeEnumFixed.ts +0 -35
  256. package/test/integration/generated/enums/fixed/tsconfig.json +0 -25
  257. package/test/integration/generated/enums/fixed/tspconfig.yaml +0 -14
  258. package/test/integration/generated/hello/.eslintrc.json +0 -11
  259. package/test/integration/generated/hello/README.md +0 -56
  260. package/test/integration/generated/hello/api-extractor.json +0 -18
  261. package/test/integration/generated/hello/package.json +0 -80
  262. package/test/integration/generated/hello/rollup.config.js +0 -118
  263. package/test/integration/generated/hello/src/clientDefinitions.ts +0 -19
  264. package/test/integration/generated/hello/src/hello.ts +0 -29
  265. package/test/integration/generated/hello/src/index.ts +0 -11
  266. package/test/integration/generated/hello/src/parameters.ts +0 -6
  267. package/test/integration/generated/hello/src/responses.ts +0 -10
  268. package/test/integration/generated/hello/tsconfig.json +0 -25
  269. package/test/integration/generated/hello/tspconfig.yaml +0 -14
  270. package/test/integration/generated/internal/src/clientDefinitions.ts +0 -53
  271. package/test/integration/generated/internal/src/index.ts +0 -12
  272. package/test/integration/generated/internal/src/internalClient.ts +0 -35
  273. package/test/integration/generated/internal/src/logger.ts +0 -5
  274. package/test/integration/generated/internal/src/outputModels.ts +0 -17
  275. package/test/integration/generated/internal/src/parameters.ts +0 -45
  276. package/test/integration/generated/internal/src/responses.ts +0 -33
  277. package/test/integration/generated/internal/tspconfig.yaml +0 -14
  278. package/test/integration/generated/lro/lroCore/.eslintrc.json +0 -11
  279. package/test/integration/generated/lro/lroCore/README.md +0 -56
  280. package/test/integration/generated/lro/lroCore/api-extractor.json +0 -18
  281. package/test/integration/generated/lro/lroCore/package.json +0 -82
  282. package/test/integration/generated/lro/lroCore/rollup.config.js +0 -118
  283. package/test/integration/generated/lro/lroCore/src/clientDefinitions.ts +0 -54
  284. package/test/integration/generated/lro/lroCore/src/index.ts +0 -15
  285. package/test/integration/generated/lro/lroCore/src/isUnexpected.ts +0 -135
  286. package/test/integration/generated/lro/lroCore/src/logger.ts +0 -5
  287. package/test/integration/generated/lro/lroCore/src/models.ts +0 -8
  288. package/test/integration/generated/lro/lroCore/src/outputModels.ts +0 -50
  289. package/test/integration/generated/lro/lroCore/src/parameters.ts +0 -25
  290. package/test/integration/generated/lro/lroCore/src/pollingHelper.ts +0 -113
  291. package/test/integration/generated/lro/lroCore/src/responses.ts +0 -109
  292. package/test/integration/generated/lro/lroCore/src/specsAzureCoreLroStandard.ts +0 -35
  293. package/test/integration/generated/lro/lroCore/tsconfig.json +0 -25
  294. package/test/integration/generated/lro/lroCore/tspconfig.yaml +0 -14
  295. package/test/integration/generated/lro/lroRPC/.eslintrc.json +0 -11
  296. package/test/integration/generated/lro/lroRPC/README.md +0 -56
  297. package/test/integration/generated/lro/lroRPC/api-extractor.json +0 -18
  298. package/test/integration/generated/lro/lroRPC/package.json +0 -82
  299. package/test/integration/generated/lro/lroRPC/rollup.config.js +0 -118
  300. package/test/integration/generated/lro/lroRPC/src/clientDefinitions.ts +0 -79
  301. package/test/integration/generated/lro/lroRPC/src/index.ts +0 -15
  302. package/test/integration/generated/lro/lroRPC/src/isUnexpected.ts +0 -153
  303. package/test/integration/generated/lro/lroRPC/src/logger.ts +0 -5
  304. package/test/integration/generated/lro/lroRPC/src/models.ts +0 -8
  305. package/test/integration/generated/lro/lroRPC/src/outputModels.ts +0 -40
  306. package/test/integration/generated/lro/lroRPC/src/parameters.ts +0 -20
  307. package/test/integration/generated/lro/lroRPC/src/pollingHelper.ts +0 -127
  308. package/test/integration/generated/lro/lroRPC/src/responses.ts +0 -124
  309. package/test/integration/generated/lro/lroRPC/src/specsAzureCoreLroRpc.ts +0 -35
  310. package/test/integration/generated/lro/lroRPC/tsconfig.json +0 -25
  311. package/test/integration/generated/lro/lroRPC/tspconfig.yaml +0 -14
  312. package/test/integration/generated/models/inheritance/.eslintrc.json +0 -11
  313. package/test/integration/generated/models/inheritance/README.md +0 -56
  314. package/test/integration/generated/models/inheritance/api-extractor.json +0 -18
  315. package/test/integration/generated/models/inheritance/package.json +0 -80
  316. package/test/integration/generated/models/inheritance/rollup.config.js +0 -118
  317. package/test/integration/generated/models/inheritance/src/clientDefinitions.ts +0 -81
  318. package/test/integration/generated/models/inheritance/src/index.ts +0 -13
  319. package/test/integration/generated/models/inheritance/src/logger.ts +0 -5
  320. package/test/integration/generated/models/inheritance/src/models.ts +0 -52
  321. package/test/integration/generated/models/inheritance/src/outputModels.ts +0 -52
  322. package/test/integration/generated/models/inheritance/src/parameters.ts +0 -35
  323. package/test/integration/generated/models/inheritance/src/responses.ts +0 -56
  324. package/test/integration/generated/models/inheritance/src/typeModelInheritance.ts +0 -35
  325. package/test/integration/generated/models/inheritance/tsconfig.json +0 -25
  326. package/test/integration/generated/models/inheritance/tspconfig.yaml +0 -14
  327. package/test/integration/generated/models/propertyNullable/.eslintrc.json +0 -11
  328. package/test/integration/generated/models/propertyNullable/README.md +0 -56
  329. package/test/integration/generated/models/propertyNullable/api-extractor.json +0 -18
  330. package/test/integration/generated/models/propertyNullable/package.json +0 -80
  331. package/test/integration/generated/models/propertyNullable/rollup.config.js +0 -118
  332. package/test/integration/generated/models/propertyNullable/src/clientDefinitions.ts +0 -227
  333. package/test/integration/generated/models/propertyNullable/src/index.ts +0 -13
  334. package/test/integration/generated/models/propertyNullable/src/logger.ts +0 -5
  335. package/test/integration/generated/models/propertyNullable/src/models.ts +0 -56
  336. package/test/integration/generated/models/propertyNullable/src/outputModels.ts +0 -56
  337. package/test/integration/generated/models/propertyNullable/src/parameters.ts +0 -197
  338. package/test/integration/generated/models/propertyNullable/src/responses.ts +0 -144
  339. package/test/integration/generated/models/propertyNullable/src/typePropertyNullable.ts +0 -35
  340. package/test/integration/generated/models/propertyNullable/tsconfig.json +0 -25
  341. package/test/integration/generated/models/propertyNullable/tspconfig.yaml +0 -14
  342. package/test/integration/generated/models/propertyOptional/.eslintrc.json +0 -11
  343. package/test/integration/generated/models/propertyOptional/README.md +0 -56
  344. package/test/integration/generated/models/propertyOptional/api-extractor.json +0 -18
  345. package/test/integration/generated/models/propertyOptional/package.json +0 -80
  346. package/test/integration/generated/models/propertyOptional/rollup.config.js +0 -118
  347. package/test/integration/generated/models/propertyOptional/src/clientDefinitions.ts +0 -263
  348. package/test/integration/generated/models/propertyOptional/src/index.ts +0 -13
  349. package/test/integration/generated/models/propertyOptional/src/logger.ts +0 -5
  350. package/test/integration/generated/models/propertyOptional/src/models.ts +0 -46
  351. package/test/integration/generated/models/propertyOptional/src/outputModels.ts +0 -46
  352. package/test/integration/generated/models/propertyOptional/src/parameters.ts +0 -125
  353. package/test/integration/generated/models/propertyOptional/src/responses.ts +0 -169
  354. package/test/integration/generated/models/propertyOptional/src/typePropertyOptional.ts +0 -35
  355. package/test/integration/generated/models/propertyOptional/tsconfig.json +0 -25
  356. package/test/integration/generated/models/propertyOptional/tspconfig.yaml +0 -14
  357. package/test/integration/generated/models/propertyTypes/.eslintrc.json +0 -11
  358. package/test/integration/generated/models/propertyTypes/README.md +0 -56
  359. package/test/integration/generated/models/propertyTypes/api-extractor.json +0 -18
  360. package/test/integration/generated/models/propertyTypes/package.json +0 -80
  361. package/test/integration/generated/models/propertyTypes/rollup.config.js +0 -118
  362. package/test/integration/generated/models/propertyTypes/src/clientDefinitions.ts +0 -310
  363. package/test/integration/generated/models/propertyTypes/src/index.ts +0 -13
  364. package/test/integration/generated/models/propertyTypes/src/logger.ts +0 -5
  365. package/test/integration/generated/models/propertyTypes/src/models.ts +0 -123
  366. package/test/integration/generated/models/propertyTypes/src/outputModels.ts +0 -123
  367. package/test/integration/generated/models/propertyTypes/src/parameters.ts +0 -189
  368. package/test/integration/generated/models/propertyTypes/src/responses.ts +0 -234
  369. package/test/integration/generated/models/propertyTypes/src/typePropertyValueTypes.ts +0 -35
  370. package/test/integration/generated/models/propertyTypes/tsconfig.json +0 -25
  371. package/test/integration/generated/models/propertyTypes/tspconfig.yaml +0 -14
  372. package/test/integration/generated/models/usage/.eslintrc.json +0 -11
  373. package/test/integration/generated/models/usage/README.md +0 -56
  374. package/test/integration/generated/models/usage/api-extractor.json +0 -18
  375. package/test/integration/generated/models/usage/package.json +0 -80
  376. package/test/integration/generated/models/usage/rollup.config.js +0 -118
  377. package/test/integration/generated/models/usage/src/clientDefinitions.ts +0 -41
  378. package/test/integration/generated/models/usage/src/index.ts +0 -13
  379. package/test/integration/generated/models/usage/src/logger.ts +0 -5
  380. package/test/integration/generated/models/usage/src/models.ts +0 -12
  381. package/test/integration/generated/models/usage/src/outputModels.ts +0 -12
  382. package/test/integration/generated/models/usage/src/parameters.ts +0 -19
  383. package/test/integration/generated/models/usage/src/responses.ts +0 -22
  384. package/test/integration/generated/models/usage/src/typeModelUsage.ts +0 -35
  385. package/test/integration/generated/models/usage/tsconfig.json +0 -25
  386. package/test/integration/generated/models/usage/tspconfig.yaml +0 -14
  387. package/test/integration/generated/models/visibility/.eslintrc.json +0 -11
  388. package/test/integration/generated/models/visibility/README.md +0 -56
  389. package/test/integration/generated/models/visibility/api-extractor.json +0 -18
  390. package/test/integration/generated/models/visibility/package.json +0 -80
  391. package/test/integration/generated/models/visibility/rollup.config.js +0 -118
  392. package/test/integration/generated/models/visibility/src/clientDefinitions.ts +0 -40
  393. package/test/integration/generated/models/visibility/src/index.ts +0 -13
  394. package/test/integration/generated/models/visibility/src/logger.ts +0 -5
  395. package/test/integration/generated/models/visibility/src/models.ts +0 -14
  396. package/test/integration/generated/models/visibility/src/outputModels.ts +0 -16
  397. package/test/integration/generated/models/visibility/src/parameters.ts +0 -41
  398. package/test/integration/generated/models/visibility/src/responses.ts +0 -36
  399. package/test/integration/generated/models/visibility/src/typeModelVisibility.ts +0 -35
  400. package/test/integration/generated/models/visibility/tsconfig.json +0 -25
  401. package/test/integration/generated/models/visibility/tspconfig.yaml +0 -14
  402. package/test/integration/generated/parameters/collection-format/src/clientDefinitions.ts +0 -63
  403. package/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts +0 -35
  404. package/test/integration/generated/parameters/collection-format/src/index.ts +0 -12
  405. package/test/integration/generated/parameters/collection-format/src/logger.ts +0 -5
  406. package/test/integration/generated/parameters/collection-format/src/parameters.ts +0 -71
  407. package/test/integration/generated/parameters/collection-format/src/responses.ts +0 -34
  408. package/test/integration/generated/parameters/collection-format/src/serializeHelper.ts +0 -28
  409. package/test/integration/generated/parameters/collection-format/tspconfig.yaml +0 -14
  410. package/test/integration/generated/parameters/spread/src/clientDefinitions.ts +0 -61
  411. package/test/integration/generated/parameters/spread/src/index.ts +0 -12
  412. package/test/integration/generated/parameters/spread/src/logger.ts +0 -5
  413. package/test/integration/generated/parameters/spread/src/models.ts +0 -7
  414. package/test/integration/generated/parameters/spread/src/parameters.ts +0 -61
  415. package/test/integration/generated/parameters/spread/src/parametersSpread.ts +0 -35
  416. package/test/integration/generated/parameters/spread/src/responses.ts +0 -25
  417. package/test/integration/generated/parameters/spread/tspconfig.yaml +0 -12
  418. package/test/integration/generated/projection/src/clientDefinitions.ts +0 -71
  419. package/test/integration/generated/projection/src/index.ts +0 -12
  420. package/test/integration/generated/projection/src/logger.ts +0 -5
  421. package/test/integration/generated/projection/src/models.ts +0 -22
  422. package/test/integration/generated/projection/src/parameters.ts +0 -48
  423. package/test/integration/generated/projection/src/projectionClient.ts +0 -35
  424. package/test/integration/generated/projection/src/responses.ts +0 -34
  425. package/test/integration/generated/projection/tspconfig.yaml +0 -14
  426. package/test/integration/generated/resiliency/srvDriven1/.eslintrc.json +0 -11
  427. package/test/integration/generated/resiliency/srvDriven1/README.md +0 -56
  428. package/test/integration/generated/resiliency/srvDriven1/api-extractor.json +0 -18
  429. package/test/integration/generated/resiliency/srvDriven1/package.json +0 -80
  430. package/test/integration/generated/resiliency/srvDriven1/rollup.config.js +0 -118
  431. package/test/integration/generated/resiliency/srvDriven1/src/clientDefinitions.ts +0 -46
  432. package/test/integration/generated/resiliency/srvDriven1/src/index.ts +0 -11
  433. package/test/integration/generated/resiliency/srvDriven1/src/logger.ts +0 -5
  434. package/test/integration/generated/resiliency/srvDriven1/src/parameters.ts +0 -30
  435. package/test/integration/generated/resiliency/srvDriven1/src/responses.ts +0 -19
  436. package/test/integration/generated/resiliency/srvDriven1/src/serviceDrivenOldClient.ts +0 -43
  437. package/test/integration/generated/resiliency/srvDriven1/tsconfig.json +0 -25
  438. package/test/integration/generated/resiliency/srvDriven1/tspconfig.yaml +0 -15
  439. package/test/integration/generated/resiliency/srvDriven2/.eslintrc.json +0 -11
  440. package/test/integration/generated/resiliency/srvDriven2/README.md +0 -65
  441. package/test/integration/generated/resiliency/srvDriven2/api-extractor.json +0 -18
  442. package/test/integration/generated/resiliency/srvDriven2/package.json +0 -80
  443. package/test/integration/generated/resiliency/srvDriven2/rollup.config.js +0 -118
  444. package/test/integration/generated/resiliency/srvDriven2/src/clientDefinitions.ts +0 -57
  445. package/test/integration/generated/resiliency/srvDriven2/src/index.ts +0 -11
  446. package/test/integration/generated/resiliency/srvDriven2/src/logger.ts +0 -5
  447. package/test/integration/generated/resiliency/srvDriven2/src/parameters.ts +0 -45
  448. package/test/integration/generated/resiliency/srvDriven2/src/responses.ts +0 -24
  449. package/test/integration/generated/resiliency/srvDriven2/src/serviceDrivenNewClient.ts +0 -43
  450. package/test/integration/generated/resiliency/srvDriven2/tsconfig.json +0 -25
  451. package/test/integration/generated/resiliency/srvDriven2/tspconfig.yaml +0 -15
  452. package/test/integration/generated/server/path/multiple/src/clientDefinitions.ts +0 -35
  453. package/test/integration/generated/server/path/multiple/src/index.ts +0 -11
  454. package/test/integration/generated/server/path/multiple/src/logger.ts +0 -5
  455. package/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts +0 -43
  456. package/test/integration/generated/server/path/multiple/src/parameters.ts +0 -7
  457. package/test/integration/generated/server/path/multiple/src/responses.ts +0 -14
  458. package/test/integration/generated/server/path/multiple/tspconfig.yaml +0 -14
  459. package/test/integration/generated/server/path/single/src/clientDefinitions.ts +0 -19
  460. package/test/integration/generated/server/path/single/src/index.ts +0 -11
  461. package/test/integration/generated/server/path/single/src/logger.ts +0 -5
  462. package/test/integration/generated/server/path/single/src/parameters.ts +0 -6
  463. package/test/integration/generated/server/path/single/src/responses.ts +0 -9
  464. package/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts +0 -38
  465. package/test/integration/generated/server/path/single/tspconfig.yaml +0 -14
  466. package/test/integration/generated/specialWords/src/clientDefinitions.ts +0 -61
  467. package/test/integration/generated/specialWords/src/index.ts +0 -13
  468. package/test/integration/generated/specialWords/src/logger.ts +0 -5
  469. package/test/integration/generated/specialWords/src/models.ts +0 -17
  470. package/test/integration/generated/specialWords/src/outputModels.ts +0 -17
  471. package/test/integration/generated/specialWords/src/parameters.ts +0 -37
  472. package/test/integration/generated/specialWords/src/responses.ts +0 -31
  473. package/test/integration/generated/specialWords/src/specialWordsClient.ts +0 -35
  474. package/test/integration/generated/specialWords/tspconfig.yaml +0 -14
  475. package/test/integration/generated/unions/src/clientDefinitions.ts +0 -53
  476. package/test/integration/generated/unions/src/index.ts +0 -12
  477. package/test/integration/generated/unions/src/logger.ts +0 -5
  478. package/test/integration/generated/unions/src/models.ts +0 -27
  479. package/test/integration/generated/unions/src/parameters.ts +0 -34
  480. package/test/integration/generated/unions/src/responses.ts +0 -24
  481. package/test/integration/generated/unions/src/unionsClient.ts +0 -35
  482. package/test/integration/generated/unions/tspconfig.yaml +0 -14
  483. package/test/integration/internal.spec.ts +0 -76
  484. package/test/integration/lroCore.spec.ts +0 -89
  485. package/test/integration/modelInheritance.spec.ts +0 -192
  486. package/test/integration/modelPropertyNullable.spec.ts +0 -115
  487. package/test/integration/modelPropertyOptional.spec.ts +0 -362
  488. package/test/integration/modelPropertyType.spec.ts +0 -135
  489. package/test/integration/modelUsage.spec.ts +0 -47
  490. package/test/integration/projection.spec.ts +0 -102
  491. package/test/integration/resiliencyDpgCustomization.spec.ts +0 -147
  492. package/test/integration/server.spec.ts +0 -59
  493. package/test/integration/specialWords.spec.ts +0 -73
  494. package/test/integration/spreadParameters.spec.ts +0 -82
  495. package/test/integration/unions.spec.ts +0 -69
  496. package/test/tsconfig.json +0 -4
  497. package/test/unit/apiVersion.spec.ts +0 -400
  498. package/test/unit/azureCoreOperationsGenerator.spec.ts +0 -71
  499. package/test/unit/clientDefinitionGenerator.spec.ts +0 -73
  500. package/test/unit/clientFactoryGenerator.spec.ts +0 -404
  501. package/test/unit/docsGenerator.spec.ts +0 -201
  502. package/test/unit/modelsGenerator.spec.ts +0 -1529
  503. package/test/unit/parametersGenerator.spec.ts +0 -561
  504. package/test/unit/responsesGenerator.spec.ts +0 -462
  505. package/test/unit/spreadAndAlias.spec.ts +0 -200
  506. package/test/unit/util/emitUtil.ts +0 -166
  507. package/test/unit/util/testUtil.ts +0 -88
  508. package/test/util/customBearerTokenTestingPolicy.ts +0 -78
  509. package/test/util/matrix.ts +0 -48
  510. package/tsconfig.json +0 -36
  511. package/tsconfig.test.json +0 -7
  512. package/typespec-ts.build.log +0 -1
@@ -1,1529 +0,0 @@
1
- import { assert } from "chai";
2
- import { emitModelsFromCadl, emitParameterFromCadl } from "./util/emitUtil.js";
3
- import { assertEqualContent } from "./util/testUtil.js";
4
-
5
- type VerifyPropertyConfig = {
6
- additionalCadlDefinition?: string;
7
- outputType?: string;
8
- additionalInputContent?: string;
9
- additionalOutputContent?: string;
10
- };
11
-
12
- describe("Input/output model type", () => {
13
- it("shouldn't generate models if there is no operations", async () => {
14
- const schemaOutput = await emitModelsFromCadl(`
15
- model Test {
16
- prop: string;
17
- }
18
- `);
19
- assert.ok(schemaOutput);
20
- const { inputModelFile, outputModelFile } = schemaOutput!;
21
- // both are undefined
22
- assert.ok(!inputModelFile);
23
- assert.ok(!outputModelFile);
24
- });
25
-
26
- async function verifyPropertyType(
27
- cadlType: string,
28
- inputType: string,
29
- options?: VerifyPropertyConfig,
30
- needAzureCore: boolean = false
31
- ) {
32
- const defaultOption: VerifyPropertyConfig = {
33
- additionalCadlDefinition: "",
34
- outputType: inputType,
35
- additionalInputContent: "",
36
- additionalOutputContent: ""
37
- };
38
- const {
39
- additionalCadlDefinition,
40
- outputType,
41
- additionalInputContent,
42
- additionalOutputContent
43
- } = {
44
- ...defaultOption,
45
- ...options
46
- };
47
- const schemaOutput = await emitModelsFromCadl(
48
- `
49
- ${additionalCadlDefinition}
50
- #suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
51
- model InputOutputModel {
52
- prop: ${cadlType};
53
- }
54
-
55
- #suppress "@azure-tools/typespec-azure-core/use-standard-operations" "for test"
56
- #suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
57
- @route("/models")
58
- @get
59
- op getModel(@body input: InputOutputModel): InputOutputModel;`,
60
- needAzureCore
61
- );
62
- assert.ok(schemaOutput);
63
- const { inputModelFile, outputModelFile } = schemaOutput!;
64
- assert.strictEqual(inputModelFile?.path, "models.ts");
65
- assertEqualContent(
66
- inputModelFile?.content!,
67
- `
68
- export interface InputOutputModel {
69
- prop: ${inputType};
70
- }
71
- ${additionalInputContent}`
72
- );
73
-
74
- assert.strictEqual(outputModelFile?.path, "outputModels.ts");
75
- assertEqualContent(
76
- outputModelFile?.content!,
77
- `
78
- export interface InputOutputModelOutput {
79
- prop: ${outputType};
80
- }
81
- ${additionalOutputContent}`
82
- );
83
- }
84
-
85
- describe("null generation", async () => {
86
- it("should generate null only", async () => {
87
- const cadlType = "null";
88
- const typeScriptType = "null";
89
- await verifyPropertyType(cadlType, typeScriptType);
90
- });
91
-
92
- it("should generate nullable union", async () => {
93
- const cadlType = "string | null";
94
- const typeScriptType = "string | null";
95
- await verifyPropertyType(cadlType, typeScriptType);
96
- });
97
-
98
- it("should generate nullable array", async () => {
99
- const cadlDefinition = `
100
- alias nullableArray = int32 | null;`;
101
- const cadlType = "nullableArray[]";
102
- const typeScriptType = "(number | null)[]";
103
- await verifyPropertyType(cadlType, typeScriptType, {
104
- additionalCadlDefinition: cadlDefinition
105
- });
106
- });
107
-
108
- it("should generate nullable boolean dictionary", async () => {
109
- const cadlType = "Record<boolean | null>";
110
- const typeScriptType = "Record<string, boolean | null>";
111
- await verifyPropertyType(cadlType, typeScriptType);
112
- });
113
-
114
- it("should generate nullable model", async () => {
115
- const cadlDefinition = `
116
- model SimpleModel {
117
- color: "red" | "blue";
118
- }
119
- `;
120
- const cadlType = "SimpleModel | null";
121
- const typeScriptType = "SimpleModel | null";
122
- await verifyPropertyType(cadlType, typeScriptType, {
123
- additionalCadlDefinition: cadlDefinition,
124
- outputType: "SimpleModelOutput | null",
125
- additionalInputContent: `
126
- export interface SimpleModel {
127
- color: "red" | "blue";
128
- }
129
- `,
130
- additionalOutputContent: `
131
- export interface SimpleModelOutput {
132
- color: "red" | "blue";
133
- }
134
- `
135
- });
136
- });
137
-
138
- it("should generate nullable literal dictionary", async () => {
139
- const cadlType = 'Record<"test" | null>';
140
- const typeScriptType = 'Record<string, "test" | null>';
141
- await verifyPropertyType(cadlType, typeScriptType);
142
- });
143
- });
144
-
145
- describe("number generation", () => {
146
- it("should handle int32 -> number", async () => {
147
- await verifyPropertyType("int32", "number");
148
- });
149
- it("should handle int64 -> number", async () => {
150
- await verifyPropertyType("int64", "number");
151
- });
152
- it("should handle safeint -> number", async () => {
153
- await verifyPropertyType("safeint", "number");
154
- });
155
- it("should handle float32 -> number", async () => {
156
- await verifyPropertyType("float32", "number");
157
- });
158
- it("should handle float64 -> number", async () => {
159
- await verifyPropertyType("float64", "number");
160
- });
161
- });
162
- describe("string generation", () => {
163
- it("should handle extensible_enum as property -> string", async () => {
164
- // When extensible_enum is comsumed as body property it should be string only
165
- const schemaOutput = await emitModelsFromCadl(`
166
- @doc("Extensible enum model description")
167
- enum TranslationLanguageValues {
168
- English,
169
- Chinese,
170
- }
171
- model InputOutputModel {
172
- @doc("Property description")
173
- prop: TranslationLanguageValues;
174
- }
175
- @route("/models")
176
- @get
177
- op getModel(@body input: InputOutputModel): InputOutputModel;
178
- `);
179
- assert.ok(schemaOutput);
180
- const { inputModelFile, outputModelFile } = schemaOutput!;
181
- assertEqualContent(
182
- inputModelFile?.content!,
183
- `
184
- export interface InputOutputModel {
185
- /**
186
- * Property description
187
- *
188
- * Possible values: English, Chinese
189
- */
190
- prop: string;
191
- }`
192
- );
193
- assertEqualContent(
194
- outputModelFile?.content!,
195
- `
196
- export interface InputOutputModelOutput {
197
- /**
198
- * Property description
199
- *
200
- * Possible values: English, Chinese
201
- */
202
- prop: string;
203
- }`
204
- );
205
- });
206
- it("should handle extensible_enum as body -> string", async () => {
207
- // When extensible_enum is comsumed as body property it should be string only
208
- const schemaOutput = await emitParameterFromCadl(`
209
- enum TranslationLanguage {
210
- English,
211
- Chinese,
212
- }
213
- model InputOutputModel {
214
- prop: TranslationLanguage;
215
- }
216
- @route("/models")
217
- @get
218
- op getModel(@body input: TranslationLanguage): InputOutputModel;
219
- `);
220
- assert.ok(schemaOutput);
221
- assertEqualContent(
222
- schemaOutput?.content!,
223
- `
224
- import { RequestParameters } from "@azure-rest/core-client";
225
-
226
- export interface GetModelBodyParam {
227
- /** Possible values: English, Chinese */
228
- body: string;
229
- }
230
-
231
- export type GetModelParameters = GetModelBodyParam & RequestParameters;`
232
- );
233
- });
234
-
235
- // TODO: Is enum convered to string literals only? Do we need to generate enum instaed?
236
- it("should handle enum -> string_literals", async () => {
237
- const cadlTypeDefinition = `
238
- #suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "for test"
239
- @fixed
240
- enum TranslationLanguageValues {
241
- English,
242
- Chinese,
243
- }`;
244
- const cadlType = "TranslationLanguageValues";
245
- const typeScriptType = `"English" | "Chinese"`;
246
- await verifyPropertyType(
247
- cadlType,
248
- typeScriptType,
249
- {
250
- additionalCadlDefinition: cadlTypeDefinition
251
- },
252
- true
253
- );
254
- });
255
-
256
- it("should handle type_literals:string -> string_literals", async () => {
257
- const cadlType = `"English" | "Chinese"`;
258
- const typeScriptType = `"English" | "Chinese"`;
259
- await verifyPropertyType(cadlType, typeScriptType);
260
- });
261
-
262
- it("should handle type_literals:boolean -> boolean_literals", async () => {
263
- const cadlType = `true`;
264
- const typeScriptType = `true`;
265
- await verifyPropertyType(cadlType, typeScriptType);
266
- });
267
-
268
- it("should handle string -> string", async () => {
269
- const cadlType = "string";
270
- const typeScriptType = "string";
271
- await verifyPropertyType(cadlType, typeScriptType);
272
- });
273
-
274
- it("should handle never, its property will be ignored both in Input and Ouput model", async () => {
275
- const cadlDefinition = `
276
- model SimpleModel {
277
- prop1: never;
278
- prop2: never;
279
- }`;
280
- const cadlType = "SimpleModel";
281
- const inputModelName = "SimpleModel";
282
- await verifyPropertyType(cadlType, inputModelName, {
283
- additionalCadlDefinition: cadlDefinition,
284
- outputType: `${inputModelName}Output`,
285
- additionalInputContent: `
286
- export interface ${inputModelName} {}`,
287
- additionalOutputContent: `
288
- export interface ${inputModelName}Output {}`
289
- });
290
- });
291
- });
292
-
293
- describe("array basic generation", () => {
294
- it("should handle string[] -> string[]", async () => {
295
- const cadlType = "string[]";
296
- const typeScriptType = "string[]";
297
- await verifyPropertyType(cadlType, typeScriptType);
298
- });
299
-
300
- it("should handle int32[] -> number[]", async () => {
301
- const cadlType = "int32[]";
302
- const typeScriptType = "number[]";
303
- await verifyPropertyType(cadlType, typeScriptType);
304
- });
305
-
306
- it("should handle float32[] -> number[]", async () => {
307
- const cadlType = "float32[]";
308
- const typeScriptType = "number[]";
309
- await verifyPropertyType(cadlType, typeScriptType);
310
- });
311
-
312
- it("should handle boolean[] -> boolean[]", async () => {
313
- const cadlType = "boolean[]";
314
- const typeScriptType = "boolean[]";
315
- await verifyPropertyType(cadlType, typeScriptType);
316
- });
317
-
318
- it("should handle bytes[] -> string[]", async () => {
319
- const cadlType = "bytes[]";
320
- const typeScriptType = "string[]";
321
- await verifyPropertyType(cadlType, typeScriptType);
322
- });
323
-
324
- it("should handle plainDate[] -> input 'Date[] | string[]' output type 'string[]'", async () => {
325
- const cadlType = "plainDate[]";
326
- const inputType = "Date[] | string[]";
327
- const outputType = "string[]";
328
- await verifyPropertyType(cadlType, inputType, { outputType });
329
- });
330
-
331
- it("should handle true[] -> true[]", async () => {
332
- const cadlType = "true[]";
333
- const typeScriptType = "true[]";
334
- await verifyPropertyType(cadlType, typeScriptType);
335
- });
336
-
337
- it("should handle 32[] -> 32[]", async () => {
338
- const cadlType = "32[]";
339
- const typeScriptType = "32[]";
340
- await verifyPropertyType(cadlType, typeScriptType);
341
- });
342
-
343
- it("should handle 'job'[] -> 'job'[]", async () => {
344
- const cadlType = `"job"[]`;
345
- const typeScriptType = `"job"[]`;
346
- await verifyPropertyType(cadlType, typeScriptType);
347
- });
348
-
349
- it("should handle unknown[] -> input 'unknown[]' output type 'any[]'", async () => {
350
- const cadlType = "unknown[]";
351
- const inputType = "unknown[]";
352
- const outputType = "any[]";
353
- await verifyPropertyType(cadlType, inputType, { outputType });
354
- });
355
-
356
- it("should handle unknown -> input 'unknown' output type 'any'", async () => {
357
- const cadlType = "unknown";
358
- const inputType = "unknown";
359
- const outputType = "any";
360
- await verifyPropertyType(cadlType, inputType, { outputType });
361
- });
362
- });
363
- describe("array models generation", () => {
364
- it("should handle SimpleModel[] -> Array<SimpleModel>", async () => {
365
- const cadlDefinition = `
366
- model SimpleModel {
367
- prop1: string;
368
- prop2: int32;
369
- }
370
- `;
371
- const cadlType = "SimpleModel[]";
372
- const inputModelName = "Array<SimpleModel>";
373
- await verifyPropertyType(cadlType, inputModelName, {
374
- additionalCadlDefinition: cadlDefinition,
375
- outputType: `Array<SimpleModelOutput>`,
376
- additionalInputContent: `
377
- export interface SimpleModel {
378
- prop1:string;
379
- prop2:number;
380
- }`,
381
- additionalOutputContent: `
382
- export interface SimpleModelOutput {
383
- prop1:string;
384
- prop2:number;
385
- }`
386
- });
387
- });
388
-
389
- it("should handle fixed enum array", async () => {
390
- const cadlDefinition = `
391
- #suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "for test"
392
- #suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
393
- @fixed
394
- enum DiskEncryptionTarget {
395
- OsDisk: "osdisk",
396
- TemporaryDisk: "temporarydisk",
397
- }
398
- `;
399
- const cadlType = "DiskEncryptionTarget[]";
400
- const typeScriptType = `("osdisk" | "temporarydisk")[]`;
401
- const inputModelName = typeScriptType;
402
- await verifyPropertyType(
403
- cadlType,
404
- inputModelName,
405
- {
406
- additionalCadlDefinition: cadlDefinition,
407
- outputType: typeScriptType
408
- },
409
- true
410
- );
411
- });
412
-
413
- it("should handle extensible enum array", async () => {
414
- const cadlDefinition = `
415
- #suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
416
- enum DiskEncryptionTarget {
417
- OsDisk: "osdisk",
418
- TemporaryDisk: "temporarydisk",
419
- }
420
- `;
421
- const cadlType = "DiskEncryptionTarget[]";
422
- const typeScriptType = `string[]`;
423
- const inputModelName = typeScriptType;
424
- await verifyPropertyType(
425
- cadlType,
426
- inputModelName,
427
- {
428
- additionalCadlDefinition: cadlDefinition,
429
- outputType: typeScriptType
430
- },
431
- true
432
- );
433
- });
434
- });
435
- describe("object generation", () => {
436
- it("should handle basic model -> type/interface", async () => {
437
- const cadlDefinition = `
438
- model SimpleModel {
439
- prop1: string;
440
- prop2: int32;
441
- }`;
442
- const cadlType = "SimpleModel";
443
- const inputModelName = "SimpleModel";
444
- await verifyPropertyType(cadlType, inputModelName, {
445
- additionalCadlDefinition: cadlDefinition,
446
- outputType: `${inputModelName}Output`,
447
- additionalInputContent: `
448
- export interface ${inputModelName} {
449
- prop1:string;
450
- prop2:number;
451
- }`,
452
- additionalOutputContent: `
453
- export interface ${inputModelName}Output {
454
- prop1:string;
455
- prop2:number;
456
- }`
457
- });
458
- });
459
-
460
- it("should handle nested model -> type/interface", async () => {
461
- const cadlDefinition = `
462
- model SimpleModel {
463
- prop1: string;
464
- prop2: int32;
465
- }
466
- model NestedModel {
467
- ...SimpleModel;
468
- }
469
- `;
470
- const cadlType = "NestedModel";
471
- const inputModelName = "NestedModel";
472
- await verifyPropertyType(cadlType, inputModelName, {
473
- additionalCadlDefinition: cadlDefinition,
474
- outputType: `${inputModelName}Output`,
475
- additionalInputContent: `
476
- export interface ${inputModelName} {
477
- prop1:string;
478
- prop2:number;
479
- }`,
480
- additionalOutputContent: `
481
- export interface ${inputModelName}Output {
482
- prop1:string;
483
- prop2:number;
484
- }`
485
- });
486
- });
487
-
488
- it.skip("should handle anonymous model -> effective type/interface", async () => {
489
- const cadlDefinition = `
490
- model SimpleModel {
491
- prop1: string;
492
- prop2: int32;
493
- }
494
- `;
495
- const cadlType = "{...SimpleModel}";
496
- const inputModelName = "SimpleModel";
497
- await verifyPropertyType(cadlType, inputModelName, {
498
- additionalCadlDefinition: cadlDefinition,
499
- outputType: `${inputModelName}Output`,
500
- additionalInputContent: `
501
- export interface ${inputModelName} {
502
- prop1:string;
503
- prop2:number;
504
- }`,
505
- additionalOutputContent: `
506
- export interface ${inputModelName}Output {
507
- prop1:string;
508
- prop2:number;
509
- }`
510
- });
511
- });
512
-
513
- describe("inheritance & polymorphism", () => {
514
- it("should handle inheritance model -> multiple types/interfaces", async () => {
515
- const schemaOutput = await emitModelsFromCadl(`
516
- @discriminator("kind")
517
- model Pet {
518
- name: string;
519
- weight?: float32;
520
- }
521
- model Cat extends Pet {
522
- kind: "cat";
523
- meow: int32;
524
- }
525
- model Dog extends Pet {
526
- kind: "dog";
527
- bark: string;
528
- }
529
- op read(): { @body body: Pet };
530
- `);
531
- assert.ok(schemaOutput);
532
- const { inputModelFile, outputModelFile } = schemaOutput!;
533
- assert.ok(!inputModelFile?.content);
534
- assert.strictEqual(outputModelFile?.path, "outputModels.ts");
535
- assertEqualContent(
536
- outputModelFile?.content!,
537
- `
538
- export interface PetOutputParent {
539
- name: string;
540
- weight?: number;
541
- "kind": "Pet" | "cat" | "dog";
542
- }
543
-
544
- export interface CatOutput extends PetOutputParent {
545
- kind: "cat";
546
- meow: number;
547
- }
548
-
549
- export interface DogOutput extends PetOutputParent {
550
- kind: "dog";
551
- bark: string;
552
- }
553
-
554
- export type PetOutput = CatOutput | DogOutput;`
555
- );
556
- });
557
-
558
- it("should handle multiple inheritance model -> multiple types/interfaces", async () => {
559
- const schemaOutput = await emitModelsFromCadl(`
560
- @doc("This is base model for polymorphic multiple levels inheritance with a discriminator.")
561
- @discriminator("kind")
562
- model Fish {
563
- age: int32;
564
- }
565
-
566
- @doc("The second level model in polymorphic multiple levels inheritance and it defines a new discriminator.")
567
- @discriminator("sharktype")
568
- model Shark extends Fish {
569
- kind: "shark";
570
- }
571
-
572
- @doc("The second level model in polymorphic multiple levels inheritance which contains references to other polymorphic instances.")
573
- model Salmon extends Fish {
574
- kind: "salmon";
575
- friends?: Fish[];
576
- hate?: Record<Fish>;
577
- partner?: Fish;
578
- }
579
-
580
- @doc("The third level model SawShark in polymorphic multiple levels inheritance.")
581
- @discriminator("sharktype")
582
- model SawShark extends Shark {
583
- sharktype: "saw";
584
- }
585
-
586
- @doc("The third level model GoblinShark in polymorphic multiple levels inheritance.")
587
- model GoblinShark extends Shark {
588
- sharktype: "goblin";
589
- }
590
- op read(): { @body body: Fish };
591
- `);
592
- assert.ok(schemaOutput);
593
- const { inputModelFile, outputModelFile } = schemaOutput!;
594
- assert.ok(!inputModelFile?.content);
595
- assert.strictEqual(outputModelFile?.path, "outputModels.ts");
596
- assertEqualContent(
597
- outputModelFile?.content!,
598
- `
599
- /** This is base model for polymorphic multiple levels inheritance with a discriminator. */
600
- export interface FishOutputParent {
601
- age: number;
602
- kind: "Fish" | "shark" | "salmon";
603
- }
604
-
605
- /** The second level model in polymorphic multiple levels inheritance and it defines a new discriminator. */
606
- export interface SharkOutputParent extends FishOutputParent {
607
- kind: "shark";
608
- sharktype: "Shark" | "saw" | "goblin";
609
- }
610
-
611
- /** The third level model SawShark in polymorphic multiple levels inheritance. */
612
- export interface SawSharkOutput extends SharkOutputParent {
613
- sharktype: "saw";
614
- }
615
-
616
- /** The third level model GoblinShark in polymorphic multiple levels inheritance. */
617
- export interface GoblinSharkOutput extends SharkOutputParent {
618
- sharktype: "goblin";
619
- }
620
-
621
- /** The second level model in polymorphic multiple levels inheritance which contains references to other polymorphic instances. */
622
- export interface SalmonOutput extends FishOutputParent {
623
- kind: "salmon";
624
- friends?: Array<FishOutput>;
625
- hate?: Record<string, FishOutput>;
626
- partner?: FishOutput;
627
- }
628
-
629
- /** This is base model for polymorphic multiple levels inheritance with a discriminator. */
630
- export type FishOutput = SharkOutput | SalmonOutput;
631
- /** The second level model in polymorphic multiple levels inheritance and it defines a new discriminator. */
632
- export type SharkOutput = SawSharkOutput | GoblinSharkOutput;
633
- `
634
- );
635
- });
636
-
637
- it("should handle basic model with special words -> type/interface", async () => {
638
- const cadlDefinition = `
639
- model SimpleModel {
640
- "model.kind": "derived";
641
- "derived.name": string;
642
- }`;
643
- const cadlType = "SimpleModel";
644
- const inputModelName = "SimpleModel";
645
- await verifyPropertyType(cadlType, inputModelName, {
646
- additionalCadlDefinition: cadlDefinition,
647
- outputType: `${inputModelName}Output`,
648
- additionalInputContent: `
649
- export interface ${inputModelName} {
650
- "model.kind": "derived";
651
- "derived.name": string;
652
- }`,
653
- additionalOutputContent: `
654
- export interface ${inputModelName}Output {
655
- "model.kind": "derived";
656
- "derived.name": string;
657
- }`
658
- });
659
- });
660
-
661
- it("should handle inheritance model with special words -> type/interface", async () => {
662
- const cadlDefinition = `
663
- @doc("This is a base model has discriminator name containing dot.")
664
- @discriminator("model.kind")
665
- model BaseModel {}
666
-
667
- @doc("This is a model has property names of special words or characters.")
668
- @discriminator("model.kind")
669
- model DerivedModel extends BaseModel {
670
- "model.kind": "derived";
671
- "derived.name": string;
672
- for: string;
673
- }`;
674
- const cadlType = "DerivedModel";
675
- const inputModelName = "DerivedModel";
676
- await verifyPropertyType(cadlType, inputModelName, {
677
- additionalCadlDefinition: cadlDefinition,
678
- outputType: `${inputModelName}Output`,
679
- additionalInputContent: `
680
- /** This is a model has property names of special words or characters. */
681
- export interface ${inputModelName} extends BaseModelParent {
682
- "model.kind": "derived";
683
- "derived.name": string;
684
- for: string;
685
- }
686
-
687
- /** This is a base model has discriminator name containing dot. */
688
- export interface BaseModelParent {
689
- "model.kind": "BaseModel" | "derived";
690
- }
691
-
692
- /** This is a base model has discriminator name containing dot. */
693
- export type BaseModel = ${inputModelName};
694
- `,
695
- additionalOutputContent: `
696
- /** This is a model has property names of special words or characters. */
697
- export interface ${inputModelName}Output extends BaseModelOutputParent {
698
- "model.kind": "derived";
699
- "derived.name": string;
700
- for: string;
701
- }
702
-
703
- /** This is a base model has discriminator name containing dot. */
704
- export interface BaseModelOutputParent {
705
- "model.kind": "BaseModel" | "derived";
706
- }
707
-
708
- /** This is a base model has discriminator name containing dot. */
709
- export type BaseModelOutput = ${inputModelName}Output;
710
- `
711
- });
712
- });
713
- });
714
- });
715
- describe("bytes generation as property", () => {
716
- it("should handle bytes -> string", async () => {
717
- await verifyPropertyType("bytes", "string");
718
- });
719
- });
720
- describe("duration generation", () => {
721
- const buildParameterDef = (type: string) => {
722
- return `
723
- import { RequestParameters } from "@azure-rest/core-client";
724
-
725
- export interface GetModelQueryParamProperties {
726
- "input": ${type};
727
- }
728
-
729
- export interface GetModelQueryParam {
730
- queryParameters: GetModelQueryParamProperties;
731
- }
732
-
733
- export type GetModelParameters = GetModelQueryParam & RequestParameters;
734
- `;
735
- };
736
-
737
- describe("as input and output model property", () => {
738
- it("should handle duration without encode", async () => {
739
- await verifyPropertyType("duration", "string");
740
- });
741
-
742
- it("should handle duration with encode `seconds`", async () => {
743
- const schemaOutput = await emitModelsFromCadl(
744
- `
745
- model SimpleModel {
746
- @encode("seconds", float64)
747
- prop: duration;
748
- }
749
- @route("/duration/prop/seconds")
750
- @get
751
- op getModel(...SimpleModel): SimpleModel;
752
- `,
753
- false,
754
- true
755
- );
756
- assert.ok(schemaOutput);
757
- const { inputModelFile, outputModelFile } = schemaOutput!;
758
- assertEqualContent(
759
- inputModelFile?.content!,
760
- `
761
- export interface SimpleModel {
762
- "prop": number;
763
- }
764
- `
765
- );
766
- assertEqualContent(
767
- outputModelFile?.content!,
768
- `
769
- export interface SimpleModelOutput {
770
- "prop": number;
771
- }
772
- `
773
- );
774
- });
775
-
776
- it("should handle duration with encode `iso8601`", async () => {
777
- const schemaOutput = await emitModelsFromCadl(
778
- `
779
- model SimpleModel {
780
- @encode("ISO8601")
781
- prop: duration;
782
- }
783
- @route("/duration/prop/iso8601")
784
- @get
785
- op getModel(...SimpleModel): SimpleModel;
786
- `,
787
- false,
788
- true
789
- );
790
- assert.ok(schemaOutput);
791
- const { inputModelFile, outputModelFile } = schemaOutput!;
792
- assertEqualContent(
793
- inputModelFile?.content!,
794
- `
795
- export interface SimpleModel {
796
- "prop": string;
797
- }
798
- `
799
- );
800
- assertEqualContent(
801
- outputModelFile?.content!,
802
- `
803
- export interface SimpleModelOutput {
804
- "prop": string;
805
- }
806
- `
807
- );
808
- });
809
- });
810
-
811
- describe("as query parameter", () => {
812
- it("should handle duration without encode", async () => {
813
- const schemaOutput = await emitParameterFromCadl(`
814
- @route("/duration/query/default")
815
- @get
816
- op getModel(@query input: duration): NoContentResponse;
817
- `);
818
- assert.ok(schemaOutput);
819
- assertEqualContent(schemaOutput?.content!, buildParameterDef("string"));
820
- });
821
-
822
- it("should handle duration with encode `seconds`", async () => {
823
- const schemaOutput = await emitParameterFromCadl(
824
- `
825
- @route("/duration/query/seconds")
826
- @get
827
- op getModel(
828
- @query
829
- @encode("seconds", float64)
830
- input: duration): NoContentResponse;
831
- `,
832
- false,
833
- false,
834
- true
835
- );
836
- assert.ok(schemaOutput);
837
- assertEqualContent(schemaOutput?.content!, buildParameterDef("number"));
838
- });
839
-
840
- it("should handle duration with encode `iso8601`", async () => {
841
- const schemaOutput = await emitParameterFromCadl(
842
- `
843
- @route("/duration/query/iso8601")
844
- @get
845
- op getModel(
846
- @query
847
- @encode("iso8601")
848
- input: duration): NoContentResponse;
849
- `,
850
- false,
851
- false,
852
- true
853
- );
854
- assert.ok(schemaOutput);
855
- assertEqualContent(schemaOutput?.content!, buildParameterDef("string"));
856
- });
857
- });
858
- });
859
- describe("datetime generation", () => {
860
- it("should handle plainDate -> string in output model & `Date | string` in input model", async () => {
861
- const inputType = "Date | string";
862
- const outputType = "string";
863
- await verifyPropertyType("plainDate", inputType, {
864
- outputType
865
- });
866
- });
867
- it("should handle plainTime -> string in output model & `Date | string` in input model", async () => {
868
- const inputType = "Date | string";
869
- const outputType = "string";
870
- await verifyPropertyType("plainTime", inputType, {
871
- outputType
872
- });
873
- });
874
- it("should handle utcDateTime -> string in output model & `Date | string` in input model", async () => {
875
- const inputType = "Date | string";
876
- const outputType = "string";
877
- await verifyPropertyType("utcDateTime", inputType, {
878
- outputType
879
- });
880
- });
881
-
882
- it("should handle offsetDateTime -> string in output model & `Date | string` in input model", async () => {
883
- const inputType = "Date | string";
884
- const outputType = "string";
885
- await verifyPropertyType("offsetDateTime ", inputType, {
886
- outputType
887
- });
888
- });
889
-
890
- it("should handle datetime with encode `unixTimestamp`", async () => {
891
- const schemaOutput = await emitModelsFromCadl(
892
- `
893
- model SimpleModel {
894
- @encode("unixTimestamp", int32)
895
- createdAt: utcDateTime;
896
- }
897
- @route("/datetime/prop/unixTimestamp")
898
- @get
899
- op getModel(...SimpleModel): SimpleModel;
900
- `,
901
- false,
902
- true
903
- );
904
- assert.ok(schemaOutput);
905
- const { inputModelFile, outputModelFile } = schemaOutput!;
906
- assertEqualContent(
907
- inputModelFile?.content!,
908
- `
909
- export interface SimpleModel {
910
- "createdAt": number;
911
- }
912
- `
913
- );
914
- assertEqualContent(
915
- outputModelFile?.content!,
916
- `
917
- export interface SimpleModelOutput {
918
- "createdAt": number;
919
- }
920
- `
921
- );
922
- });
923
-
924
- it("should handle datetime with encode `rfc3339`", async () => {
925
- const schemaOutput = await emitModelsFromCadl(
926
- `
927
- model SimpleModel {
928
- @encode("rfc3339")
929
- createdAt: offsetDateTime;
930
- }
931
- @route("/datetime/prop/rfc3339")
932
- @get
933
- op getModel(...SimpleModel): SimpleModel;
934
- `,
935
- false,
936
- true
937
- );
938
- assert.ok(schemaOutput);
939
- const { inputModelFile, outputModelFile } = schemaOutput!;
940
- assertEqualContent(
941
- inputModelFile?.content!,
942
- `
943
- export interface SimpleModel {
944
- "createdAt": Date | string;
945
- }
946
- `
947
- );
948
- assertEqualContent(
949
- outputModelFile?.content!,
950
- `
951
- export interface SimpleModelOutput {
952
- "createdAt": string;
953
- }
954
- `
955
- );
956
- });
957
- });
958
- describe("record generation", () => {
959
- it("should handle Record<int32> -> Record<string, number>", async () => {
960
- await verifyPropertyType("Record<int32>", "Record<string, number>");
961
- });
962
- it("should handle Record<boolean> -> Record<string, boolean>", async () => {
963
- await verifyPropertyType("Record<boolean>", "Record<string, boolean>");
964
- });
965
- it("should handle Record<string> -> Record<string, string>", async () => {
966
- await verifyPropertyType("Record<string>", "Record<string, string>");
967
- });
968
- it("should handle Record<unknown> -> input 'Record<unknown>' output type 'Record<any>'", async () => {
969
- const cadlType = "Record<unknown>";
970
- const inputType = "Record<string, unknown>";
971
- const outputType = "Record<string, any>";
972
- await verifyPropertyType(cadlType, inputType, { outputType });
973
- });
974
- });
975
-
976
- describe("Record Model generation", () => {
977
- it("should handle Record<SimpleModel> -> Record<string, SimpleModel>", async () => {
978
- const cadlDefinition = `
979
- model SimpleModel {
980
- prop1: string;
981
- prop2: int32;
982
- }
983
- `;
984
- const cadlType = "Record<SimpleModel>";
985
- const inputModelName = "Record<string, SimpleModel>";
986
- await verifyPropertyType(cadlType, inputModelName, {
987
- additionalCadlDefinition: cadlDefinition,
988
- outputType: `Record<string, SimpleModelOutput>`,
989
- additionalInputContent: `
990
- export interface SimpleModel {
991
- prop1:string;
992
- prop2:number;
993
- }`,
994
- additionalOutputContent: `
995
- export interface SimpleModelOutput {
996
- prop1:string;
997
- prop2:number;
998
- }`
999
- });
1000
- });
1001
- });
1002
-
1003
- describe("property definition correctness", () => {
1004
- it("should handle @visibility(read) -> readonly ", async () => {
1005
- const cadlDefinition = `
1006
- model SimpleModel {
1007
- @visibility("read")
1008
- prop: int32;
1009
- prop1: int32;
1010
- }
1011
- `;
1012
- const cadlType = `SimpleModel`;
1013
- const inputModelName = "SimpleModel";
1014
- await verifyPropertyType(cadlType, inputModelName, {
1015
- additionalCadlDefinition: cadlDefinition,
1016
- outputType: `${inputModelName}Output`,
1017
- additionalInputContent: `
1018
- export interface ${inputModelName} {
1019
- prop1:number;
1020
- }`,
1021
- additionalOutputContent: `
1022
- export interface ${inputModelName}Output {
1023
- readonly prop:number;
1024
- prop1:number;
1025
- }`
1026
- });
1027
- });
1028
-
1029
- it("should handle optional parameter -> with question mark ", async () => {
1030
- const cadlDefinition = `
1031
- model SimpleModel {
1032
- prop?: int32;
1033
- }
1034
- `;
1035
- const cadlType = `SimpleModel`;
1036
- const inputModelName = cadlType;
1037
- await verifyPropertyType(cadlType, inputModelName, {
1038
- additionalCadlDefinition: cadlDefinition,
1039
- outputType: `${inputModelName}Output`,
1040
- additionalInputContent: `
1041
- export interface ${inputModelName} {
1042
- prop?:number;
1043
- }`,
1044
- additionalOutputContent: `
1045
- export interface ${inputModelName}Output {
1046
- prop?:number;
1047
- }`
1048
- });
1049
- });
1050
-
1051
- it("should handle nullable optional/required parameter", async () => {
1052
- const cadlDefinition = `
1053
- model SimpleModel {
1054
- foo?: string | null;
1055
- bar: string | null;
1056
- baz: string;
1057
- }
1058
- `;
1059
- const cadlType = `SimpleModel`;
1060
- const inputModelName = cadlType;
1061
- await verifyPropertyType(cadlType, inputModelName, {
1062
- additionalCadlDefinition: cadlDefinition,
1063
- outputType: `${inputModelName}Output`,
1064
- additionalInputContent: `
1065
- export interface ${inputModelName} {
1066
- foo?: string | null;
1067
- bar: string | null;
1068
- baz: string;
1069
- }`,
1070
- additionalOutputContent: `
1071
- export interface ${inputModelName}Output {
1072
- foo?: string | null;
1073
- bar: string | null;
1074
- baz: string;
1075
- }`
1076
- });
1077
- });
1078
-
1079
- it("should handle optional parameter with defaul value -> general type ", async () => {
1080
- const cadlDefinition = `
1081
- model SimpleModel {
1082
- prop?: int32 = 0;
1083
- }
1084
- `;
1085
- const cadlType = `SimpleModel`;
1086
- const inputModelName = cadlType;
1087
- await verifyPropertyType(cadlType, inputModelName, {
1088
- additionalCadlDefinition: cadlDefinition,
1089
- outputType: `${inputModelName}Output`,
1090
- additionalInputContent: `
1091
- export interface ${inputModelName} {
1092
- prop?:number;
1093
- }`,
1094
- additionalOutputContent: `
1095
- export interface ${inputModelName}Output {
1096
- prop?:number;
1097
- }`
1098
- });
1099
- });
1100
- });
1101
- describe("Union basic generation", () => {
1102
- it("should handle string | integer -> string | number", async () => {
1103
- const cadlType = "string | integer";
1104
- const typeScriptType = "string | number";
1105
- await verifyPropertyType(cadlType, typeScriptType);
1106
- });
1107
-
1108
- it("should handle int32 | string -> number | string", async () => {
1109
- const cadlType = "int32 | string";
1110
- const typeScriptType = "number | string";
1111
- await verifyPropertyType(cadlType, typeScriptType);
1112
- });
1113
-
1114
- it("should handle float32[] | string[] -> number[] | string[]", async () => {
1115
- const cadlType = "float32[] | string[]";
1116
- const typeScriptType = "number[] | string[]";
1117
- await verifyPropertyType(cadlType, typeScriptType);
1118
- });
1119
-
1120
- it("should handle boolean[] | string[] -> boolean[] | string[]", async () => {
1121
- const cadlType = "boolean[] | string[]";
1122
- const typeScriptType = "boolean[] | string[]";
1123
- await verifyPropertyType(cadlType, typeScriptType);
1124
- });
1125
-
1126
- it("should handle true[] | string[] -> true[] | string[]", async () => {
1127
- const cadlType = "true[] | string[]";
1128
- const typeScriptType = "true[] | string[]";
1129
- await verifyPropertyType(cadlType, typeScriptType);
1130
- });
1131
-
1132
- it("should handle 32[] | string[] -> 32[] | string[]", async () => {
1133
- const cadlType = "32[] | string[]";
1134
- const typeScriptType = "32[] | string[]";
1135
- await verifyPropertyType(cadlType, typeScriptType);
1136
- });
1137
-
1138
- it("should handle 'job'[] | string[] -> 'job'[] | string[]", async () => {
1139
- const cadlType = `"job"[] | string[]`;
1140
- const typeScriptType = `"job"[] | string[]`;
1141
- await verifyPropertyType(cadlType, typeScriptType);
1142
- });
1143
- });
1144
-
1145
- describe("Union Models generation", () => {
1146
- it("should handle named unions", async () => {
1147
- const cadlDefinition = `
1148
- @doc("This is a base model.")
1149
- model BaseModel {
1150
- name: string;
1151
- }
1152
-
1153
- @doc("The first one of the unioned model type.")
1154
- model Model1 extends BaseModel {
1155
- prop1: int32;
1156
- }
1157
-
1158
- @doc("The second one of the unioned model type.")
1159
- model Model2 extends BaseModel {
1160
- prop2: int32;
1161
- }
1162
-
1163
- union MyNamedUnion {
1164
- one: Model1,
1165
- two: Model2,
1166
- }
1167
- `;
1168
- const cadlType = "MyNamedUnion";
1169
- const inputModelName = "MyNamedUnion";
1170
- await verifyPropertyType(cadlType, inputModelName, {
1171
- additionalCadlDefinition: cadlDefinition,
1172
- outputType: `MyNamedUnionOutput`,
1173
- additionalInputContent: `
1174
- /** The first one of the unioned model type. */
1175
- export interface Model1 extends BaseModel {
1176
- prop1: number;
1177
- }
1178
-
1179
- /** This is a base model. */
1180
- export interface BaseModel {
1181
- name: string;
1182
- }
1183
-
1184
- /** The second one of the unioned model type. */
1185
- export interface Model2 extends BaseModel {
1186
- prop2: number;
1187
- }
1188
-
1189
- export type MyNamedUnion = Model1 | Model2;`,
1190
- additionalOutputContent: `
1191
- /** The first one of the unioned model type. */
1192
- export interface Model1Output extends BaseModelOutput {
1193
- prop1: number;
1194
- }
1195
-
1196
- /** This is a base model. */
1197
- export interface BaseModelOutput {
1198
- name: string;
1199
- }
1200
-
1201
- /** The second one of the unioned model type. */
1202
- export interface Model2Output extends BaseModelOutput {
1203
- prop2: number;
1204
- }
1205
-
1206
- export type MyNamedUnionOutput = Model1Output | Model2Output;`
1207
- });
1208
- });
1209
-
1210
- it("should handle named unions with null variant", async () => {
1211
- const cadlDefinition = `
1212
- @doc("The first one of the unioned model type.")
1213
- model Model1 {
1214
- prop1: int32;
1215
- }
1216
-
1217
- @doc("The second one of the unioned model type.")
1218
- model Model2 {
1219
- prop2: int32;
1220
- }
1221
-
1222
- union MyNamedUnion {
1223
- one: Model1,
1224
- two: Model2,
1225
- three: null
1226
- }
1227
- `;
1228
- const cadlType = "MyNamedUnion";
1229
- const inputModelName = "MyNamedUnion";
1230
- await verifyPropertyType(cadlType, inputModelName, {
1231
- additionalCadlDefinition: cadlDefinition,
1232
- outputType: `MyNamedUnionOutput`,
1233
- additionalInputContent: `
1234
- /** The first one of the unioned model type. */
1235
- export interface Model1 {
1236
- prop1: number;
1237
- }
1238
-
1239
- /** The second one of the unioned model type. */
1240
- export interface Model2 {
1241
- prop2: number;
1242
- }
1243
-
1244
- export type MyNamedUnion = Model1 | Model2 | null;`,
1245
- additionalOutputContent: `
1246
- /** The first one of the unioned model type. */
1247
- export interface Model1Output {
1248
- prop1: number;
1249
- }
1250
-
1251
- /** The second one of the unioned model type. */
1252
- export interface Model2Output {
1253
- prop2: number;
1254
- }
1255
-
1256
- export type MyNamedUnionOutput = Model1Output | Model2Output | null;`
1257
- });
1258
- });
1259
-
1260
- it("should handle nullable named unions", async () => {
1261
- const cadlDefinition = `
1262
- @doc("The first one of the unioned model type.")
1263
- model Model1 {
1264
- prop1: int32;
1265
- }
1266
-
1267
- @doc("The second one of the unioned model type.")
1268
- model Model2 {
1269
- prop2: int32;
1270
- }
1271
-
1272
- union MyNamedUnion {
1273
- one: Model1,
1274
- two: Model2,
1275
- }
1276
- `;
1277
- const cadlType = "MyNamedUnion | null";
1278
- const inputModelName = "MyNamedUnion | null";
1279
- await verifyPropertyType(cadlType, inputModelName, {
1280
- additionalCadlDefinition: cadlDefinition,
1281
- outputType: `MyNamedUnionOutput | null`,
1282
- additionalInputContent: `
1283
- /** The first one of the unioned model type. */
1284
- export interface Model1 {
1285
- prop1: number;
1286
- }
1287
-
1288
- /** The second one of the unioned model type. */
1289
- export interface Model2 {
1290
- prop2: number;
1291
- }
1292
-
1293
- export type MyNamedUnion = Model1 | Model2;`,
1294
- additionalOutputContent: `
1295
- /** The first one of the unioned model type. */
1296
- export interface Model1Output {
1297
- prop1: number;
1298
- }
1299
-
1300
- /** The second one of the unioned model type. */
1301
- export interface Model2Output {
1302
- prop2: number;
1303
- }
1304
-
1305
- export type MyNamedUnionOutput = Model1Output | Model2Output;`
1306
- });
1307
- });
1308
- });
1309
-
1310
- describe("'is' keyword generation", () => {
1311
- it("should handle A is B, only A is referenced", async () => {
1312
- const cadlDefinition = `
1313
- model B {
1314
- "prop": string;
1315
- }
1316
- model A is B{
1317
- "prop1": string;
1318
- }`;
1319
- const cadlType = "A";
1320
- const inputModelName = "A";
1321
- await verifyPropertyType(cadlType, inputModelName, {
1322
- additionalCadlDefinition: cadlDefinition,
1323
- outputType: `${inputModelName}Output`,
1324
- additionalInputContent: `
1325
- export interface ${inputModelName} {
1326
- "prop": string;
1327
- "prop1": string;
1328
- }`,
1329
- additionalOutputContent: `
1330
- export interface ${inputModelName}Output {
1331
- "prop": string;
1332
- "prop1": string;
1333
- }`
1334
- });
1335
- });
1336
-
1337
- it("should handle A is B, both A and B are referenced", async () => {
1338
- const schemaOutput = await emitModelsFromCadl(`
1339
- model B {
1340
- "prop": string;
1341
- }
1342
- model A is B{
1343
- "prop1": string;
1344
- }
1345
-
1346
- @route("/models")
1347
- @get
1348
- op getModel(@body input: A): B;`);
1349
- assert.ok(schemaOutput);
1350
- const { inputModelFile, outputModelFile } = schemaOutput!;
1351
- assert.ok(inputModelFile?.content);
1352
- assert.strictEqual(outputModelFile?.path, "outputModels.ts");
1353
- assertEqualContent(
1354
- inputModelFile?.content!,
1355
- `
1356
- export interface A {
1357
- "prop": string;
1358
- "prop1": string;
1359
- }
1360
- `
1361
- );
1362
- assertEqualContent(
1363
- outputModelFile?.content!,
1364
- `
1365
- export interface BOutput {
1366
- "prop": string;
1367
- }
1368
- `
1369
- );
1370
- });
1371
-
1372
- it("should handle A is B, B is string", async () => {
1373
- const cadlDefinition = `
1374
- scalar MyStr extends string;`;
1375
- const cadlType = "MyStr";
1376
- const inputModelName = "string";
1377
- await verifyPropertyType(cadlType, inputModelName, {
1378
- additionalCadlDefinition: cadlDefinition,
1379
- outputType: `${inputModelName}`
1380
- });
1381
- });
1382
- });
1383
-
1384
- describe("@projectedName", () => {
1385
- it("should generate projected json name for property", async () => {
1386
- const cadlDefinition = `
1387
- @doc("This is a Foo model.")
1388
- model FooModel {
1389
- @projectedName("json", "xJson")
1390
- @projectedName("javascript", "MadeForTS")
1391
- @projectedName("client", "NotToUseMeAsName") // Should be ignored
1392
- x: int32;
1393
-
1394
- y: string;
1395
- }
1396
- `;
1397
- const cadlType = "FooModel";
1398
- const inputModelName = "FooModel";
1399
- await verifyPropertyType(cadlType, inputModelName, {
1400
- additionalCadlDefinition: cadlDefinition,
1401
- outputType: `FooModelOutput`,
1402
- additionalInputContent: `
1403
- /** This is a Foo model. */
1404
- export interface FooModel {
1405
- xJson: number;
1406
- y: string;
1407
- }`,
1408
- additionalOutputContent: `
1409
- /** This is a Foo model. */
1410
- export interface FooModelOutput {
1411
- xJson: number;
1412
- y: string;
1413
- }`
1414
- });
1415
- });
1416
-
1417
- it("should generate augmented projected json name for property", async () => {
1418
- const cadlDefinition = `
1419
- @doc("This is a Foo model.")
1420
- model FooModel {
1421
- x: int32;
1422
- }
1423
-
1424
- @@projectedName(FooModel.x, "client", "NotToUseMeAsName") // Should be ignored
1425
- @@projectedName(FooModel.x, "javascript", "MadeForTS")
1426
- @@projectedName(FooModel.x, "json", "xJson")
1427
- `;
1428
- const cadlType = "FooModel";
1429
- const inputModelName = "FooModel";
1430
- await verifyPropertyType(cadlType, inputModelName, {
1431
- additionalCadlDefinition: cadlDefinition,
1432
- outputType: `FooModelOutput`,
1433
- additionalInputContent: `
1434
- /** This is a Foo model. */
1435
- export interface FooModel {
1436
- xJson: number;
1437
- }`,
1438
- additionalOutputContent: `
1439
- /** This is a Foo model. */
1440
- export interface FooModelOutput {
1441
- xJson: number;
1442
- }`
1443
- });
1444
- });
1445
-
1446
- it("should generate projected model name over friendly name", async () => {
1447
- const cadlDefinition = `
1448
- @projectedName("javascript", "CustomProjectedModelTS")
1449
- @projectedName("json", "CustomProjectedModel")
1450
- @friendlyName("CustomFriendlyModel")
1451
- @doc("This is a Foo model.")
1452
- model FooModel {
1453
- x: int32;
1454
- }
1455
- `;
1456
- const cadlType = "FooModel";
1457
- const inputModelName = "CustomProjectedModelTS";
1458
- await verifyPropertyType(cadlType, inputModelName, {
1459
- additionalCadlDefinition: cadlDefinition,
1460
- outputType: `CustomProjectedModelTSOutput`,
1461
- additionalInputContent: `
1462
- /** This is a Foo model. */
1463
- export interface CustomProjectedModelTS {
1464
- x: number;
1465
- }`,
1466
- additionalOutputContent: `
1467
- /** This is a Foo model. */
1468
- export interface CustomProjectedModelTSOutput {
1469
- x: number;
1470
- }`
1471
- });
1472
- });
1473
- });
1474
-
1475
- describe("@friendlyName for model", () => {
1476
- it("should generate friendly name", async () => {
1477
- const cadlDefinition = `
1478
- @friendlyName("MyNameIsA")
1479
- model A { }
1480
- `;
1481
- const cadlType = "A";
1482
- const inputModelName = "MyNameIsA";
1483
- await verifyPropertyType(cadlType, inputModelName, {
1484
- additionalCadlDefinition: cadlDefinition,
1485
- outputType: `MyNameIsAOutput`,
1486
- additionalInputContent: `
1487
- export interface MyNameIsA {}
1488
- `,
1489
- additionalOutputContent: `
1490
- export interface MyNameIsAOutput {}
1491
- `
1492
- });
1493
- });
1494
-
1495
- it("should generate templated friendly name", async () => {
1496
- const cadlDefinition = `
1497
- @friendlyName("{name}Model", Base)
1498
- model Base { }
1499
-
1500
- @friendlyName("Templated{name}", T)
1501
- model Templated<T> {
1502
- prop: T;
1503
- }
1504
-
1505
- model X is Templated<Base>{};
1506
- `;
1507
- const cadlType = "X";
1508
- const inputModelName = "TemplatedBase";
1509
- await verifyPropertyType(cadlType, inputModelName, {
1510
- additionalCadlDefinition: cadlDefinition,
1511
- outputType: `TemplatedBaseOutput`,
1512
- additionalInputContent: `
1513
- export interface TemplatedBase {
1514
- prop: BaseModel;
1515
- }
1516
-
1517
- export interface BaseModel {}
1518
- `,
1519
- additionalOutputContent: `
1520
- export interface TemplatedBaseOutput {
1521
- prop: BaseModelOutput;
1522
- }
1523
-
1524
- export interface BaseModelOutput {}
1525
- `
1526
- });
1527
- });
1528
- });
1529
- });