@autorest/powershell 4.0.0-dev.9 → 4.0.617

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 (303) hide show
  1. package/.rush/temp/operation/build/state.json +3 -0
  2. package/.rush/temp/package-deps_build.json +98 -98
  3. package/.rush/temp/shrinkwrap-deps.json +182 -234
  4. package/dist/cmdlets/class.d.ts +9 -2
  5. package/dist/cmdlets/class.d.ts.map +1 -1
  6. package/dist/cmdlets/class.js +663 -581
  7. package/dist/cmdlets/class.js.map +1 -1
  8. package/dist/cmdlets/namespace.d.ts.map +1 -1
  9. package/dist/cmdlets/namespace.js +38 -5
  10. package/dist/cmdlets/namespace.js.map +1 -1
  11. package/dist/enums/namespace.js +5 -5
  12. package/dist/enums/namespace.js.map +1 -1
  13. package/dist/generators/psm1.custom.js +2 -2
  14. package/dist/generators/psm1.custom.js.map +1 -1
  15. package/dist/generators/psm1.internal.js +2 -2
  16. package/dist/generators/psm1.internal.js.map +1 -1
  17. package/dist/generators/psm1.js +1 -1
  18. package/dist/generators/psm1.js.map +1 -1
  19. package/dist/generators/script-cmdlet.js +18 -18
  20. package/dist/generators/script-cmdlet.js.map +1 -1
  21. package/dist/internal/name-inferrer.d.ts +1 -1
  22. package/dist/internal/name-inferrer.d.ts.map +1 -1
  23. package/dist/internal/name-inferrer.js +12 -12
  24. package/dist/internal/name-inferrer.js.map +1 -1
  25. package/dist/internal/powershell-declarations.d.ts +1 -0
  26. package/dist/internal/powershell-declarations.d.ts.map +1 -1
  27. package/dist/internal/powershell-declarations.js +3 -2
  28. package/dist/internal/powershell-declarations.js.map +1 -1
  29. package/dist/internal/project.d.ts +3 -3
  30. package/dist/internal/project.d.ts.map +1 -1
  31. package/dist/internal/project.js +11 -11
  32. package/dist/internal/project.js.map +1 -1
  33. package/dist/internal/state.d.ts +1 -1
  34. package/dist/internal/state.d.ts.map +1 -1
  35. package/dist/llcsharp/clientruntime.d.ts +1 -0
  36. package/dist/llcsharp/clientruntime.d.ts.map +1 -1
  37. package/dist/llcsharp/clientruntime.js +12 -11
  38. package/dist/llcsharp/clientruntime.js.map +1 -1
  39. package/dist/llcsharp/code-model.d.ts +7 -7
  40. package/dist/llcsharp/code-model.d.ts.map +1 -1
  41. package/dist/llcsharp/enums/enum.d.ts +1 -1
  42. package/dist/llcsharp/enums/enum.d.ts.map +1 -1
  43. package/dist/llcsharp/enums/enum.js +42 -42
  44. package/dist/llcsharp/enums/enum.js.map +1 -1
  45. package/dist/llcsharp/exports.js +5 -1
  46. package/dist/llcsharp/exports.js.map +1 -1
  47. package/dist/llcsharp/generator.d.ts +1 -1
  48. package/dist/llcsharp/generator.d.ts.map +1 -1
  49. package/dist/llcsharp/model/idictionary.js +16 -16
  50. package/dist/llcsharp/model/idictionary.js.map +1 -1
  51. package/dist/llcsharp/model/interface.d.ts +1 -1
  52. package/dist/llcsharp/model/interface.d.ts.map +1 -1
  53. package/dist/llcsharp/model/interface.js +19 -19
  54. package/dist/llcsharp/model/interface.js.map +1 -1
  55. package/dist/llcsharp/model/model-class-dictionary.js +18 -18
  56. package/dist/llcsharp/model/model-class-dictionary.js.map +1 -1
  57. package/dist/llcsharp/model/model-class-json.js +19 -19
  58. package/dist/llcsharp/model/model-class-json.js.map +1 -1
  59. package/dist/llcsharp/model/model-class-serializer.d.ts +1 -1
  60. package/dist/llcsharp/model/model-class-serializer.d.ts.map +1 -1
  61. package/dist/llcsharp/model/model-class-serializer.js +6 -6
  62. package/dist/llcsharp/model/model-class-serializer.js.map +1 -1
  63. package/dist/llcsharp/model/model-class.d.ts +1 -1
  64. package/dist/llcsharp/model/model-class.d.ts.map +1 -1
  65. package/dist/llcsharp/model/model-class.js +97 -89
  66. package/dist/llcsharp/model/model-class.js.map +1 -1
  67. package/dist/llcsharp/model/namespace.d.ts +1 -1
  68. package/dist/llcsharp/model/namespace.d.ts.map +1 -1
  69. package/dist/llcsharp/model/namespace.js +2 -2
  70. package/dist/llcsharp/model/namespace.js.map +1 -1
  71. package/dist/llcsharp/model/property.d.ts +1 -1
  72. package/dist/llcsharp/model/property.d.ts.map +1 -1
  73. package/dist/llcsharp/model/property.js +20 -20
  74. package/dist/llcsharp/model/property.js.map +1 -1
  75. package/dist/llcsharp/operation/api-class.d.ts.map +1 -1
  76. package/dist/llcsharp/operation/api-class.js +26 -1
  77. package/dist/llcsharp/operation/api-class.js.map +1 -1
  78. package/dist/llcsharp/operation/method.d.ts +10 -5
  79. package/dist/llcsharp/operation/method.d.ts.map +1 -1
  80. package/dist/llcsharp/operation/method.js +276 -134
  81. package/dist/llcsharp/operation/method.js.map +1 -1
  82. package/dist/llcsharp/operation/parameter.d.ts +1 -1
  83. package/dist/llcsharp/operation/parameter.d.ts.map +1 -1
  84. package/dist/llcsharp/operation/parameter.js +10 -10
  85. package/dist/llcsharp/operation/parameter.js.map +1 -1
  86. package/dist/llcsharp/project.d.ts +2 -1
  87. package/dist/llcsharp/project.d.ts.map +1 -1
  88. package/dist/llcsharp/project.js +6 -0
  89. package/dist/llcsharp/project.js.map +1 -1
  90. package/dist/llcsharp/schema/Uuid.d.ts +1 -1
  91. package/dist/llcsharp/schema/Uuid.d.ts.map +1 -1
  92. package/dist/llcsharp/schema/Uuid.js +2 -2
  93. package/dist/llcsharp/schema/Uuid.js.map +1 -1
  94. package/dist/llcsharp/schema/array.d.ts +1 -1
  95. package/dist/llcsharp/schema/array.d.ts.map +1 -1
  96. package/dist/llcsharp/schema/array.js +45 -43
  97. package/dist/llcsharp/schema/array.js.map +1 -1
  98. package/dist/llcsharp/schema/binary.d.ts +1 -1
  99. package/dist/llcsharp/schema/binary.d.ts.map +1 -1
  100. package/dist/llcsharp/schema/binary.js +9 -9
  101. package/dist/llcsharp/schema/binary.js.map +1 -1
  102. package/dist/llcsharp/schema/boolean.d.ts +1 -1
  103. package/dist/llcsharp/schema/boolean.d.ts.map +1 -1
  104. package/dist/llcsharp/schema/byte-array.d.ts +1 -1
  105. package/dist/llcsharp/schema/byte-array.d.ts.map +1 -1
  106. package/dist/llcsharp/schema/byte-array.js +24 -24
  107. package/dist/llcsharp/schema/byte-array.js.map +1 -1
  108. package/dist/llcsharp/schema/char.d.ts +1 -1
  109. package/dist/llcsharp/schema/char.d.ts.map +1 -1
  110. package/dist/llcsharp/schema/char.js +1 -1
  111. package/dist/llcsharp/schema/char.js.map +1 -1
  112. package/dist/llcsharp/schema/date-time.d.ts +1 -1
  113. package/dist/llcsharp/schema/date-time.d.ts.map +1 -1
  114. package/dist/llcsharp/schema/date-time.js +45 -41
  115. package/dist/llcsharp/schema/date-time.js.map +1 -1
  116. package/dist/llcsharp/schema/date.d.ts +1 -1
  117. package/dist/llcsharp/schema/date.d.ts.map +1 -1
  118. package/dist/llcsharp/schema/duration.d.ts +1 -1
  119. package/dist/llcsharp/schema/duration.d.ts.map +1 -1
  120. package/dist/llcsharp/schema/duration.js +9 -7
  121. package/dist/llcsharp/schema/duration.js.map +1 -1
  122. package/dist/llcsharp/schema/enum.d.ts +6 -2
  123. package/dist/llcsharp/schema/enum.d.ts.map +1 -1
  124. package/dist/llcsharp/schema/enum.js +13 -4
  125. package/dist/llcsharp/schema/enum.js.map +1 -1
  126. package/dist/llcsharp/schema/extended-type-declaration.d.ts +1 -1
  127. package/dist/llcsharp/schema/extended-type-declaration.d.ts.map +1 -1
  128. package/dist/llcsharp/schema/fixed-array.d.ts +1 -1
  129. package/dist/llcsharp/schema/fixed-array.d.ts.map +1 -1
  130. package/dist/llcsharp/schema/fixed-array.js +44 -42
  131. package/dist/llcsharp/schema/fixed-array.js.map +1 -1
  132. package/dist/llcsharp/schema/integer.d.ts +1 -1
  133. package/dist/llcsharp/schema/integer.d.ts.map +1 -1
  134. package/dist/llcsharp/schema/integer.js +5 -5
  135. package/dist/llcsharp/schema/integer.js.map +1 -1
  136. package/dist/llcsharp/schema/object.d.ts +1 -1
  137. package/dist/llcsharp/schema/object.d.ts.map +1 -1
  138. package/dist/llcsharp/schema/object.js +28 -28
  139. package/dist/llcsharp/schema/object.js.map +1 -1
  140. package/dist/llcsharp/schema/password.d.ts +1 -1
  141. package/dist/llcsharp/schema/password.d.ts.map +1 -1
  142. package/dist/llcsharp/schema/password.js +13 -13
  143. package/dist/llcsharp/schema/password.js.map +1 -1
  144. package/dist/llcsharp/schema/primitive.d.ts +1 -1
  145. package/dist/llcsharp/schema/primitive.d.ts.map +1 -1
  146. package/dist/llcsharp/schema/primitive.js +40 -37
  147. package/dist/llcsharp/schema/primitive.js.map +1 -1
  148. package/dist/llcsharp/schema/schema-resolver.d.ts +1 -1
  149. package/dist/llcsharp/schema/schema-resolver.d.ts.map +1 -1
  150. package/dist/llcsharp/schema/schema-resolver.js +1 -1
  151. package/dist/llcsharp/schema/schema-resolver.js.map +1 -1
  152. package/dist/llcsharp/schema/string.d.ts +1 -1
  153. package/dist/llcsharp/schema/string.d.ts.map +1 -1
  154. package/dist/llcsharp/schema/string.js +48 -44
  155. package/dist/llcsharp/schema/string.js.map +1 -1
  156. package/dist/llcsharp/schema/uri.d.ts +1 -1
  157. package/dist/llcsharp/schema/uri.d.ts.map +1 -1
  158. package/dist/llcsharp/schema/uri.js +2 -2
  159. package/dist/llcsharp/schema/uri.js.map +1 -1
  160. package/dist/llcsharp/validations.js +2 -2
  161. package/dist/llcsharp/validations.js.map +1 -1
  162. package/dist/main.js +2 -2
  163. package/dist/main.js.map +1 -1
  164. package/dist/models/model-extensions.d.ts +1 -1
  165. package/dist/models/model-extensions.d.ts.map +1 -1
  166. package/dist/models/model-extensions.js +39 -39
  167. package/dist/models/model-extensions.js.map +1 -1
  168. package/dist/module/module-class.js +8 -8
  169. package/dist/module/module-class.js.map +1 -1
  170. package/dist/module/module-namespace.js +3 -3
  171. package/dist/module/module-namespace.js.map +1 -1
  172. package/dist/plugins/add-azure-completers-v2.d.ts +1 -1
  173. package/dist/plugins/add-azure-completers-v2.d.ts.map +1 -1
  174. package/dist/plugins/add-azure-completers-v2.js +3 -3
  175. package/dist/plugins/add-azure-completers-v2.js.map +1 -1
  176. package/dist/plugins/create-commands-v2.d.ts +8 -7
  177. package/dist/plugins/create-commands-v2.d.ts.map +1 -1
  178. package/dist/plugins/create-commands-v2.js +199 -61
  179. package/dist/plugins/create-commands-v2.js.map +1 -1
  180. package/dist/plugins/cs-namer-v2.d.ts +1 -1
  181. package/dist/plugins/cs-namer-v2.d.ts.map +1 -1
  182. package/dist/plugins/cs-namer-v2.js +40 -40
  183. package/dist/plugins/cs-namer-v2.js.map +1 -1
  184. package/dist/plugins/llcsharp-v2.d.ts +1 -1
  185. package/dist/plugins/llcsharp-v2.d.ts.map +1 -1
  186. package/dist/plugins/llcsharp-v2.js +9 -7
  187. package/dist/plugins/llcsharp-v2.js.map +1 -1
  188. package/dist/plugins/modifiers-v2.d.ts +1 -1
  189. package/dist/plugins/modifiers-v2.d.ts.map +1 -1
  190. package/dist/plugins/modifiers-v2.js +94 -82
  191. package/dist/plugins/modifiers-v2.js.map +1 -1
  192. package/dist/plugins/plugin-create-inline-properties.d.ts +1 -1
  193. package/dist/plugins/plugin-create-inline-properties.d.ts.map +1 -1
  194. package/dist/plugins/plugin-create-inline-properties.js +42 -31
  195. package/dist/plugins/plugin-create-inline-properties.js.map +1 -1
  196. package/dist/plugins/plugin-tweak-m4-model.d.ts +1 -1
  197. package/dist/plugins/plugin-tweak-m4-model.d.ts.map +1 -1
  198. package/dist/plugins/plugin-tweak-m4-model.js +8 -8
  199. package/dist/plugins/plugin-tweak-m4-model.js.map +1 -1
  200. package/dist/plugins/plugin-tweak-model-azure-v2.d.ts +1 -1
  201. package/dist/plugins/plugin-tweak-model-azure-v2.d.ts.map +1 -1
  202. package/dist/plugins/plugin-tweak-model-azure-v2.js +17 -17
  203. package/dist/plugins/plugin-tweak-model-azure-v2.js.map +1 -1
  204. package/dist/plugins/plugin-tweak-model.d.ts +1 -1
  205. package/dist/plugins/plugin-tweak-model.d.ts.map +1 -1
  206. package/dist/plugins/plugin-tweak-model.js +31 -31
  207. package/dist/plugins/plugin-tweak-model.js.map +1 -1
  208. package/dist/plugins/powershell-v2.d.ts +1 -1
  209. package/dist/plugins/powershell-v2.d.ts.map +1 -1
  210. package/dist/plugins/powershell-v2.js +26 -26
  211. package/dist/plugins/powershell-v2.js.map +1 -1
  212. package/dist/plugins/ps-namer-v2.d.ts +1 -1
  213. package/dist/plugins/ps-namer-v2.d.ts.map +1 -1
  214. package/dist/plugins/ps-namer-v2.js +31 -31
  215. package/dist/plugins/ps-namer-v2.js.map +1 -1
  216. package/dist/plugins/sdk-create-inline-properties.d.ts +1 -1
  217. package/dist/plugins/sdk-create-inline-properties.d.ts.map +1 -1
  218. package/dist/plugins/sdk-create-inline-properties.js +37 -37
  219. package/dist/plugins/sdk-create-inline-properties.js.map +1 -1
  220. package/dist/plugins/sdk-cs-namer.d.ts +1 -1
  221. package/dist/plugins/sdk-cs-namer.d.ts.map +1 -1
  222. package/dist/plugins/sdk-cs-namer.js +21 -21
  223. package/dist/plugins/sdk-cs-namer.js.map +1 -1
  224. package/dist/plugins/sdk-cs-simplifier.d.ts +1 -1
  225. package/dist/plugins/sdk-cs-simplifier.d.ts.map +1 -1
  226. package/dist/plugins/sdk-cs-simplifier.js +3 -3
  227. package/dist/plugins/sdk-cs-simplifier.js.map +1 -1
  228. package/dist/plugins/sdk-generate.d.ts +1 -1
  229. package/dist/plugins/sdk-generate.d.ts.map +1 -1
  230. package/dist/plugins/sdk-generate.js +14 -14
  231. package/dist/plugins/sdk-generate.js.map +1 -1
  232. package/dist/plugins/sdk-tweak-model.d.ts +1 -1
  233. package/dist/plugins/sdk-tweak-model.d.ts.map +1 -1
  234. package/dist/plugins/sdk-tweak-model.js +23 -23
  235. package/dist/plugins/sdk-tweak-model.js.map +1 -1
  236. package/dist/sdk/project.d.ts +2 -2
  237. package/dist/sdk/project.d.ts.map +1 -1
  238. package/dist/sdk/project.js +8 -8
  239. package/dist/sdk/project.js.map +1 -1
  240. package/dist/sdk/state.d.ts +2 -2
  241. package/dist/sdk/state.d.ts.map +1 -1
  242. package/dist/sdk/utility.d.ts +1 -1
  243. package/dist/sdk/utility.d.ts.map +1 -1
  244. package/dist/sdk/utility.js +17 -16
  245. package/dist/sdk/utility.js.map +1 -1
  246. package/dist/utils/PwshModel.d.ts +1 -1
  247. package/dist/utils/PwshModel.d.ts.map +1 -1
  248. package/dist/utils/PwshModel.js +1 -1
  249. package/dist/utils/PwshModel.js.map +1 -1
  250. package/dist/utils/SdkModel.d.ts +1 -1
  251. package/dist/utils/SdkModel.d.ts.map +1 -1
  252. package/dist/utils/SdkModel.js +1 -1
  253. package/dist/utils/SdkModel.js.map +1 -1
  254. package/dist/utils/command-operation.d.ts +9 -3
  255. package/dist/utils/command-operation.d.ts.map +1 -1
  256. package/dist/utils/command-operation.js +24 -4
  257. package/dist/utils/command-operation.js.map +1 -1
  258. package/dist/utils/components.d.ts +1 -1
  259. package/dist/utils/components.d.ts.map +1 -1
  260. package/dist/utils/components.js +2 -2
  261. package/dist/utils/components.js.map +1 -1
  262. package/dist/utils/http-operation.d.ts +2 -0
  263. package/dist/utils/http-operation.d.ts.map +1 -1
  264. package/dist/utils/http-operation.js +16 -12
  265. package/dist/utils/http-operation.js.map +1 -1
  266. package/dist/utils/model-state.d.ts +1 -1
  267. package/dist/utils/model-state.d.ts.map +1 -1
  268. package/dist/utils/model-state.js +20 -20
  269. package/dist/utils/model-state.js.map +1 -1
  270. package/dist/utils/programatic-operation.d.ts +1 -1
  271. package/dist/utils/programatic-operation.d.ts.map +1 -1
  272. package/dist/utils/programatic-operation.js +1 -1
  273. package/dist/utils/programatic-operation.js.map +1 -1
  274. package/dist/utils/resolve-conflicts.js +8 -8
  275. package/dist/utils/resolve-conflicts.js.map +1 -1
  276. package/dist/utils/schema.d.ts +1 -1
  277. package/dist/utils/schema.d.ts.map +1 -1
  278. package/dist/utils/schema.js +11 -11
  279. package/dist/utils/schema.js.map +1 -1
  280. package/dist/utils/security-scheme.d.ts +2 -2
  281. package/dist/utils/security-scheme.d.ts.map +1 -1
  282. package/dist/utils/security-scheme.js +2 -2
  283. package/dist/utils/security-scheme.js.map +1 -1
  284. package/dist/utils/sort-parameters.d.ts +1 -1
  285. package/dist/utils/sort-parameters.d.ts.map +1 -1
  286. package/package.json +7 -7
  287. package/resources/assets/build-module.ps1 +6 -1
  288. package/resources/assets/generate-help.ps1 +2 -2
  289. package/resources/assets/test-module.ps1 +3 -3
  290. package/resources/assets/tools/Resources/custom/New-AzDeployment.ps1 +2 -2
  291. package/resources/psruntime/BuildTime/Cmdlets/ExportHelpMarkdown.cs +4 -1
  292. package/resources/psruntime/BuildTime/Cmdlets/ExportProxyCmdlet.cs +4 -1
  293. package/resources/psruntime/BuildTime/Cmdlets/ExportPsd1.cs +6 -4
  294. package/resources/psruntime/BuildTime/MarkdownRenderer.cs +16 -8
  295. package/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs +2 -2
  296. package/resources/psruntime/BuildTime/Models/PsProxyTypes.cs +13 -0
  297. package/resources/psruntime/BuildTime/PsAttributes.cs +5 -0
  298. package/resources/psruntime/BuildTime/PsHelpers.cs +4 -3
  299. package/resources/psruntime/MessageAttribute.cs +23 -52
  300. package/resources/psruntime/MessageAttributeHelper.cs +5 -1
  301. package/resources/psruntime/Properties/Resources.Designer.cs +15 -2
  302. package/resources/psruntime/Properties/Resources.resx +4 -1
  303. package/resources/runtime/csharp/pipeline/PipelineMocking.cs +1 -1
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.CmdletClass = exports.NewAddInfoAttribute = exports.addInfoAttribute = exports.addDefaultInfo = exports.addPreviewMessage = exports.addParameterBreakingChange = exports.addPSArgumentCompleterAttribute = exports.isEnumImplementation = exports.NewAddCompleterInfo = exports.addCompleterInfo = exports.createStepper = void 0;
8
8
  const ejs = require('ejs');
9
- const codemodel_1 = require("@azure-tools/codemodel");
9
+ const codemodel_1 = require("@autorest/codemodel");
10
10
  const codemodel_v3_1 = require("@azure-tools/codemodel-v3");
11
11
  const command_operation_1 = require("../utils/command-operation");
12
12
  const schema_1 = require("../utils/schema");
@@ -15,7 +15,7 @@ const linq_1 = require("@azure-tools/linq");
15
15
  const codegen_csharp_1 = require("@azure-tools/codegen-csharp");
16
16
  const exports_1 = require("../llcsharp/exports");
17
17
  const powershell_declarations_1 = require("../internal/powershell-declarations");
18
- const autorest_extension_base_1 = require("@azure-tools/autorest-extension-base");
18
+ const extension_base_1 = require("@autorest/extension-base");
19
19
  const codegen_csharp_2 = require("@azure-tools/codegen-csharp");
20
20
  const model_class_1 = require("../llcsharp/model/model-class");
21
21
  const resourceName_1 = require("../utils/resourceName");
@@ -130,7 +130,7 @@ const category = {
130
130
  'Use': Verbs.Other,
131
131
  };
132
132
  function createStepper(p) {
133
- return codegen_csharp_1.toExpression(`${codegen_csharp_1.System.Linq.Enumerable.declaration}.Select<${exports_1.ClientRuntime.SendAsyncStep.declaration},${exports_1.ClientRuntime.SendAsyncStep.declaration}>(${p.value}, step =>
133
+ return (0, codegen_csharp_1.toExpression)(`${codegen_csharp_1.System.Linq.Enumerable.declaration}.Select<${exports_1.ClientRuntime.SendAsyncStep.declaration},${exports_1.ClientRuntime.SendAsyncStep.declaration}>(${p.value}, step =>
134
134
  (r, c, n) => {
135
135
  ${powershell_declarations_1.DefaultRunspace.value} = ${powershell_declarations_1.DefaultRunspace.value} ?? ${powershell_declarations_1.RunspaceFactory.declaration}.CreateRunspace();
136
136
  return step(r, c, n);
@@ -167,7 +167,7 @@ function isEnumImplementation(schema) {
167
167
  }
168
168
  exports.isEnumImplementation = isEnumImplementation;
169
169
  function addPSArgumentCompleterAttribute(targetProperty, parameterSchema) {
170
- const enumValues = linq_1.values(parameterSchema.language.csharp.enum.values).select(v => `"${v.value}"`).toArray().join(", ");
170
+ const enumValues = (0, linq_1.values)(parameterSchema.language.csharp.enum.values).select(v => `"${v.value}"`).toArray().join(', ');
171
171
  targetProperty.add(new codegen_csharp_1.Attribute(powershell_declarations_1.PSArgumentCompleterAttribute, { parameters: [`${enumValues}`] }));
172
172
  }
173
173
  exports.addPSArgumentCompleterAttribute = addPSArgumentCompleterAttribute;
@@ -175,11 +175,13 @@ function addParameterBreakingChange(targetProperty, parameter) {
175
175
  if (parameter.breakingChange) {
176
176
  const parameters = [];
177
177
  parameters.push(`"${parameter.breakingChange.parameterName}"`);
178
- if (parameter.breakingChange.deprecateByVersion) {
179
- parameters.push(`"${parameter.breakingChange.deprecateByVersion}"`);
180
- if (parameter.breakingChange.changeInEfectByDate)
181
- parameters.push(`"${parameter.breakingChange.changeInEfectByDate}"`);
178
+ if (!parameter.breakingChange.deprecateByVersion || !parameter.breakingChange.deprecateByAzVersion) {
179
+ throw new Error(`breakingChange.deprecateByVersion and breakingChange.deprecateByAzVersion must be set for ${parameter.name}`);
182
180
  }
181
+ parameters.push(`"${parameter.breakingChange.deprecateByVersion}"`);
182
+ parameters.push(`"${parameter.breakingChange.deprecateByAzVersion}"`);
183
+ if (parameter.breakingChange.changeInEfectByDate)
184
+ parameters.push(`"${parameter.breakingChange.changeInEfectByDate}"`);
183
185
  if (parameter.breakingChange.replacement)
184
186
  parameters.push(`ReplaceMentCmdletParameterName="${parameter.breakingChange.replacement}"`);
185
187
  if (parameter.breakingChange.isBecomingMandatory)
@@ -331,6 +333,11 @@ class CmdletClass extends codegen_csharp_1.Class {
331
333
  this.dropBodyParameter = operation.details.csharp.dropBodyParameter ? true : false;
332
334
  this.apply(objectInitializer);
333
335
  this.operation = operation;
336
+ this.apiCall = this.operation.callGraph[this.operation.callGraph.length - 1];
337
+ // create the response handlers
338
+ this.responses = [...(0, linq_1.values)(this.apiCall.responses), ...(0, linq_1.values)(this.apiCall.exceptions)];
339
+ this.callbackMethods = (0, linq_1.values)(this.responses).toArray().map(each => { var _a; return new codegen_csharp_1.LiteralExpression(((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.name) || ''); });
340
+ this.operationParameters = [];
334
341
  this.state = state;
335
342
  this.thingsToSerialize = [];
336
343
  this.variantName = variantName;
@@ -339,13 +346,13 @@ class CmdletClass extends codegen_csharp_1.Class {
339
346
  this.interfaces.push(exports_1.ClientRuntime.IContext);
340
347
  this.eventListener = new exports_1.EventListener(new codegen_csharp_1.LiteralExpression(`((${exports_1.ClientRuntime.IEventListener})this)`), true);
341
348
  this.isViaIdentity = variantName.indexOf('ViaIdentity') > 0;
342
- this.clientsidePagination = !!operation.details.csharp.clientsidePagination && !!((_a = operation.callGraph[0].language.csharp) === null || _a === void 0 ? void 0 : _a.pageable);
349
+ this.clientsidePagination = !!operation.details.csharp.clientsidePagination && !!((_a = this.apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.pageable);
343
350
  this.inputObjectParameterName = 'InputObject';
344
351
  }
345
352
  async init() {
346
353
  // basic stuff
347
354
  this.addCommonStuff();
348
- this.description = codegen_1.escapeString(this.operation.details.csharp.description);
355
+ this.description = (0, codegen_1.escapeString)(this.operation.details.csharp.description);
349
356
  const $this = this;
350
357
  this.add(new codegen_csharp_1.Method('BeginProcessing', codegen_csharp_1.dotnet.Void, {
351
358
  override: codegen_csharp_1.Modifier.Override,
@@ -354,10 +361,10 @@ class CmdletClass extends codegen_csharp_1.Class {
354
361
  *body() {
355
362
  if ($this.state.project.azure) {
356
363
  yield `var telemetryId = ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.GetTelemetryId.Invoke();`;
357
- yield codegen_csharp_1.If('telemetryId != "" && telemetryId != "internal"', '__correlationId = telemetryId;');
364
+ yield (0, codegen_csharp_1.If)('telemetryId != "" && telemetryId != "internal"', '__correlationId = telemetryId;');
358
365
  }
359
366
  yield 'Module.Instance.SetProxyConfiguration(Proxy, ProxyCredential, ProxyUseDefaultCredentials);';
360
- yield codegen_csharp_1.If($this.$('Break'), `${exports_1.ClientRuntime.AttachDebugger}.Break();`);
367
+ yield (0, codegen_csharp_1.If)($this.$('Break'), `${exports_1.ClientRuntime.AttachDebugger}.Break();`);
361
368
  yield $this.eventListener.syncSignal(powershell_declarations_1.Events.CmdletBeginProcessing);
362
369
  }
363
370
  }));
@@ -376,9 +383,45 @@ class CmdletClass extends codegen_csharp_1.Class {
376
383
  this.implementIContext();
377
384
  // add constructors
378
385
  this.implementConstructors();
386
+ // add callback methods
387
+ this.NewImplementResponseMethod();
379
388
  // processRecord
380
- this.NewImplementProcessRecord(this.operation);
381
- this.NewImplementProcessRecordAsync(this.operation);
389
+ this.NewImplementProcessRecord();
390
+ // find each parameter to the method, and find out where the value is going to come from.
391
+ this.operationParameters =
392
+ (0, linq_1.values)(this.apiCall.parameters).
393
+ // filter out constants and path parameters when using piping for identity
394
+ where(each => { var _a, _b; return !((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.constantValue) && ((_b = each.language.default) === null || _b === void 0 ? void 0 : _b.name) !== '$host'; } /* && (!$this.isViaIdentity || each.in !== ParameterLocation.Path) */).
395
+ select(p => {
396
+ var _a, _b, _c;
397
+ return {
398
+ name: (_a = p.language.csharp) === null || _a === void 0 ? void 0 : _a.name,
399
+ param: (0, linq_1.values)(this.properties).
400
+ where(each => each.metadata.parameterDefinition).
401
+ first(each => { var _a, _b; return ((_a = each.metadata.parameterDefinition.language.csharp) === null || _a === void 0 ? void 0 : _a.serializedName) === ((_b = p.language.csharp) === null || _b === void 0 ? void 0 : _b.serializedName); }),
402
+ parameterLocation: (_c = (_b = p.protocol) === null || _b === void 0 ? void 0 : _b.http) === null || _c === void 0 ? void 0 : _c.in
403
+ };
404
+ }).
405
+ select(each => {
406
+ if (each.param) {
407
+ const httpParam = (each.param.metadata.parameterDefinition);
408
+ if (httpParam.required) {
409
+ return {
410
+ name: each.param,
411
+ expression: each.param,
412
+ parameterLocation: each.parameterLocation
413
+ };
414
+ }
415
+ const httpParamTD = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(httpParam.schema, httpParam.required, this.state);
416
+ return {
417
+ name: each.param,
418
+ expression: (0, codegen_csharp_1.toExpression)(`this.InvocationInformation.BoundParameters.ContainsKey("${each.param.value}") ? ${each.param.value} : ${httpParamTD.defaultOfType}`),
419
+ parameterLocation: each.parameterLocation
420
+ };
421
+ }
422
+ return { name: each.name, expression: codegen_csharp_1.dotnet.Null, parameterLocation: each.parameterLocation };
423
+ }).toArray();
424
+ this.NewImplementProcessRecordAsync();
382
425
  this.debugMode = await this.state.getValue('debug', false);
383
426
  // json serialization
384
427
  this.NewImplementSerialization(this.operation);
@@ -393,7 +436,7 @@ class CmdletClass extends codegen_csharp_1.Class {
393
436
  var _a, _b, _c, _d, _e;
394
437
  const header = super.headerComment;
395
438
  let ops = '';
396
- for (const httpOperation of linq_1.values(this.operation.callGraph)) {
439
+ for (const httpOperation of (0, linq_1.values)(this.operation.callGraph)) {
397
440
  const request = (_a = httpOperation.requests) === null || _a === void 0 ? void 0 : _a[0];
398
441
  if (!request) {
399
442
  continue;
@@ -414,7 +457,7 @@ class CmdletClass extends codegen_csharp_1.Class {
414
457
  ops = `${ops}\n variant: ${this.operation.details.csharp.name}`;
415
458
  }
416
459
  }
417
- return ops ? `${header}\n${codegen_1.docComment(codegen_csharp_1.xmlize('remarks', ops))}` : header;
460
+ return ops ? `${header}\n${(0, codegen_1.docComment)((0, codegen_csharp_1.xmlize)('remarks', ops))}` : header;
418
461
  }
419
462
  AddSwitchViewProperty(responseType = codegen_csharp_1.dotnet.Object) {
420
463
  const fieldNames = this.fields.map(f => f.name);
@@ -432,7 +475,7 @@ class CmdletClass extends codegen_csharp_1.Class {
432
475
  FlushResponse(singleFlush = true) {
433
476
  const fieldNames = this.fields.map(f => f.name);
434
477
  return fieldNames.includes('_responseSize') ?
435
- codegen_csharp_1.If('1 ==_responseSize', function* () {
478
+ (0, codegen_csharp_1.If)('1 ==_responseSize', function* () {
436
479
  yield '// Flush buffer';
437
480
  if (singleFlush) {
438
481
  yield 'WriteObject(_firstResponse);';
@@ -447,16 +490,15 @@ class CmdletClass extends codegen_csharp_1.Class {
447
490
  if ($this.state.project.autoSwitchView) {
448
491
  if (isEnumerable) {
449
492
  return function* () {
450
- yield `var outputObjects = ${valueName};`;
451
- yield codegen_csharp_1.If('null != outputObjects', function* () {
452
- yield codegen_csharp_1.If('0 == _responseSize && 1 == outputObjects.Count', function* () {
453
- yield '_firstResponse = outputObjects[0];';
493
+ yield (0, codegen_csharp_1.If)(`null != ${valueName}`, function* () {
494
+ yield (0, codegen_csharp_1.If)(`0 == _responseSize && 1 == ${valueName}.Count`, function* () {
495
+ yield `_firstResponse = ${valueName}[0];`;
454
496
  yield '_responseSize = 1;';
455
497
  });
456
- yield codegen_csharp_1.Else(function* () {
498
+ yield (0, codegen_csharp_1.Else)(function* () {
457
499
  yield $this.FlushResponse(false);
458
500
  yield 'var values = new System.Collections.Generic.List<System.Management.Automation.PSObject>();';
459
- yield codegen_csharp_1.ForEach('value', 'outputObjects', function* () {
501
+ yield (0, codegen_csharp_1.ForEach)('value', valueName, function* () {
460
502
  yield 'values.Add(value.AddMultipleTypeNameIntoPSObject());';
461
503
  });
462
504
  yield 'WriteObject(values, true); ';
@@ -467,15 +509,14 @@ class CmdletClass extends codegen_csharp_1.Class {
467
509
  }
468
510
  else {
469
511
  return function* () {
470
- yield `var outputObject = ${valueName};`;
471
- yield codegen_csharp_1.If('null != outputObject', function* () {
472
- yield codegen_csharp_1.If('0 == _responseSize', function* () {
473
- yield '_firstResponse = outputObject;';
512
+ yield (0, codegen_csharp_1.If)(`null != ${valueName}`, function* () {
513
+ yield (0, codegen_csharp_1.If)('0 == _responseSize', function* () {
514
+ yield `_firstResponse = ${valueName};`;
474
515
  yield '_responseSize = 1;';
475
516
  });
476
- yield codegen_csharp_1.Else(function* () {
517
+ yield (0, codegen_csharp_1.Else)(function* () {
477
518
  yield $this.FlushResponse(false);
478
- yield 'WriteObject(outputObject.AddMultipleTypeNameIntoPSObject());';
519
+ yield `WriteObject(${valueName}.AddMultipleTypeNameIntoPSObject());`;
479
520
  yield '_responseSize = 2;';
480
521
  });
481
522
  });
@@ -491,7 +532,7 @@ class CmdletClass extends codegen_csharp_1.Class {
491
532
  // add a private copy of invocation information for our own uses.
492
533
  const privateInvocationInfo = this.add(new codegen_csharp_1.Field('__invocationInfo', powershell_declarations_1.InvocationInfo, { description: 'A copy of the Invocation Info (necessary to allow asJob to clone this cmdlet)', access: codegen_csharp_1.Access.Private }));
493
534
  this.invocationInfo = new codegen_csharp_1.Property('InvocationInformation', powershell_declarations_1.InvocationInfo, { description: 'Accessor for our copy of the InvocationInfo.' });
494
- this.invocationInfo.get = codegen_csharp_1.toExpression(`${privateInvocationInfo.value} = ${privateInvocationInfo.value} ?? this.MyInvocation `);
535
+ this.invocationInfo.get = (0, codegen_csharp_1.toExpression)(`${privateInvocationInfo.value} = ${privateInvocationInfo.value} ?? this.MyInvocation `);
495
536
  this.invocationInfo.set = new codegen_csharp_1.Statements(privateInvocationInfo.assign('value'));
496
537
  this.add(this.invocationInfo);
497
538
  if (this.state.project.azure) {
@@ -517,6 +558,9 @@ class CmdletClass extends codegen_csharp_1.Class {
517
558
  if ($this.state.project.autoSwitchView) {
518
559
  yield $this.FlushResponse();
519
560
  }
561
+ if (!$this.state.project.azure) {
562
+ yield $this.eventListener.syncSignal(powershell_declarations_1.Events.CmdletEndProcessing);
563
+ }
520
564
  });
521
565
  // debugging
522
566
  const brk = this.add(new codegen_csharp_1.Property('Break', powershell_declarations_1.SwitchParameter, { attributes: [], description: 'Wait for .NET debugger to attach' }));
@@ -542,40 +586,27 @@ class CmdletClass extends codegen_csharp_1.Class {
542
586
  proxyUri.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: ['Mandatory = false', 'DontShow = true', 'HelpMessage = "The URI for the proxy server to use"'] }));
543
587
  proxyUri.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.Runtime`] }));
544
588
  if (this.state.project.azure) {
545
- this.defaultProfile = this.add(new codegen_csharp_1.Property('DefaultProfile', powershell_declarations_1.PSObject, { description: 'The credentials, account, tenant, and subscription used for communication with Azure' }));
546
- this.defaultProfile.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: ['Mandatory = false', 'HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure."'] }));
589
+ this.defaultProfile = this.add(new codegen_csharp_1.Property('DefaultProfile', powershell_declarations_1.PSObject, { description: 'The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription' }));
590
+ this.defaultProfile.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: ['Mandatory = false', 'HelpMessage = "The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription."'] }));
547
591
  this.defaultProfile.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ValidateNotNull));
548
592
  this.defaultProfile.add(new codegen_csharp_1.Attribute(powershell_declarations_1.Alias, { parameters: ['"AzureRMContext"', '"AzureCredential"'] }));
549
593
  this.defaultProfile.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.Azure`] }));
550
594
  }
551
595
  }
552
- NewIsWritableCmdlet(operation) {
553
- var _a, _b;
554
- if (operation.callGraph[0].requests) {
555
- switch ((_b = (_a = operation.callGraph[0].requests[0]) === null || _a === void 0 ? void 0 : _a.protocol.http) === null || _b === void 0 ? void 0 : _b.method.toLowerCase()) {
556
- case 'put':
557
- case 'post':
558
- case 'delete':
559
- case 'patch':
560
- return true;
561
- }
562
- }
563
- return false;
564
- }
565
- NewImplementProcessRecord(operation) {
596
+ NewImplementProcessRecord() {
566
597
  const $this = this;
567
- const writable = this.NewIsWritableCmdlet(operation);
598
+ const operation = $this.operation;
568
599
  this.add(new codegen_csharp_1.Method('ProcessRecord', undefined, { access: codegen_csharp_1.Access.Protected, override: codegen_csharp_1.Modifier.Override, description: 'Performs execution of the command.' })).add(function* () {
569
600
  yield $this.eventListener.syncSignal(powershell_declarations_1.Events.CmdletProcessRecordStart);
570
601
  if ($this.state.project.azure) {
571
602
  yield $this.processRecordId.assign('System.Guid.NewGuid().ToString()');
572
603
  }
573
- yield codegen_csharp_1.Try(function* () {
604
+ yield (0, codegen_csharp_1.Try)(function* () {
574
605
  var _a;
575
606
  yield '// work';
576
607
  const normal = new codegen_csharp_1.Statements(function* () {
577
608
  const acr = new codegen_csharp_1.LocalVariable('asyncCommandRuntime', codegen_csharp_1.dotnet.Var, { initializer: powershell_declarations_1.AsyncCommandRuntime.new(codegen_csharp_1.dotnet.This, $this.cancellationToken) });
578
- yield codegen_csharp_1.Using(acr.declarationExpression, function* () {
609
+ yield (0, codegen_csharp_1.Using)(acr.declarationExpression, function* () {
579
610
  yield `${acr}.Wait( ProcessRecordAsync(),${$this.cancellationToken});`;
580
611
  });
581
612
  });
@@ -588,7 +619,7 @@ class CmdletClass extends codegen_csharp_1.Class {
588
619
  nowait.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.Runtime`] }));
589
620
  }
590
621
  const work = operation.asjob ? function* () {
591
- yield codegen_csharp_1.If('true == MyInvocation?.BoundParameters?.ContainsKey("AsJob")', function* () {
622
+ yield (0, codegen_csharp_1.If)('true == MyInvocation?.BoundParameters?.ContainsKey("AsJob")', function* () {
592
623
  // clone the cmdlet instance, since the instance can be reused and overwrite data.
593
624
  const instance = new codegen_csharp_1.LocalVariable('instance', codegen_csharp_1.dotnet.Var, { initializer: 'this.Clone()' });
594
625
  yield instance.declarationStatement;
@@ -605,46 +636,48 @@ class CmdletClass extends codegen_csharp_1.Class {
605
636
  // return the job to the user now.
606
637
  yield `WriteObject(${job});`;
607
638
  });
608
- yield codegen_csharp_1.Else(normal);
639
+ yield (0, codegen_csharp_1.Else)(normal);
609
640
  } : normal;
610
- if (writable) {
611
- yield codegen_csharp_1.If(`ShouldProcess($"Call remote '${(_a = operation.callGraph[0].language.csharp) === null || _a === void 0 ? void 0 : _a.name}' operation")`, work);
641
+ if ((0, command_operation_1.isWritableCmdlet)(operation) && !operation.details.csharp.supportShouldProcess) {
642
+ yield (0, codegen_csharp_1.If)(`ShouldProcess($"Call remote '${(_a = $this.apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.name}' operation")`, work);
612
643
  }
613
644
  else {
614
645
  yield work;
615
646
  }
616
647
  });
617
648
  const aggregateException = new codegen_csharp_1.Parameter('aggregateException', codegen_csharp_1.System.AggregateException);
618
- yield codegen_csharp_1.Catch(aggregateException, function* () {
649
+ yield (0, codegen_csharp_1.Catch)(aggregateException, function* () {
619
650
  yield '// unroll the inner exceptions to get the root cause';
620
- yield codegen_csharp_1.ForEach('innerException', new codegen_csharp_1.LiteralExpression(`${aggregateException.use}.Flatten().InnerExceptions`), function* () {
651
+ yield (0, codegen_csharp_1.ForEach)('innerException', new codegen_csharp_1.LiteralExpression(`${aggregateException.use}.Flatten().InnerExceptions`), function* () {
621
652
  yield $this.eventListener.syncSignal(powershell_declarations_1.Events.CmdletException, new codegen_csharp_1.LiteralExpression('$"{innerException.GetType().Name} - {innerException.Message} : {innerException.StackTrace}"'));
622
653
  yield '// Write exception out to error channel.';
623
- yield `WriteError( new ${powershell_declarations_1.ErrorRecord}(innerException,string.Empty, ${powershell_declarations_1.ErrorCategory('NotSpecified')}, null) );`;
654
+ yield `WriteError( new ${powershell_declarations_1.ErrorRecord}(innerException,string.Empty, ${(0, powershell_declarations_1.ErrorCategory)('NotSpecified')}, null) );`;
624
655
  });
625
656
  });
626
657
  const exception = new codegen_csharp_1.Parameter('exception', codegen_csharp_1.System.Exception);
627
- yield codegen_csharp_1.Catch(exception, function* () {
658
+ yield (0, codegen_csharp_1.Catch)(exception, function* () {
628
659
  yield $this.eventListener.syncSignal(powershell_declarations_1.Events.CmdletException, new codegen_csharp_1.LiteralExpression(`$"{${exception.use}.GetType().Name} - {${exception.use}.Message} : {${exception.use}.StackTrace}"`));
629
660
  yield '// Write exception out to error channel.';
630
- yield `WriteError( new ${powershell_declarations_1.ErrorRecord}(${exception.use},string.Empty, ${powershell_declarations_1.ErrorCategory('NotSpecified')}, null) );`;
661
+ yield `WriteError( new ${powershell_declarations_1.ErrorRecord}(${exception.use},string.Empty, ${(0, powershell_declarations_1.ErrorCategory)('NotSpecified')}, null) );`;
631
662
  }, { when: new codegen_csharp_1.LiteralExpression('(exception as System.Management.Automation.PipelineStoppedException)== null || (exception as System.Management.Automation.PipelineStoppedException).InnerException != null') });
632
- yield codegen_csharp_1.Finally(function* () {
663
+ yield (0, codegen_csharp_1.Finally)(function* () {
633
664
  yield $this.eventListener.syncSignalNoCheck(powershell_declarations_1.Events.CmdletProcessRecordEnd);
634
665
  });
635
666
  });
636
667
  }
637
- NewImplementProcessRecordAsync(operation) {
668
+ NewImplementProcessRecordAsync() {
638
669
  const $this = this;
639
- const PAR = this.add(new codegen_csharp_1.Method('ProcessRecordAsync', codegen_csharp_1.System.Threading.Tasks.Task(), {
670
+ const operationParameters = $this.operationParameters;
671
+ const pipeline = $this.$('Pipeline');
672
+ this.serializationMode = this.bodyParameter ? (this.operation.operationType === command_operation_1.OperationType.Create ? exports_1.ClientRuntime.SerializationMode.IncludeCreate : (this.operation.operationType === command_operation_1.OperationType.Update ? exports_1.ClientRuntime.SerializationMode.IncludeUpdate : undefined)) : undefined;
673
+ const PRA = this.add(new codegen_csharp_1.Method('ProcessRecordAsync', codegen_csharp_1.System.Threading.Tasks.Task(), {
640
674
  access: codegen_csharp_1.Access.Protected, async: codegen_csharp_1.Modifier.Async,
641
675
  description: 'Performs execution of the command, working asynchronously if required.',
642
676
  returnsDescription: `A <see cref="${codegen_csharp_1.System.Threading.Tasks.Task()}" /> that will be complete when handling of the method is completed.`
643
677
  }));
644
678
  // we don't want to use SynchContext here.
645
- PAR.push(codegen_csharp_1.Using('NoSynchronizationContext', ''));
646
- PAR.add(function* () {
647
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
679
+ PRA.push((0, codegen_csharp_1.Using)('NoSynchronizationContext', ''));
680
+ PRA.add(function* () {
648
681
  if ($this.apProp && $this.bodyParameter && $this.bodyParameterInfo) {
649
682
  // yield `${ClientRuntime}.DictionaryExtensions.HashTableToDictionary<${$this.bodyParameterInfo.type.declaration},${$this.bodyParameterInfo.valueType.declaration}>(${$this.apProp.value},${$this.bodyParameter.Cast($this.bodyParameterInfo.type)});`;
650
683
  let vt = $this.bodyParameterInfo.valueType.declaration;
@@ -654,16 +687,18 @@ class CmdletClass extends codegen_csharp_1.Class {
654
687
  yield `${exports_1.ClientRuntime}.DictionaryExtensions.HashTableToDictionary<${vt}>(${$this.apProp.value},${$this.bodyParameter}.AdditionalProperties);`;
655
688
  }
656
689
  // construct the call to the operation
690
+ if (!$this.state.project.azure) {
691
+ yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletProcessRecordAsyncStart);
692
+ }
657
693
  yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletGetPipeline);
658
- const pipeline = $this.$('Pipeline');
659
694
  if ($this.state.project.azure) {
660
695
  yield pipeline.assign(new codegen_csharp_1.LiteralExpression(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.CreatePipeline(${$this.invocationInfo}, ${$this.correlationId}, ${$this.processRecordId}, this.ParameterSetName, this.ExtensibleParameters)`));
661
696
  }
662
697
  else {
663
698
  yield pipeline.assign(new codegen_csharp_1.LiteralExpression(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.CreatePipeline(${$this.invocationInfo}, this.ParameterSetName, this.ExtensibleParameters)`));
664
699
  }
665
- yield codegen_csharp_1.If(codegen_csharp_1.IsNotNull($this.$('HttpPipelinePrepend')), pipeline.invokeMethod('Prepend', codegen_csharp_1.toExpression(`(this.CommandRuntime as Microsoft.Rest.ClientRuntime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(${$this.$('HttpPipelinePrepend')}) ?? ${$this.$('HttpPipelinePrepend')}`)));
666
- yield codegen_csharp_1.If(codegen_csharp_1.IsNotNull($this.$('HttpPipelineAppend')), pipeline.invokeMethod('Append', codegen_csharp_1.toExpression(`(this.CommandRuntime as Microsoft.Rest.ClientRuntime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(${$this.$('HttpPipelineAppend')}) ?? ${$this.$('HttpPipelineAppend')}`)));
700
+ yield (0, codegen_csharp_1.If)((0, codegen_csharp_1.IsNotNull)($this.$('HttpPipelinePrepend')), pipeline.invokeMethod('Prepend', (0, codegen_csharp_1.toExpression)(`(this.CommandRuntime as Microsoft.Rest.ClientRuntime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(${$this.$('HttpPipelinePrepend')}) ?? ${$this.$('HttpPipelinePrepend')}`)));
701
+ yield (0, codegen_csharp_1.If)((0, codegen_csharp_1.IsNotNull)($this.$('HttpPipelineAppend')), pipeline.invokeMethod('Append', (0, codegen_csharp_1.toExpression)(`(this.CommandRuntime as Microsoft.Rest.ClientRuntime.PowerShell.IAsyncCommandRuntimeExtensions)?.Wrap(${$this.$('HttpPipelineAppend')}) ?? ${$this.$('HttpPipelineAppend')}`)));
667
702
  yield '// get the client instance';
668
703
  // Add input pipeline if it is configured by developers.
669
704
  if ($this.operation.extensions.inputPipe) {
@@ -685,471 +720,517 @@ class CmdletClass extends codegen_csharp_1.Class {
685
720
  for (const vParam of [...vps.body, ...vps.operation]) {
686
721
  if (vParam.hidden) {
687
722
  const td = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(vParam.schema, true, $this.state, true);
688
- yield codegen_csharp_1.If(`true == this.MyInvocation?.BoundParameters?.ContainsKey("${vParam.name}")`, `${vParam.name} = (${td.declaration})this.MyInvocation.BoundParameters["${vParam.name}"];`);
723
+ yield (0, codegen_csharp_1.If)(`true == this.MyInvocation?.BoundParameters?.ContainsKey("${vParam.name}")`, `${vParam.name} = (${td.declaration})this.MyInvocation.BoundParameters["${vParam.name}"];`);
689
724
  }
690
725
  }
691
- const apiCall = operation.callGraph[0];
692
- // find each parameter to the method, and find out where the value is going to come from.
693
- const operationParameters = linq_1.values(apiCall.parameters).
694
- // filter out constants and path parameters when using piping for identity
695
- where(each => { var _a, _b; return !((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.constantValue) && ((_b = each.language.default) === null || _b === void 0 ? void 0 : _b.name) !== '$host'; } /* && (!$this.isViaIdentity || each.in !== ParameterLocation.Path) */).
696
- select(p => {
697
- var _a, _b;
698
- return {
699
- name: (_a = p.language.csharp) === null || _a === void 0 ? void 0 : _a.name,
700
- param: linq_1.values($this.properties).
701
- where(each => each.metadata.parameterDefinition).
702
- first(each => { var _a, _b; return ((_a = each.metadata.parameterDefinition.language.csharp) === null || _a === void 0 ? void 0 : _a.serializedName) === ((_b = p.language.csharp) === null || _b === void 0 ? void 0 : _b.serializedName); }),
703
- isPathParam: $this.isViaIdentity && ((_b = p.protocol.http) === null || _b === void 0 ? void 0 : _b.in) === codemodel_v3_1.ParameterLocation.Path
726
+ // is there a body parameter we should include?
727
+ // if ($this.bodyParameter) {
728
+ // operationParameters.push({ name: 'body', expression: $this.bodyParameter, isPathParam: false });
729
+ // }
730
+ yield (0, codegen_csharp_1.Try)(function* () {
731
+ // make the call.
732
+ let preProcess;
733
+ switch ($this.operation.commandType) {
734
+ case command_operation_1.CommandType.GetPut:
735
+ preProcess = $this.GetPutPreProcess;
736
+ break;
737
+ case command_operation_1.CommandType.Atomic:
738
+ default:
739
+ preProcess = undefined;
740
+ break;
741
+ }
742
+ const actualCall = function* () {
743
+ yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletBeforeAPICall);
744
+ yield $this.ImplementCall(preProcess);
745
+ yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletAfterAPICall);
704
746
  };
705
- }).
706
- select(each => {
707
- if (each.param) {
708
- const httpParam = (each.param.metadata.parameterDefinition);
709
- if (httpParam.required) {
710
- return {
711
- name: each.param,
712
- expression: each.param,
713
- isPathParam: each.isPathParam
747
+ if ($this.state.project.azure && operationParameters.find(each => each.expression && each.expression.value === 'SubscriptionId') && $this.operation.details.csharp.verb.toLowerCase() === 'get') {
748
+ yield 'foreach( var SubscriptionId in this.SubscriptionId )';
749
+ yield (0, codegen_csharp_1.BlockStatement)(actualCall);
750
+ }
751
+ else {
752
+ yield actualCall;
753
+ }
754
+ });
755
+ const ure = new codegen_csharp_1.Parameter('urexception', { declaration: `${exports_1.ClientRuntime.fullName}.UndeclaredResponseException` });
756
+ yield (0, codegen_csharp_1.Catch)(ure, function* () {
757
+ yield `WriteError(new global::System.Management.Automation.ErrorRecord(${ure.value}, ${ure.value}.StatusCode.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ${operationParameters.filter(e => (0, codegen_csharp_1.valueOf)(e.expression) !== 'null').map(each => `${each.name}=${each.expression}`).join(',')}})
758
+ {
759
+ ErrorDetails = new global::System.Management.Automation.ErrorDetails(${ure.value}.Message) { RecommendedAction = ${ure.value}.Action }
760
+ });`;
761
+ });
762
+ yield (0, codegen_csharp_1.Finally)(function* () {
763
+ yield $this.eventListener.signalNoCheck(powershell_declarations_1.Events.CmdletProcessRecordAsyncEnd);
764
+ });
765
+ });
766
+ }
767
+ *ImplementCall(preProcess) {
768
+ var _a, _b;
769
+ const $this = this;
770
+ const operation = $this.operation;
771
+ const apiCall = $this.apiCall;
772
+ const operationParameters = $this.operationParameters;
773
+ const callbackMethods = $this.callbackMethods;
774
+ const pipeline = $this.$('Pipeline');
775
+ const serializationMode = $this.serializationMode;
776
+ const bodyParameter = this.bodyParameter ? { name: 'body', value: (0, codegen_csharp_1.valueOf)(this.bodyParameter) } : undefined;
777
+ const pathParamsNotInIdentity = [];
778
+ const pathParamsInIdentity = [];
779
+ const pathParamsInIdentitySerializedName = [];
780
+ const headerParams = [];
781
+ const queryParams = [];
782
+ const otherParams = [];
783
+ const idschema = (0, linq_1.values)($this.state.project.model.schemas.objects).first(each => each.language.default.uid === 'universal-parameter-type');
784
+ let httpOperationName = `${(_a = apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.name}`;
785
+ if (idschema) {
786
+ const allVPs = (0, schema_1.getAllPublicVirtualProperties)((_b = idschema.language.csharp) === null || _b === void 0 ? void 0 : _b.virtualProperties);
787
+ const props = [...(0, linq_1.values)(idschema.properties)];
788
+ operationParameters.forEach(each => {
789
+ var _a, _b, _c, _d, _e, _f;
790
+ const pascalName = (0, codegen_1.pascalCase)(`${each.name}`);
791
+ //push parameters that is not path parameters into allParams and idOpParamsNotFromIdentity
792
+ if (each.parameterLocation !== codemodel_v3_1.ParameterLocation.Path) {
793
+ const param = {
794
+ name: undefined,
795
+ value: (0, codegen_csharp_1.valueOf)(each.expression)
796
+ };
797
+ switch (each.parameterLocation) {
798
+ case codemodel_v3_1.ParameterLocation.Header:
799
+ headerParams.push(param);
800
+ break;
801
+ case codemodel_v3_1.ParameterLocation.Query:
802
+ queryParams.push(param);
803
+ break;
804
+ default:
805
+ otherParams.push(param);
806
+ break;
807
+ }
808
+ return;
809
+ }
810
+ else {
811
+ const match = props.find(p => (0, codegen_1.pascalCase)(p.serializedName) === pascalName);
812
+ if (match) {
813
+ const defaultOfType = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(match.schema, true, $this.state).defaultOfType;
814
+ // match up vp name
815
+ const vp = allVPs.find(pp => (0, codegen_1.pascalCase)(pp.property.serializedName) === pascalName);
816
+ //push path parameters that form current identity into allParams, idOpParamsFromIdentity and idOpParamsFromIdentityserializedName
817
+ if (vp && each.expression === codegen_csharp_1.dotnet.Null) {
818
+ const param = {
819
+ name: `${$this.inputObjectParameterName}.${vp.name}`,
820
+ value: `${$this.inputObjectParameterName}.${vp.name} ?? ${defaultOfType}`
821
+ };
822
+ pathParamsInIdentity.push(param);
823
+ pathParamsInIdentitySerializedName.push(match.serializedName);
824
+ return;
825
+ }
826
+ // fall back!
827
+ console.error(`Unable to match identity parameter '${each.name}' member to appropriate virtual parameter. (Guessing '${(0, codegen_1.pascalCase)((_b = (_a = match.language.csharp) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '')}').`);
828
+ //push path parameters that current identity does not contain into allParams and idOpParamsNotFromIdentity
829
+ const param = {
830
+ name: `${(0, codegen_1.pascalCase)((_d = (_c = match.language.csharp) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '')}`,
831
+ value: `${(0, codegen_1.pascalCase)((_f = (_e = match.language.csharp) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '')}`
714
832
  };
833
+ pathParamsNotInIdentity.push(param);
834
+ }
835
+ else {
836
+ console.error(`Unable to match identity parameter '${each.name}' member to appropriate virtual parameter. (Guessing '${pascalName}')`);
837
+ /*
838
+ push path parameters do not match the name in identity schema into allParams and idOpParamsNotFromIdentity
839
+ for example, module 'Service' has only one GET API:
840
+ /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Service/resource1/{resource1Name}/resource2/{resource2Name}/resource3/{resource3Name}
841
+ the identity schema 'ServiceIdentity.cs' will have properties: {subscriptionId, resourceGroupName, resource1Name, resource2Name, resource3Name}
842
+ for variant which has (identity of resource2 + resource3Name) combined as parameters, the parameter name for 'resource3Name' is called 'Name' which do not match 'resource3Name' in 'ServiceIdentity.cs'
843
+ */
844
+ const param = {
845
+ name: `${pascalName}`,
846
+ value: `${pascalName}`
847
+ };
848
+ pathParamsNotInIdentity.push(param);
715
849
  }
716
- const httpParamTD = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(httpParam.schema, httpParam.required, $this.state);
717
- return {
718
- name: each.param,
719
- expression: codegen_csharp_1.toExpression(`this.InvocationInformation.BoundParameters.ContainsKey("${each.param.value}") ? ${each.param.value} : ${httpParamTD.defaultOfType}`),
720
- isPathParam: each.isPathParam
721
- };
722
850
  }
723
- return { name: each.name, expression: codegen_csharp_1.dotnet.Null, isPathParam: each.isPathParam };
724
- }).toArray();
725
- // is there a body parameter we should include?
726
- if ($this.bodyParameter) {
727
- operationParameters.push({ name: 'body', expression: $this.bodyParameter, isPathParam: false });
728
- }
729
- // create the response handlers
730
- const responses = [...linq_1.values(apiCall.responses), ...linq_1.values(apiCall.exceptions)];
731
- const callbackMethods = linq_1.values(responses).toArray().map(each => { var _a; return new codegen_csharp_1.LiteralExpression(((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.name) || ''); });
732
- // make callback methods
733
- for (const each of linq_1.values(responses)) {
734
- const isBinary = each.binary;
735
- const parameters = new Array();
736
- parameters.push(new codegen_csharp_1.Parameter('responseMessage', codegen_csharp_1.System.Net.Http.HttpResponseMessage, { description: `the raw response message as an ${codegen_csharp_1.System.Net.Http.HttpResponseMessage}.` }));
737
- if ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.responseType) {
738
- parameters.push(new codegen_csharp_1.Parameter('response', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: (_b = each.language.csharp) === null || _b === void 0 ? void 0 : _b.responseType }), {
739
- description: `the body result as a <see cref="${(_c = each.language.csharp) === null || _c === void 0 ? void 0 : _c.responseType.replace(/\[|\]|\?/g, '')}">${(_d = each.language.csharp) === null || _d === void 0 ? void 0 : _d.responseType}</see> from the remote call`
740
- }));
851
+ });
852
+ }
853
+ if ($this.isViaIdentity) {
854
+ //when identity does not contain property: 'Id'
855
+ const identityFromPathParams = function* () {
856
+ yield '// try to call with PATH parameters from Input Object';
857
+ if (idschema) {
858
+ for (const opParam of pathParamsInIdentity) {
859
+ if (opParam && opParam.name) {
860
+ yield (0, codegen_csharp_1.If)((0, codegen_csharp_1.IsNull)(opParam.name), `ThrowTerminatingError( new ${powershell_declarations_1.ErrorRecord}(new global::System.Exception("${$this.inputObjectParameterName} has null value for ${opParam.name}"),string.Empty, ${(0, powershell_declarations_1.ErrorCategory)('InvalidArgument')}, ${$this.inputObjectParameterName}) );`);
861
+ }
862
+ }
863
+ const pathParameters = [...pathParamsInIdentity.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...pathParamsNotInIdentity.map(each => (0, codegen_csharp_1.toExpression)(each.value))];
864
+ const nonPathParameters = [...headerParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...queryParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...otherParams.map(each => (0, codegen_csharp_1.toExpression)(each.value))];
865
+ const parameters = bodyParameter ? [...pathParameters, ...nonPathParameters, (0, codegen_csharp_1.toExpression)(bodyParameter.value), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline] : [...pathParameters, ...nonPathParameters, ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
866
+ if (serializationMode) {
867
+ parameters.push(serializationMode);
868
+ }
869
+ if (preProcess) {
870
+ yield preProcess($this, pathParameters, [...otherParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), codegen_csharp_1.dotnet.This, pipeline], false);
871
+ }
872
+ yield `await this.${$this.$('Client').invokeMethod(httpOperationName, ...parameters).implementation}`;
741
873
  }
742
- if ((_e = each.language.csharp) === null || _e === void 0 ? void 0 : _e.headerType) {
743
- parameters.push(new codegen_csharp_1.Parameter('headers', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: each.language.csharp.headerType }), { description: `the header result as a <see cref="${each.language.csharp.headerType}" /> from the remote call` }));
874
+ };
875
+ //when identity does contain property: 'Id'
876
+ const identityParams = function* () {
877
+ var _a, _b;
878
+ const path = (_b = (_a = apiCall.requests) === null || _a === void 0 ? void 0 : _a[0].protocol.http) === null || _b === void 0 ? void 0 : _b.path;
879
+ let pathParams = '';
880
+ //append path parameters which are not part of current identity
881
+ pathParamsNotInIdentity.forEach(each => {
882
+ var _a;
883
+ const serializedName = (_a = (0, linq_1.values)($this.properties)
884
+ .where(p => p.metadata.parameterDefinition)
885
+ .first(p => p.name === each.name)) === null || _a === void 0 ? void 0 : _a.metadata.parameterDefinition.language.csharp.serializedName;
886
+ if (each.name && serializedName) {
887
+ if (!pathParams) {
888
+ pathParams += '$"';
889
+ }
890
+ const resourceName = (0, resourceName_1.getResourceNameFromPath)(path, serializedName);
891
+ if (resourceName) {
892
+ pathParams += `/${resourceName}/{(global::System.Uri.EscapeDataString(this.${each.name}.ToString()))}`;
893
+ }
894
+ }
895
+ });
896
+ //add child resource to path for list operation
897
+ if ($this.operation.variant.startsWith('List') && (pathParamsInIdentitySerializedName === null || pathParamsInIdentitySerializedName === void 0 ? void 0 : pathParamsInIdentitySerializedName[pathParamsInIdentitySerializedName.length - 1])) {
898
+ const childResourceName = (0, resourceName_1.getChildResourceNameFromPath)(path, pathParamsInIdentitySerializedName === null || pathParamsInIdentitySerializedName === void 0 ? void 0 : pathParamsInIdentitySerializedName[pathParamsInIdentitySerializedName.length - 1]);
899
+ if (pathParams && pathParams.length > 0) {
900
+ pathParams += `/${childResourceName}`;
901
+ }
902
+ else {
903
+ pathParams += `"/${childResourceName}`;
904
+ }
744
905
  }
745
- if (isBinary) {
746
- parameters.push(new codegen_csharp_1.Parameter('response', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: 'global::System.IO.Stream' }), { description: 'the body result as a <see cref="global::System.IO.Stream" /> from the remote call' }));
906
+ if (pathParams && pathParams.length > 0) {
907
+ pathParams += '";';
908
+ yield `this.${$this.inputObjectParameterName}.Id += ${pathParams}`;
747
909
  }
748
- const override = `override${codegen_1.pascalCase(((_f = each.language.csharp) === null || _f === void 0 ? void 0 : _f.name) || '')}`;
749
- const returnNow = new codegen_csharp_1.Parameter('returnNow', codegen_csharp_1.System.Threading.Tasks.Task(codegen_csharp_1.dotnet.Bool), { modifier: codegen_csharp_2.ParameterModifier.Ref, description: `/// Determines if the rest of the ${(_g = each.language.csharp) === null || _g === void 0 ? void 0 : _g.name} method should be processed, or if the method should return immediately (set to true to skip further processing )` });
750
- const overrideResponseMethod = new codegen_csharp_1.PartialMethod(override, codegen_csharp_1.dotnet.Void, {
751
- parameters: [...parameters, returnNow],
752
- description: `<c>${override}</c> will be called before the regular ${(_h = each.language.csharp) === null || _h === void 0 ? void 0 : _h.name} has been processed, allowing customization of what happens on that response. Implement this method in a partial class to enable this behavior`,
753
- returnsDescription: `A <see cref="${codegen_csharp_1.System.Threading.Tasks.Task()}" /> that will be complete when handling of the method is completed.`
754
- });
755
- $this.add(overrideResponseMethod);
756
- const responseMethod = new codegen_csharp_1.Method(`${(_j = each.language.csharp) === null || _j === void 0 ? void 0 : _j.name}`, codegen_csharp_1.System.Threading.Tasks.Task(), {
757
- access: codegen_csharp_1.Access.Private,
758
- parameters,
759
- async: codegen_csharp_1.Modifier.Async,
760
- description: (_k = each.language.csharp) === null || _k === void 0 ? void 0 : _k.description,
761
- returnsDescription: `A <see cref="${codegen_csharp_1.System.Threading.Tasks.Task()}" /> that will be complete when handling of the method is completed.`
910
+ const pathParameters = [(0, codegen_csharp_1.toExpression)(`${$this.inputObjectParameterName}.Id`)];
911
+ const nonPathParameters = [...headerParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...queryParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...otherParams.map(each => (0, codegen_csharp_1.toExpression)(each.value))];
912
+ const parameters = bodyParameter ? [...pathParameters, ...nonPathParameters, (0, codegen_csharp_1.toExpression)(bodyParameter.value), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline] : [...pathParameters, ...nonPathParameters, ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
913
+ if (serializationMode) {
914
+ parameters.push(serializationMode);
915
+ }
916
+ if (preProcess) {
917
+ yield preProcess($this, pathParameters, [...otherParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), codegen_csharp_1.dotnet.This, pipeline], true);
918
+ }
919
+ yield `await this.${$this.$('Client').invokeMethod(`${httpOperationName}ViaIdentity`, ...parameters).implementation}`;
920
+ };
921
+ if (idschema && (0, linq_1.values)(idschema.properties).first(each => { var _a; return ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.uid) === 'universal-parameter:resource identity'; })) {
922
+ yield (0, codegen_csharp_1.If)(`${$this.inputObjectParameterName}?.Id != null`, identityParams);
923
+ yield (0, codegen_csharp_1.Else)(identityFromPathParams);
924
+ }
925
+ else {
926
+ yield identityFromPathParams;
927
+ }
928
+ }
929
+ else {
930
+ const pathParameters = [...pathParamsInIdentity.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...pathParamsNotInIdentity.map(each => (0, codegen_csharp_1.toExpression)(each.value))];
931
+ const nonPathParameters = [...headerParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...queryParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), ...otherParams.map(each => (0, codegen_csharp_1.toExpression)(each.value))];
932
+ let parameters = bodyParameter ? [...pathParameters, ...nonPathParameters, (0, codegen_csharp_1.toExpression)(bodyParameter.value), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline] : [...pathParameters, ...nonPathParameters, ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
933
+ if (serializationMode) {
934
+ parameters.push(serializationMode);
935
+ }
936
+ if (operation.variant.includes('ViaJsonString') || operation.variant.includes('ViaJsonFilePath')) {
937
+ httpOperationName = `${httpOperationName}ViaJsonString`;
938
+ const jsonParameter = new codegen_csharp_1.Field('_jsonString', codegen_csharp_1.System.String);
939
+ parameters = [...pathParameters, ...nonPathParameters, jsonParameter, ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
940
+ }
941
+ if (preProcess) {
942
+ yield preProcess($this, pathParameters, [...otherParams.map(each => (0, codegen_csharp_1.toExpression)(each.value)), codegen_csharp_1.dotnet.This, pipeline], false);
943
+ }
944
+ yield `await this.${$this.$('Client').invokeMethod(httpOperationName, ...parameters).implementation}`;
945
+ }
946
+ }
947
+ GetPutPreProcess(cmdlet, pathParams, nonPathParams, viaIdentity) {
948
+ var _a, _b;
949
+ const $this = cmdlet;
950
+ const updateBodyMethod = new codegen_csharp_1.Method(`Update${(_a = $this.bodyParameter) === null || _a === void 0 ? void 0 : _a.value}`, codegen_csharp_1.dotnet.Void, {
951
+ access: codegen_csharp_1.Access.Private
952
+ });
953
+ const httpOperationName = `${(_b = $this.operation.callGraph[0].language.csharp) === null || _b === void 0 ? void 0 : _b.name}${viaIdentity ? 'ViaIdentity' : ''}WithResult`;
954
+ if (!$this.hasMethodWithSameDeclaration(updateBodyMethod)) {
955
+ updateBodyMethod.add(function* () {
956
+ const bodyParameters = $this.properties.filter(each => {
957
+ for (const attribute of each.attributes) {
958
+ for (const parameter of attribute.parameters) {
959
+ if ('global::Microsoft.Rest.ParameterCategory.Body' === (0, codegen_csharp_1.valueOf)(parameter)) {
960
+ return true;
961
+ }
962
+ }
963
+ }
964
+ return false;
762
965
  });
763
- responseMethod.push(codegen_csharp_1.Using('NoSynchronizationContext', ''));
764
- responseMethod.add(function* () {
765
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
766
- const skip = codegen_csharp_2.Local('_returnNow', `${codegen_csharp_1.System.Threading.Tasks.Task(codegen_csharp_1.dotnet.Bool).declaration}.FromResult(${codegen_csharp_1.dotnet.False})`);
767
- yield skip.declarationStatement;
768
- yield `${overrideResponseMethod.invoke(...parameters, `ref ${skip.value}`)};`;
769
- yield `// if ${override} has returned true, then return right away.`;
770
- yield codegen_csharp_1.If(codegen_csharp_1.And(codegen_csharp_1.IsNotNull(skip), `await ${skip}`), codegen_csharp_1.Return());
771
- if ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.isErrorResponse) {
772
- // this should write an error to the error channel.
773
- yield `// Error Response : ${(_b = each.protocol.http) === null || _b === void 0 ? void 0 : _b.statusCodes[0]}`;
774
- const unexpected = function* () {
775
- var _a;
776
- yield '// Unrecognized Response. Create an error record based on what we have.';
777
- const ex = ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.responseType) ?
778
- codegen_csharp_2.Local('ex', `new ${exports_1.ClientRuntime.name}.RestException<${each.language.csharp.responseType}>(responseMessage, await response)`) :
779
- codegen_csharp_2.Local('ex', `new ${exports_1.ClientRuntime.name}.RestException(responseMessage)`);
780
- yield ex.declarationStatement;
781
- yield `WriteError( new global::System.Management.Automation.ErrorRecord(${ex.value}, ${ex.value}.Code, global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ${operationParameters.filter(e => codegen_csharp_1.valueOf(e.expression) !== 'null').map(each => `${each.name}=${each.expression}`).join(', ')} })
966
+ for (const param of bodyParameters) {
967
+ yield (0, codegen_csharp_1.If)(`(bool)(true == this.MyInvocation?.BoundParameters.ContainsKey("${param.name}"))`, `this.${param.name} = (${param.type.declaration})(this.MyInvocation?.BoundParameters["${param.name}"]);`);
968
+ }
969
+ });
970
+ $this.add(updateBodyMethod);
971
+ }
972
+ const getPut = function* () {
973
+ var _a;
974
+ yield `${(_a = $this.bodyParameter) === null || _a === void 0 ? void 0 : _a.value} = await this.${$this.$('Client').invokeMethod(httpOperationName, ...[...pathParams, ...nonPathParams]).implementation}`;
975
+ yield `this.${updateBodyMethod.name}();`;
976
+ };
977
+ return new codegen_csharp_1.Statements(getPut);
978
+ }
979
+ NewImplementResponseMethod() {
980
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
981
+ const $this = this;
982
+ const apiCall = $this.apiCall;
983
+ const operationParameters = $this.operationParameters;
984
+ const callbackMethods = $this.callbackMethods;
985
+ const pipeline = $this.$('Pipeline');
986
+ // make callback methods
987
+ for (const each of (0, linq_1.values)($this.responses)) {
988
+ const parameters = new Array();
989
+ const isBinary = each.binary;
990
+ parameters.push(new codegen_csharp_1.Parameter('responseMessage', codegen_csharp_1.System.Net.Http.HttpResponseMessage, { description: `the raw response message as an ${codegen_csharp_1.System.Net.Http.HttpResponseMessage}.` }));
991
+ if ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.responseType) {
992
+ parameters.push(new codegen_csharp_1.Parameter('response', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: (_b = each.language.csharp) === null || _b === void 0 ? void 0 : _b.responseType }), {
993
+ description: `the body result as a <see cref="${(_c = each.language.csharp) === null || _c === void 0 ? void 0 : _c.responseType.replace(/\[|\]|\?/g, '')}">${(_d = each.language.csharp) === null || _d === void 0 ? void 0 : _d.responseType}</see> from the remote call`
994
+ }));
995
+ }
996
+ if ((_e = each.language.csharp) === null || _e === void 0 ? void 0 : _e.headerType) {
997
+ parameters.push(new codegen_csharp_1.Parameter('headers', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: each.language.csharp.headerType }), { description: `the header result as a <see cref="${each.language.csharp.headerType}" /> from the remote call` }));
998
+ }
999
+ if (isBinary) {
1000
+ parameters.push(new codegen_csharp_1.Parameter('response', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: 'global::System.IO.Stream' }), { description: 'the body result as a <see cref="global::System.IO.Stream" /> from the remote call' }));
1001
+ }
1002
+ const override = `override${(0, codegen_1.pascalCase)(((_f = each.language.csharp) === null || _f === void 0 ? void 0 : _f.name) || '')}`;
1003
+ const returnNow = new codegen_csharp_1.Parameter('returnNow', codegen_csharp_1.System.Threading.Tasks.Task(codegen_csharp_1.dotnet.Bool), { modifier: codegen_csharp_2.ParameterModifier.Ref, description: `/// Determines if the rest of the ${(_g = each.language.csharp) === null || _g === void 0 ? void 0 : _g.name} method should be processed, or if the method should return immediately (set to true to skip further processing )` });
1004
+ const overrideResponseMethod = new codegen_csharp_1.PartialMethod(override, codegen_csharp_1.dotnet.Void, {
1005
+ parameters: [...parameters, returnNow],
1006
+ description: `<c>${override}</c> will be called before the regular ${(_h = each.language.csharp) === null || _h === void 0 ? void 0 : _h.name} has been processed, allowing customization of what happens on that response. Implement this method in a partial class to enable this behavior`,
1007
+ returnsDescription: `A <see cref="${codegen_csharp_1.System.Threading.Tasks.Task()}" /> that will be complete when handling of the method is completed.`
1008
+ });
1009
+ $this.add(overrideResponseMethod);
1010
+ const responseMethod = new codegen_csharp_1.Method(`${(_j = each.language.csharp) === null || _j === void 0 ? void 0 : _j.name}`, codegen_csharp_1.System.Threading.Tasks.Task(), {
1011
+ access: codegen_csharp_1.Access.Private,
1012
+ parameters,
1013
+ async: codegen_csharp_1.Modifier.Async,
1014
+ description: (_k = each.language.csharp) === null || _k === void 0 ? void 0 : _k.description,
1015
+ returnsDescription: `A <see cref="${codegen_csharp_1.System.Threading.Tasks.Task()}" /> that will be complete when handling of the method is completed.`
1016
+ });
1017
+ responseMethod.push((0, codegen_csharp_1.Using)('NoSynchronizationContext', ''));
1018
+ responseMethod.add(function* () {
1019
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
1020
+ const skip = (0, codegen_csharp_2.Local)('_returnNow', `${codegen_csharp_1.System.Threading.Tasks.Task(codegen_csharp_1.dotnet.Bool).declaration}.FromResult(${codegen_csharp_1.dotnet.False})`);
1021
+ yield skip.declarationStatement;
1022
+ yield `${overrideResponseMethod.invoke(...parameters, `ref ${skip.value}`)};`;
1023
+ yield `// if ${override} has returned true, then return right away.`;
1024
+ yield (0, codegen_csharp_1.If)((0, codegen_csharp_1.And)((0, codegen_csharp_1.IsNotNull)(skip), `await ${skip}`), (0, codegen_csharp_1.Return)());
1025
+ if ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.isErrorResponse) {
1026
+ // this should write an error to the error channel.
1027
+ yield `// Error Response : ${(_b = each.protocol.http) === null || _b === void 0 ? void 0 : _b.statusCodes[0]}`;
1028
+ const unexpected = function* () {
1029
+ var _a;
1030
+ yield '// Unrecognized Response. Create an error record based on what we have.';
1031
+ const ex = ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.responseType) ?
1032
+ (0, codegen_csharp_2.Local)('ex', `new ${exports_1.ClientRuntime.name}.RestException<${each.language.csharp.responseType}>(responseMessage, await response)`) :
1033
+ (0, codegen_csharp_2.Local)('ex', `new ${exports_1.ClientRuntime.name}.RestException(responseMessage)`);
1034
+ yield ex.declarationStatement;
1035
+ yield `WriteError( new global::System.Management.Automation.ErrorRecord(${ex.value}, ${ex.value}.Code, global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ${operationParameters.filter(e => (0, codegen_csharp_1.valueOf)(e.expression) !== 'null').map(each => `${each.name}=${each.expression}`).join(', ')} })
782
1036
  {
783
1037
  ErrorDetails = new global::System.Management.Automation.ErrorDetails(${ex.value}.Message) { RecommendedAction = ${ex.value}.Action }
784
1038
  });`;
785
- };
786
- if (each.schema !== undefined) {
787
- // the schema should be the error information.
788
- // this supports both { error { message, code} } and { message, code}
789
- let props = schema_1.getAllPublicVirtualProperties((_c = each.schema.language.csharp) === null || _c === void 0 ? void 0 : _c.virtualProperties);
790
- const errorProperty = linq_1.values(props).first(p => p.property.serializedName === 'error');
791
- let ep = '';
792
- if (errorProperty) {
793
- props = schema_1.getAllPublicVirtualProperties((_d = errorProperty.property.schema.language.csharp) === null || _d === void 0 ? void 0 : _d.virtualProperties);
794
- ep = `${errorProperty.name}?.`;
795
- }
796
- const codeProp = props.find(p => p.name.toLowerCase().indexOf('code') > -1); // first property with 'code'
797
- const messageProp = props.find(p => p.name.toLowerCase().indexOf('message') > -1); // first property with 'message'
798
- const actionProp = props.find(p => p.name.toLowerCase().indexOf('action') > -1); // first property with 'action'
799
- if (codeProp && messageProp) {
800
- const lcode = new codegen_csharp_1.LocalVariable('code', codegen_csharp_1.dotnet.Var, { initializer: `(await response)?.${ep}${codeProp.name}` });
801
- const lmessage = new codegen_csharp_1.LocalVariable('message', codegen_csharp_1.dotnet.Var, { initializer: `(await response)?.${ep}${messageProp.name}` });
802
- const laction = actionProp ? new codegen_csharp_1.LocalVariable('action', codegen_csharp_1.dotnet.Var, { initializer: `(await response)?.${ep}${actionProp.name} ?? ${codegen_csharp_1.System.String.Empty}` }) : undefined;
803
- yield lcode;
804
- yield lmessage;
805
- yield laction;
806
- yield codegen_csharp_1.If(codegen_csharp_1.Or(codegen_csharp_1.IsNull(lcode), (codegen_csharp_1.IsNull(lmessage))), unexpected);
807
- yield codegen_csharp_1.Else(`WriteError( new global::System.Management.Automation.ErrorRecord(new global::System.Exception($"[{${lcode}}] : {${lmessage}}"), ${lcode}?.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ${operationParameters.filter(e => codegen_csharp_1.valueOf(e.expression) !== 'null').map(each => `${each.name}=${each.expression}`).join(', ')} })
1039
+ };
1040
+ if (each.schema !== undefined) {
1041
+ // the schema should be the error information.
1042
+ // this supports both { error { message, code} } and { message, code}
1043
+ let props = (0, schema_1.getAllPublicVirtualProperties)((_c = each.schema.language.csharp) === null || _c === void 0 ? void 0 : _c.virtualProperties);
1044
+ const errorProperty = (0, linq_1.values)(props).first(p => p.property.serializedName === 'error');
1045
+ let ep = '';
1046
+ if (errorProperty) {
1047
+ props = (0, schema_1.getAllPublicVirtualProperties)((_d = errorProperty.property.schema.language.csharp) === null || _d === void 0 ? void 0 : _d.virtualProperties);
1048
+ ep = `${errorProperty.name}?.`;
1049
+ }
1050
+ const codeProp = props.find(p => p.name.toLowerCase().indexOf('code') > -1); // first property with 'code'
1051
+ const messageProp = props.find(p => p.name.toLowerCase().indexOf('message') > -1); // first property with 'message'
1052
+ const actionProp = props.find(p => p.name.toLowerCase().indexOf('action') > -1); // first property with 'action'
1053
+ if (codeProp && messageProp) {
1054
+ const lcode = new codegen_csharp_1.LocalVariable('code', codegen_csharp_1.dotnet.Var, { initializer: `(await response)?.${ep}${codeProp.name}` });
1055
+ const lmessage = new codegen_csharp_1.LocalVariable('message', codegen_csharp_1.dotnet.Var, { initializer: `(await response)?.${ep}${messageProp.name}` });
1056
+ const laction = actionProp ? new codegen_csharp_1.LocalVariable('action', codegen_csharp_1.dotnet.Var, { initializer: `(await response)?.${ep}${actionProp.name} ?? ${codegen_csharp_1.System.String.Empty}` }) : undefined;
1057
+ yield lcode;
1058
+ yield lmessage;
1059
+ yield laction;
1060
+ yield (0, codegen_csharp_1.If)((0, codegen_csharp_1.Or)((0, codegen_csharp_1.IsNull)(lcode), ((0, codegen_csharp_1.IsNull)(lmessage))), unexpected);
1061
+ yield (0, codegen_csharp_1.Else)(`WriteError( new global::System.Management.Automation.ErrorRecord(new global::System.Exception($"[{${lcode}}] : {${lmessage}}"), ${lcode}?.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ${operationParameters.filter(e => (0, codegen_csharp_1.valueOf)(e.expression) !== 'null').map(each => `${each.name}=${each.expression}`).join(', ')} })
808
1062
  {
809
1063
  ErrorDetails = new global::System.Management.Automation.ErrorDetails(${lmessage}) { RecommendedAction = ${laction || codegen_csharp_1.System.String.Empty} }
810
1064
  });`);
811
- return;
812
- }
813
- else {
814
- yield unexpected;
815
- return;
816
- }
1065
+ return;
817
1066
  }
818
1067
  else {
819
1068
  yield unexpected;
820
1069
  return;
821
1070
  }
822
1071
  }
823
- yield `// ${(_e = each.language.csharp) === null || _e === void 0 ? void 0 : _e.name} - response for ${(_f = each.protocol.http) === null || _f === void 0 ? void 0 : _f.statusCodes[0]} / ${linq_1.values((_g = each.protocol.http) === null || _g === void 0 ? void 0 : _g.mediaTypes).join('/')}`;
824
- if ('schema' in each) {
825
- const schema = each.schema;
826
- if ((_h = apiCall.language.csharp) === null || _h === void 0 ? void 0 : _h.pageable) {
827
- const pageable = apiCall.language.csharp.pageable;
828
- if ($this.clientsidePagination) {
829
- yield '// clientside pagination enabled';
830
- }
831
- yield '// response should be returning an array of some kind. +Pageable';
832
- yield `// ${pageable.responseType} / ${pageable.itemName || '<none>'} / ${pageable.nextLinkName || '<none>'}`;
833
- switch (pageable.responseType) {
834
- // the result is (or works like a x-ms-pageable)
835
- case 'pageable':
836
- case 'nested-array':
837
- {
838
- const valueProperty = (_j = schema.properties) === null || _j === void 0 ? void 0 : _j.find(p => p.serializedName === pageable.itemName);
839
- const nextLinkProperty = (_l = (_k = schema) === null || _k === void 0 ? void 0 : _k.properties) === null || _l === void 0 ? void 0 : _l.find(p => p.serializedName === pageable.nextLinkName);
840
- if (valueProperty && nextLinkProperty) {
841
- // it's pageable!
842
- const result = new codegen_csharp_1.LocalVariable('result', codegen_csharp_1.dotnet.Var, { initializer: new codegen_csharp_1.LiteralExpression('await response') });
843
- yield result.declarationStatement;
844
- // write out the current contents
845
- const vp = schema_1.getVirtualPropertyFromPropertyName((_m = schema.language.csharp) === null || _m === void 0 ? void 0 : _m.virtualProperties, valueProperty.serializedName);
846
- if (vp) {
847
- if ($this.clientsidePagination) {
848
- yield (codegen_csharp_1.If('(ulong)result.Value.Count <= this.PagingParameters.Skip', function* () {
849
- yield ('this.PagingParameters.Skip = this.PagingParameters.Skip - (ulong)result.Value.Count;');
850
- }));
851
- yield codegen_csharp_1.Else(function* () {
852
- yield ('ulong toRead = Math.Min(this.PagingParameters.First, (ulong)result.Value.Count - this.PagingParameters.Skip);');
853
- yield ('var requiredResult = result.Value.GetRange((int)this.PagingParameters.Skip, (int)toRead);');
854
- yield $this.WriteObjectWithViewControl(`requiredResult`, true);
855
- yield ('this.PagingParameters.Skip = 0;');
856
- yield ('this.PagingParameters.First = this.PagingParameters.First <= toRead ? 0 : this.PagingParameters.First - toRead;');
857
- });
858
- }
859
- else {
860
- yield $this.WriteObjectWithViewControl(`${result.value}.${vp.name}`, true);
861
- }
862
- }
863
- const nl = schema_1.getVirtualPropertyFromPropertyName((_o = schema.language.csharp) === null || _o === void 0 ? void 0 : _o.virtualProperties, nextLinkProperty.serializedName);
864
- if (nl) {
865
- $this.add(new codegen_csharp_1.Field('_isFirst', codegen_csharp_1.dotnet.Bool, {
866
- access: codegen_csharp_1.Access.Private,
867
- initialValue: new codegen_csharp_1.LiteralExpression('true'),
868
- description: 'A flag to tell whether it is the first onOK call.'
869
- }));
870
- $this.add(new codegen_csharp_1.Field('_nextLink', codegen_csharp_1.dotnet.String, {
871
- access: codegen_csharp_1.Access.Private,
872
- description: 'Link to retrieve next page.'
873
- }));
874
- const nextLinkName = `${result.value}.${nl.name}`;
875
- yield `_nextLink = ${nextLinkName};`;
876
- const nextLinkCondition = $this.clientsidePagination ? '_nextLink != null && this.PagingParameters.First > 0' : '_nextLink != null';
877
- yield (codegen_csharp_1.If('_isFirst', function* () {
878
- yield '_isFirst = false;';
879
- yield (codegen_csharp_1.While(nextLinkCondition, codegen_csharp_1.If('responseMessage.RequestMessage is System.Net.Http.HttpRequestMessage requestMessage ', function* () {
880
- var _a;
881
- yield `requestMessage = requestMessage.Clone(new global::System.Uri( _nextLink ),${exports_1.ClientRuntime.Method.Get} );`;
882
- yield $this.eventListener.signal(powershell_declarations_1.Events.FollowingNextLink);
883
- yield `await this.${$this.$('Client').invokeMethod(`${(_a = apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.name}_Call`, ...[codegen_csharp_1.toExpression('requestMessage'), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline]).implementation}`;
884
- })));
1072
+ else {
1073
+ yield unexpected;
1074
+ return;
1075
+ }
1076
+ }
1077
+ yield `// ${(_e = each.language.csharp) === null || _e === void 0 ? void 0 : _e.name} - response for ${(_f = each.protocol.http) === null || _f === void 0 ? void 0 : _f.statusCodes[0]} / ${(0, linq_1.values)((_g = each.protocol.http) === null || _g === void 0 ? void 0 : _g.mediaTypes).join('/')}`;
1078
+ if ('schema' in each) {
1079
+ const schema = each.schema;
1080
+ const props = (0, schema_1.getAllPublicVirtualProperties)((_h = schema.language.csharp) === null || _h === void 0 ? void 0 : _h.virtualProperties);
1081
+ const rType = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(schema, true, $this.state);
1082
+ const result = new codegen_csharp_1.LocalVariable('result', codegen_csharp_1.dotnet.Var, { initializer: new codegen_csharp_1.LiteralExpression('(await response)') });
1083
+ yield `// (await response) // should be ${rType.declaration}`;
1084
+ yield result.declarationStatement;
1085
+ if ((_j = apiCall.language.csharp) === null || _j === void 0 ? void 0 : _j.pageable) {
1086
+ const pageable = apiCall.language.csharp.pageable;
1087
+ if ($this.clientsidePagination) {
1088
+ yield '// clientside pagination enabled';
1089
+ }
1090
+ yield '// response should be returning an array of some kind. +Pageable';
1091
+ yield `// ${pageable.responseType} / ${pageable.itemName || '<none>'} / ${pageable.nextLinkName || '<none>'}`;
1092
+ switch (pageable.responseType) {
1093
+ // the result is (or works like a x-ms-pageable)
1094
+ case 'pageable':
1095
+ case 'nested-array':
1096
+ {
1097
+ const valueProperty = (_k = schema.properties) === null || _k === void 0 ? void 0 : _k.find(p => p.serializedName === pageable.itemName);
1098
+ const nextLinkProperty = (_l = schema === null || schema === void 0 ? void 0 : schema.properties) === null || _l === void 0 ? void 0 : _l.find(p => p.serializedName === pageable.nextLinkName);
1099
+ if (valueProperty && nextLinkProperty) {
1100
+ // it's pageable!
1101
+ // write out the current contents
1102
+ const vp = (0, schema_1.getVirtualPropertyFromPropertyName)((_m = schema.language.csharp) === null || _m === void 0 ? void 0 : _m.virtualProperties, valueProperty.serializedName);
1103
+ if (vp) {
1104
+ if ($this.clientsidePagination) {
1105
+ yield ((0, codegen_csharp_1.If)('(ulong)result.Value.Count <= this.PagingParameters.Skip', function* () {
1106
+ yield ('this.PagingParameters.Skip = this.PagingParameters.Skip - (ulong)result.Value.Count;');
885
1107
  }));
1108
+ yield (0, codegen_csharp_1.Else)(function* () {
1109
+ yield ('ulong toRead = Math.Min(this.PagingParameters.First, (ulong)result.Value.Count - this.PagingParameters.Skip);');
1110
+ yield ('var requiredResult = result.Value.GetRange((int)this.PagingParameters.Skip, (int)toRead);');
1111
+ yield $this.WriteObjectWithViewControl('requiredResult', true);
1112
+ yield ('this.PagingParameters.Skip = 0;');
1113
+ yield ('this.PagingParameters.First = this.PagingParameters.First <= toRead ? 0 : this.PagingParameters.First - toRead;');
1114
+ });
886
1115
  }
887
- return;
888
- }
889
- else if (valueProperty) {
890
- // it's just a nested array
891
- const p = codemodel_v3_1.getVirtualPropertyFromPropertyName((_p = schema.language.csharp) === null || _p === void 0 ? void 0 : _p.virtualProperties, valueProperty.serializedName);
892
- if (p) {
893
- yield $this.WriteObjectWithViewControl(`(await response).${p.name}`, true);
1116
+ else {
1117
+ yield $this.WriteObjectWithViewControl(`${result.value}.${vp.name}`, true);
894
1118
  }
895
- return;
896
1119
  }
1120
+ const nl = (0, schema_1.getVirtualPropertyFromPropertyName)((_o = schema.language.csharp) === null || _o === void 0 ? void 0 : _o.virtualProperties, nextLinkProperty.serializedName);
1121
+ if (nl) {
1122
+ $this.add(new codegen_csharp_1.Field('_isFirst', codegen_csharp_1.dotnet.Bool, {
1123
+ access: codegen_csharp_1.Access.Private,
1124
+ initialValue: new codegen_csharp_1.LiteralExpression('true'),
1125
+ description: 'A flag to tell whether it is the first onOK call.'
1126
+ }));
1127
+ $this.add(new codegen_csharp_1.Field('_nextLink', codegen_csharp_1.dotnet.String, {
1128
+ access: codegen_csharp_1.Access.Private,
1129
+ description: 'Link to retrieve next page.'
1130
+ }));
1131
+ const nextLinkName = `${result.value}.${nl.name}`;
1132
+ yield `_nextLink = ${nextLinkName};`;
1133
+ const nextLinkCondition = $this.clientsidePagination ? '!String.IsNullOrEmpty(_nextLink) && this.PagingParameters.First > 0' : '!String.IsNullOrEmpty(_nextLink)';
1134
+ yield ((0, codegen_csharp_1.If)('_isFirst', function* () {
1135
+ yield '_isFirst = false;';
1136
+ yield ((0, codegen_csharp_1.While)(nextLinkCondition, (0, codegen_csharp_1.If)('responseMessage.RequestMessage is System.Net.Http.HttpRequestMessage requestMessage ', function* () {
1137
+ var _a;
1138
+ yield `requestMessage = requestMessage.Clone(new global::System.Uri( _nextLink ),${exports_1.ClientRuntime.Method.Get} );`;
1139
+ yield $this.eventListener.signal(powershell_declarations_1.Events.FollowingNextLink);
1140
+ yield `await this.${$this.$('Client').invokeMethod(`${(_a = apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.name}_Call`, ...[(0, codegen_csharp_1.toExpression)('requestMessage'), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline]).implementation}`;
1141
+ })));
1142
+ }));
1143
+ }
1144
+ return;
897
1145
  }
898
- break;
899
- // it's just an array,
900
- case 'array':
901
- // just write-object(enumerate) with the output
902
- yield $this.WriteObjectWithViewControl('(await response)', true);
903
- return;
904
- }
905
- // ok, let's see if the response type
906
- }
907
- const props = schema_1.getAllPublicVirtualProperties((_q = schema.language.csharp) === null || _q === void 0 ? void 0 : _q.virtualProperties);
908
- const outValue = (linq_1.length(props) === 1) ? `(await response).${props[0].name}` : '(await response)';
909
- // we expect to get back some data from this call.
910
- const rType = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(schema, true, $this.state);
911
- yield `// (await response) // should be ${rType.declaration}`;
912
- if ($this.hasStreamOutput && $this.outFileParameter) {
913
- const outfile = $this.outFileParameter;
914
- const provider = codegen_csharp_2.Local('provider');
915
- provider.initializer = undefined;
916
- const paths = codegen_csharp_2.Local('paths', `this.SessionState.Path.GetResolvedProviderPathFromPSPath(${outfile.value}, out ${provider.declarationExpression})`);
917
- yield paths.declarationStatement;
918
- yield codegen_csharp_1.If(`${provider.value}.Name != "FileSystem" || ${paths.value}.Count == 0`, `ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Invalid output path."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}) );`);
919
- yield codegen_csharp_1.If(`${paths.value}.Count > 1`, `ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Multiple output paths not allowed."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}) );`);
920
- if (rType.declaration === codegen_csharp_1.System.IO.Stream.declaration) {
921
- // this is a stream output. write to outfile
922
- const stream = codegen_csharp_2.Local('stream', 'await response');
923
- yield codegen_csharp_1.Using(stream.declarationExpression, function* () {
924
- const fileStream = codegen_csharp_2.Local('fileStream', `global::System.IO.File.OpenWrite(${paths.value}[0])`);
925
- yield codegen_csharp_1.Using(fileStream.declarationExpression, `await ${stream.value}.CopyToAsync(${fileStream.value});`);
926
- });
927
- }
928
- else {
929
- // assuming byte array output (via outValue)
930
- yield `global::System.IO.File.WriteAllBytes(${paths.value}[0],${outValue});`;
931
- }
932
- yield codegen_csharp_1.If('true == MyInvocation?.BoundParameters?.ContainsKey("PassThru")', function* () {
933
- // no return type. Let's just return ... true?
934
- yield 'WriteObject(true);';
935
- });
936
- return;
937
- }
938
- // let's just return the result object (or unwrapped result object)
939
- yield $this.WriteObjectWithViewControl(`${outValue}`);
940
- return;
941
- }
942
- // in m4, there will be no schema deinfed for the binary response, instead, we will have a field called binary with value true.
943
- if ('binary' in each) {
944
- yield '// (await response) // should be global::System.IO.Stream';
945
- if ($this.hasStreamOutput && $this.outFileParameter) {
946
- const outfile = $this.outFileParameter;
947
- const provider = codegen_csharp_2.Local('provider');
948
- provider.initializer = undefined;
949
- const paths = codegen_csharp_2.Local('paths', 'new global::System.Collections.ObjectModel.Collection<global::System.String>()');
950
- yield paths.declarationStatement;
951
- yield codegen_csharp_1.Try(function* () {
952
- yield `${paths.value} = this.SessionState.Path.GetResolvedProviderPathFromPSPath(${outfile.value}, out ${provider.declarationExpression});`;
953
- yield codegen_csharp_1.If(`${provider.value}.Name != "FileSystem" || ${paths.value}.Count == 0`, `ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new global::System.Exception("Invalid output path."), string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}));`);
954
- yield codegen_csharp_1.If(`${paths.value}.Count > 1`, `ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new global::System.Exception("Multiple output paths not allowed."), string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}));`);
955
- });
956
- const notfound = new codegen_csharp_1.Parameter('', { declaration: 'global::System.Management.Automation.ItemNotFoundException' });
957
- yield codegen_csharp_1.Catch(notfound, function* () {
958
- yield '// If the file does not exist, we will try to create it';
959
- yield `${paths.value}.Add(${outfile.value});`;
960
- });
961
- // this is a stream output. write to outfile
962
- const stream = codegen_csharp_2.Local('stream', 'await response');
963
- yield codegen_csharp_1.Using(stream.declarationExpression, function* () {
964
- const fileStream = codegen_csharp_2.Local('fileStream', `global::System.IO.File.OpenWrite(${paths.value}[0])`);
965
- yield codegen_csharp_1.Using(fileStream.declarationExpression, `await ${stream.value}.CopyToAsync(${fileStream.value});`);
966
- });
967
- yield codegen_csharp_1.If('true == MyInvocation?.BoundParameters?.ContainsKey("PassThru")', function* () {
968
- // no return type. Let's just return ... true?
969
- yield 'WriteObject(true);';
970
- });
971
- return;
972
- }
973
- }
974
- yield codegen_csharp_1.If('true == MyInvocation?.BoundParameters?.ContainsKey("PassThru")', function* () {
975
- // no return type. Let's just return ... true?
976
- yield 'WriteObject(true);';
977
- });
978
- });
979
- $this.add(responseMethod);
980
- }
981
- yield codegen_csharp_1.Try(function* () {
982
- // make the call.
983
- const actualCall = function* () {
984
- var _a, _b;
985
- yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletBeforeAPICall);
986
- const nonPathParams = operationParameters.filter(each => !each.isPathParam);
987
- const allParams = [];
988
- const idOpParamsNotFromIdentity = [];
989
- const idOpParamsFromIdentity = [];
990
- const idOpParamsFromIdentityserializedName = [];
991
- const idschema = linq_1.values($this.state.project.model.schemas.objects).first(each => each.language.default.uid === 'universal-parameter-type');
992
- let serializationMode = null;
993
- if ($this.bodyParameter) {
994
- if ($this.operation.operationType === command_operation_1.OperationType.Create) {
995
- serializationMode = exports_1.ClientRuntime.SerializationMode.IncludeCreate;
996
- }
997
- else if ($this.operation.operationType === command_operation_1.OperationType.Update) {
998
- serializationMode = exports_1.ClientRuntime.SerializationMode.IncludeUpdate;
999
- }
1000
- }
1001
- if ($this.isViaIdentity) {
1002
- if (idschema) {
1003
- const allVPs = schema_1.getAllPublicVirtualProperties((_a = idschema.language.csharp) === null || _a === void 0 ? void 0 : _a.virtualProperties);
1004
- const props = [...linq_1.values(idschema.properties)];
1005
- operationParameters.forEach(each => {
1006
- var _a, _b, _c, _d, _e, _f;
1007
- const pascalName = codegen_1.pascalCase(`${each.name}`);
1008
- //push parameters that is not path parameters into allParams and idOpParamsNotFromIdentity
1009
- if (!each.isPathParam) {
1010
- const param = {
1011
- name: undefined,
1012
- value: codegen_csharp_1.valueOf(each.expression)
1013
- };
1014
- allParams.push(param);
1015
- idOpParamsNotFromIdentity.push(param);
1016
- return;
1017
- }
1018
- const match = props.find(p => codegen_1.pascalCase(p.serializedName) === pascalName);
1019
- if (match) {
1020
- const defaultOfType = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(match.schema, true, $this.state).defaultOfType;
1021
- // match up vp name
1022
- const vp = allVPs.find(pp => codegen_1.pascalCase(pp.property.serializedName) === pascalName);
1023
- //push path parameters that form current identity into allParams, idOpParamsFromIdentity and idOpParamsFromIdentityserializedName
1024
- if (vp && each.expression === codegen_csharp_1.dotnet.Null) {
1025
- const param = {
1026
- name: `${$this.inputObjectParameterName}.${vp.name}`,
1027
- value: `${$this.inputObjectParameterName}.${vp.name} ?? ${defaultOfType}`
1028
- };
1029
- allParams.push(param);
1030
- idOpParamsFromIdentity.push(param);
1031
- idOpParamsFromIdentityserializedName.push(match.serializedName);
1146
+ else if (valueProperty) {
1147
+ // it's just a nested array
1148
+ const p = (0, codemodel_v3_1.getVirtualPropertyFromPropertyName)((_p = schema.language.csharp) === null || _p === void 0 ? void 0 : _p.virtualProperties, valueProperty.serializedName);
1149
+ if (p) {
1150
+ yield $this.WriteObjectWithViewControl(`${result.value}.${p.name}`, true);
1151
+ }
1032
1152
  return;
1033
1153
  }
1034
- // fall back!
1035
- console.error(`Unable to match identity parameter '${each.name}' member to appropriate virtual parameter. (Guessing '${codegen_1.pascalCase((_b = (_a = match.language.csharp) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '')}').`);
1036
- //push path parameters that current identity does not contain into allParams and idOpParamsNotFromIdentity
1037
- const param = {
1038
- name: `${codegen_1.pascalCase((_d = (_c = match.language.csharp) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '')}`,
1039
- value: `${codegen_1.pascalCase((_f = (_e = match.language.csharp) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '')}`
1040
- };
1041
- allParams.push(param);
1042
- idOpParamsNotFromIdentity.push(param);
1043
1154
  }
1044
- else {
1045
- console.error(`Unable to match identity parameter '${each.name}' member to appropriate virtual parameter. (Guessing '${pascalName}')`);
1046
- /*
1047
- push path parameters do not match the name in identity schema into allParams and idOpParamsNotFromIdentity
1048
- for example, module 'Service' has only one GET API:
1049
- /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Service/resource1/{resource1Name}/resource2/{resource2Name}/resource3/{resource3Name}
1050
- the identity schema 'ServiceIdentity.cs' will have properties: {subscriptionId, resourceGroupName, resource1Name, resource2Name, resource3Name}
1051
- for variant which has (identity of resource2 + resource3Name) combined as parameters, the parameter name for 'resource3Name' is called 'Name' which do not match 'resource3Name' in 'ServiceIdentity.cs'
1052
- */
1053
- const param = {
1054
- name: `${pascalName}`,
1055
- value: `${pascalName}`
1056
- };
1057
- allParams.push(param);
1058
- idOpParamsNotFromIdentity.push(param);
1059
- }
1060
- });
1155
+ break;
1156
+ // it's just an array,
1157
+ case 'array':
1158
+ // just write-object(enumerate) with the output
1159
+ yield $this.WriteObjectWithViewControl(result.value, true);
1160
+ return;
1061
1161
  }
1062
- const parameters = [codegen_csharp_1.toExpression(`${$this.inputObjectParameterName}.Id`), ...nonPathParams.map(each => each.expression), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
1063
- //when identity does not contain property: 'Id'
1064
- const identityFromPathParams = function* () {
1065
- var _a;
1066
- yield '// try to call with PATH parameters from Input Object';
1067
- if (idschema) {
1068
- for (const opParam of idOpParamsFromIdentity) {
1069
- if (opParam && opParam.name) {
1070
- yield codegen_csharp_1.If(codegen_csharp_1.IsNull(opParam.name), `ThrowTerminatingError( new ${powershell_declarations_1.ErrorRecord}(new global::System.Exception("${$this.inputObjectParameterName} has null value for ${opParam.name}"),string.Empty, ${powershell_declarations_1.ErrorCategory('InvalidArgument')}, ${$this.inputObjectParameterName}) );`);
1071
- }
1072
- }
1073
- yield `await this.${$this.$('Client').invokeMethod(`${(_a = apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.name}`, ...[...allParams.map(each => codegen_csharp_1.toExpression(each.value)), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline]).implementation}`;
1074
- }
1075
- };
1076
- //when identity does contain property: 'Id'
1077
- const identityParams = function* () {
1078
- var _a, _b, _c, _d;
1079
- const path = (_c = (_b = (_a = $this.operation.callGraph) === null || _a === void 0 ? void 0 : _a[0].requests) === null || _b === void 0 ? void 0 : _b[0].protocol.http) === null || _c === void 0 ? void 0 : _c.path;
1080
- let pathParams = '';
1081
- //append path parameters which are not part of current identity
1082
- idOpParamsNotFromIdentity.forEach(each => {
1083
- var _a;
1084
- const serializedName = (_a = linq_1.values($this.properties)
1085
- .where(p => p.metadata.parameterDefinition)
1086
- .first(p => p.name === each.name)) === null || _a === void 0 ? void 0 : _a.metadata.parameterDefinition.language.csharp.serializedName;
1087
- if (each.name && serializedName) {
1088
- if (!pathParams) {
1089
- pathParams += '$"';
1090
- }
1091
- const resourceName = resourceName_1.getResourceNameFromPath(path, serializedName);
1092
- if (resourceName) {
1093
- pathParams += `/${resourceName}/{(global::System.Uri.EscapeDataString(this.${each.name}.ToString()))}`;
1094
- }
1095
- }
1162
+ // ok, let's see if the response type
1163
+ }
1164
+ // we expect to get back some data from this call.
1165
+ if ($this.hasStreamOutput && $this.outFileParameter) {
1166
+ const outfile = $this.outFileParameter;
1167
+ const provider = (0, codegen_csharp_2.Local)('provider');
1168
+ provider.initializer = undefined;
1169
+ const paths = (0, codegen_csharp_2.Local)('paths', `this.SessionState.Path.GetResolvedProviderPathFromPSPath(${outfile.value}, out ${provider.declarationExpression})`);
1170
+ yield paths.declarationStatement;
1171
+ yield (0, codegen_csharp_1.If)(`${provider.value}.Name != "FileSystem" || ${paths.value}.Count == 0`, `ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Invalid output path."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}) );`);
1172
+ yield (0, codegen_csharp_1.If)(`${paths.value}.Count > 1`, `ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Multiple output paths not allowed."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}) );`);
1173
+ if (rType.declaration === codegen_csharp_1.System.IO.Stream.declaration) {
1174
+ // this is a stream output. write to outfile
1175
+ const stream = (0, codegen_csharp_2.Local)('stream', result.value);
1176
+ yield (0, codegen_csharp_1.Using)(stream.declarationExpression, function* () {
1177
+ const fileStream = (0, codegen_csharp_2.Local)('fileStream', `global::System.IO.File.OpenWrite(${paths.value}[0])`);
1178
+ yield (0, codegen_csharp_1.Using)(fileStream.declarationExpression, `await ${stream.value}.CopyToAsync(${fileStream.value});`);
1096
1179
  });
1097
- const hasPath = pathParams && pathParams.length > 0;
1098
- //add child resource to path for list operation
1099
- if ($this.operation.variant.startsWith('List') && (idOpParamsFromIdentityserializedName === null || idOpParamsFromIdentityserializedName === void 0 ? void 0 : idOpParamsFromIdentityserializedName[idOpParamsFromIdentityserializedName.length - 1])) {
1100
- const childResourceName = resourceName_1.getChildResourceNameFromPath(path, idOpParamsFromIdentityserializedName === null || idOpParamsFromIdentityserializedName === void 0 ? void 0 : idOpParamsFromIdentityserializedName[idOpParamsFromIdentityserializedName.length - 1]);
1101
- if (pathParams && pathParams.length > 0) {
1102
- pathParams += `/${childResourceName}`;
1103
- }
1104
- else {
1105
- pathParams += `"/${childResourceName}`;
1106
- }
1107
- }
1108
- if (pathParams && pathParams.length > 0) {
1109
- pathParams += '";';
1110
- yield `this.${$this.inputObjectParameterName}.Id += ${pathParams}`;
1111
- }
1112
- yield `await this.${$this.$('Client').invokeMethod(`${(_d = apiCall.language.csharp) === null || _d === void 0 ? void 0 : _d.name}ViaIdentity`, ...parameters).implementation}`;
1113
- };
1114
- if (idschema && linq_1.values(idschema.properties).first(each => { var _a; return ((_a = each.language.csharp) === null || _a === void 0 ? void 0 : _a.uid) === 'universal-parameter:resource identity'; })) {
1115
- if (serializationMode) {
1116
- parameters.push(serializationMode);
1117
- }
1118
- yield codegen_csharp_1.If(`${$this.inputObjectParameterName}?.Id != null`, identityParams);
1119
- yield codegen_csharp_1.Else(identityFromPathParams);
1120
1180
  }
1121
1181
  else {
1122
- yield identityFromPathParams;
1123
- }
1124
- }
1125
- else {
1126
- const parameters = [...operationParameters.map(each => each.expression), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
1127
- if (serializationMode) {
1128
- parameters.push(serializationMode);
1182
+ // assuming byte array output (via result)
1183
+ yield `global::System.IO.File.WriteAllBytes(${paths.value}[0],${result.value});`;
1129
1184
  }
1130
- yield `await this.${$this.$('Client').invokeMethod(`${(_b = apiCall.language.csharp) === null || _b === void 0 ? void 0 : _b.name}`, ...parameters).implementation}`;
1185
+ yield (0, codegen_csharp_1.If)('true == MyInvocation?.BoundParameters?.ContainsKey("PassThru")', function* () {
1186
+ // no return type. Let's just return ... true?
1187
+ yield 'WriteObject(true);';
1188
+ });
1189
+ return;
1131
1190
  }
1132
- yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletAfterAPICall);
1133
- };
1134
- if ($this.state.project.azure && operationParameters.find(each => each.expression && each.expression.value === 'SubscriptionId') && $this.operation.details.csharp.verb.toLowerCase() === 'get') {
1135
- yield 'foreach( var SubscriptionId in this.SubscriptionId )';
1136
- yield codegen_csharp_1.BlockStatement(actualCall);
1191
+ // let's just return the result object (or unwrapped result object)
1192
+ yield $this.WriteObjectWithViewControl(result.value);
1193
+ return;
1137
1194
  }
1138
- else {
1139
- yield actualCall;
1195
+ // in m4, there will be no schema deinfed for the binary response, instead, we will have a field called binary with value true.
1196
+ if ('binary' in each) {
1197
+ yield '// (await response) // should be global::System.IO.Stream';
1198
+ if ($this.hasStreamOutput && $this.outFileParameter) {
1199
+ const outfile = $this.outFileParameter;
1200
+ const provider = (0, codegen_csharp_2.Local)('provider');
1201
+ provider.initializer = undefined;
1202
+ const paths = (0, codegen_csharp_2.Local)('paths', 'new global::System.Collections.ObjectModel.Collection<global::System.String>()');
1203
+ yield paths.declarationStatement;
1204
+ yield (0, codegen_csharp_1.Try)(function* () {
1205
+ yield `${paths.value} = this.SessionState.Path.GetResolvedProviderPathFromPSPath(${outfile.value}, out ${provider.declarationExpression});`;
1206
+ yield (0, codegen_csharp_1.If)(`${provider.value}.Name != "FileSystem" || ${paths.value}.Count == 0`, `ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new global::System.Exception("Invalid output path."), string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}));`);
1207
+ yield (0, codegen_csharp_1.If)(`${paths.value}.Count > 1`, `ThrowTerminatingError(new System.Management.Automation.ErrorRecord(new global::System.Exception("Multiple output paths not allowed."), string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, ${outfile.value}));`);
1208
+ });
1209
+ const notfound = new codegen_csharp_1.Parameter('', { declaration: 'global::System.Management.Automation.ItemNotFoundException' });
1210
+ yield (0, codegen_csharp_1.Catch)(notfound, function* () {
1211
+ yield '// If the file does not exist, we will try to create it';
1212
+ yield `${paths.value}.Add(${outfile.value});`;
1213
+ });
1214
+ // this is a stream output. write to outfile
1215
+ const stream = (0, codegen_csharp_2.Local)('stream', 'await response');
1216
+ yield (0, codegen_csharp_1.Using)(stream.declarationExpression, function* () {
1217
+ const fileStream = (0, codegen_csharp_2.Local)('fileStream', `global::System.IO.File.OpenWrite(${paths.value}[0])`);
1218
+ yield (0, codegen_csharp_1.Using)(fileStream.declarationExpression, `await ${stream.value}.CopyToAsync(${fileStream.value});`);
1219
+ });
1220
+ yield (0, codegen_csharp_1.If)('true == MyInvocation?.BoundParameters?.ContainsKey("PassThru")', function* () {
1221
+ // no return type. Let's just return ... true?
1222
+ yield 'WriteObject(true);';
1223
+ });
1224
+ return;
1225
+ }
1140
1226
  }
1227
+ yield (0, codegen_csharp_1.If)('true == MyInvocation?.BoundParameters?.ContainsKey("PassThru")', function* () {
1228
+ // no return type. Let's just return ... true?
1229
+ yield 'WriteObject(true);';
1230
+ });
1141
1231
  });
1142
- const ure = new codegen_csharp_1.Parameter('urexception', { declaration: `${exports_1.ClientRuntime.fullName}.UndeclaredResponseException` });
1143
- yield codegen_csharp_1.Catch(ure, function* () {
1144
- yield `WriteError(new global::System.Management.Automation.ErrorRecord(${ure.value}, ${ure.value}.StatusCode.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ${operationParameters.filter(e => codegen_csharp_1.valueOf(e.expression) !== 'null').map(each => `${each.name}=${each.expression}`).join(',')}})
1145
- {
1146
- ErrorDetails = new global::System.Management.Automation.ErrorDetails(${ure.value}.Message) { RecommendedAction = ${ure.value}.Action }
1147
- });`;
1148
- });
1149
- yield codegen_csharp_1.Finally(function* () {
1150
- yield $this.eventListener.signalNoCheck(powershell_declarations_1.Events.CmdletProcessRecordAsyncEnd);
1151
- });
1152
- });
1232
+ $this.add(responseMethod);
1233
+ }
1153
1234
  }
1154
1235
  NewImplementSerialization(operation) {
1155
1236
  const $this = this;
@@ -1179,7 +1260,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1179
1260
  //_parametersBody = this._parametersBody,
1180
1261
  //_resourceGroupName = this._resourceGroupName,
1181
1262
  //_subscriptionId = this._subscriptionId,
1182
- yield codegen_csharp_1.Return(i);
1263
+ yield (0, codegen_csharp_1.Return)(i);
1183
1264
  });
1184
1265
  }
1185
1266
  }
@@ -1194,7 +1275,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1194
1275
  description: 'A dictionary to carry over additional data for pipeline.'
1195
1276
  }));
1196
1277
  const extensibleParametersProp = new codegen_csharp_1.Property('ExtensibleParameters', codegen_csharp_1.System.Collections.Generic.IDictionary(codegen_csharp_1.System.String, codegen_csharp_1.System.Object), { description: 'Accessor for extensibleParameters.' });
1197
- extensibleParametersProp.get = codegen_csharp_1.toExpression(`${extensibleParameters.value} `);
1278
+ extensibleParametersProp.get = (0, codegen_csharp_1.toExpression)(`${extensibleParameters.value} `);
1198
1279
  this.add(extensibleParametersProp);
1199
1280
  }
1200
1281
  implementIEventListener() {
@@ -1205,11 +1286,11 @@ class CmdletClass extends codegen_csharp_1.Class {
1205
1286
  description: `The <see cref="${codegen_csharp_1.System.Threading.CancellationTokenSource}" /> for this operation.`
1206
1287
  }));
1207
1288
  const cancellationTokenSource = new codegen_csharp_1.Property('CancellationTokenSource', codegen_csharp_1.System.Threading.CancellationTokenSource, { description: 'Accessor for cancellationTokenSource.' });
1208
- cancellationTokenSource.get = codegen_csharp_1.toExpression(`${cts.value} `);
1289
+ cancellationTokenSource.get = (0, codegen_csharp_1.toExpression)(`${cts.value} `);
1209
1290
  cancellationTokenSource.set = new codegen_csharp_1.Statements(cts.assign('value'));
1210
1291
  this.add(cancellationTokenSource);
1211
1292
  this.add(new codegen_csharp_1.LambdaProperty(`${exports_1.ClientRuntime.IEventListener}.Token`, codegen_csharp_1.System.Threading.CancellationToken, new codegen_csharp_1.LiteralExpression(`${cts.value}.Token`), { getAccess: codegen_csharp_1.Access.Default, setAccess: codegen_csharp_1.Access.Default, description: `<see cref="${exports_1.ClientRuntime}.IEventListener" /> cancellation token.` }));
1212
- this.cancellationToken = codegen_csharp_1.toExpression(`((${exports_1.ClientRuntime.IEventListener})this).Token`);
1293
+ this.cancellationToken = (0, codegen_csharp_1.toExpression)(`((${exports_1.ClientRuntime.IEventListener})this).Token`);
1213
1294
  this.add(new codegen_csharp_1.LambdaProperty(`${exports_1.ClientRuntime.IEventListener}.Cancel`, codegen_csharp_1.System.Action(), new codegen_csharp_1.LiteralExpression(`${cts.value}.Cancel`), { getAccess: codegen_csharp_1.Access.Default, setAccess: codegen_csharp_1.Access.Default, description: `<see cref="${exports_1.ClientRuntime}.IEventListener" /> cancellation delegate. Stops the cmdlet when called.` }));
1214
1295
  const id = new codegen_csharp_1.Parameter('id', codegen_csharp_1.dotnet.String, { description: 'The message id' });
1215
1296
  const token = new codegen_csharp_1.Parameter('token', codegen_csharp_1.System.Threading.CancellationToken, { description: 'The message cancellation token. When this call is cancelled, this should be <c>true</c>' });
@@ -1221,20 +1302,20 @@ class CmdletClass extends codegen_csharp_1.Class {
1221
1302
  description: 'Handles/Dispatches events during the call to the REST service.',
1222
1303
  returnsDescription: `A <see cref="${codegen_csharp_1.System.Threading.Tasks.Task()}" /> that will be complete when handling of the message is completed.`
1223
1304
  }));
1224
- signalMethod.push(codegen_csharp_1.Using('NoSynchronizationContext', ''));
1305
+ signalMethod.push((0, codegen_csharp_1.Using)('NoSynchronizationContext', ''));
1225
1306
  signalMethod.add(function* () {
1226
- yield codegen_csharp_1.If(`${token.value}.IsCancellationRequested`, codegen_csharp_1.Return());
1307
+ yield (0, codegen_csharp_1.If)(`${token.value}.IsCancellationRequested`, (0, codegen_csharp_1.Return)());
1227
1308
  // if the
1228
- const sw = codegen_csharp_1.Switch(id, [
1229
- codegen_csharp_1.TerminalCase(powershell_declarations_1.Events.Verbose.value, function* () {
1309
+ const sw = (0, codegen_csharp_1.Switch)(id, [
1310
+ (0, codegen_csharp_1.TerminalCase)(powershell_declarations_1.Events.Verbose.value, function* () {
1230
1311
  yield `WriteVerbose($"{(messageData().Message ?? ${codegen_csharp_1.System.String.Empty})}");`;
1231
- yield codegen_csharp_1.Return();
1312
+ yield (0, codegen_csharp_1.Return)();
1232
1313
  }),
1233
- codegen_csharp_1.TerminalCase(powershell_declarations_1.Events.Warning.value, function* () {
1314
+ (0, codegen_csharp_1.TerminalCase)(powershell_declarations_1.Events.Warning.value, function* () {
1234
1315
  yield `WriteWarning($"{(messageData().Message ?? ${codegen_csharp_1.System.String.Empty})}");`;
1235
- yield codegen_csharp_1.Return();
1316
+ yield (0, codegen_csharp_1.Return)();
1236
1317
  }),
1237
- codegen_csharp_1.TerminalCase(powershell_declarations_1.Events.Information.value, function* () {
1318
+ (0, codegen_csharp_1.TerminalCase)(powershell_declarations_1.Events.Information.value, function* () {
1238
1319
  if ($this.operation.asjob) {
1239
1320
  yield '// When an operation supports asjob, Information messages must go thru verbose.';
1240
1321
  yield `WriteVerbose($"INFORMATION: {(messageData().Message ?? ${codegen_csharp_1.System.String.Empty})}");`;
@@ -1244,17 +1325,17 @@ class CmdletClass extends codegen_csharp_1.Class {
1244
1325
  yield data.declarationStatement;
1245
1326
  yield 'WriteInformation(data.Message, new string[]{});';
1246
1327
  }
1247
- yield codegen_csharp_1.Return();
1328
+ yield (0, codegen_csharp_1.Return)();
1248
1329
  }),
1249
- codegen_csharp_1.TerminalCase(powershell_declarations_1.Events.Debug.value, function* () {
1330
+ (0, codegen_csharp_1.TerminalCase)(powershell_declarations_1.Events.Debug.value, function* () {
1250
1331
  yield `WriteDebug($"{(messageData().Message ?? ${codegen_csharp_1.System.String.Empty})}");`;
1251
- yield codegen_csharp_1.Return();
1332
+ yield (0, codegen_csharp_1.Return)();
1252
1333
  }),
1253
- codegen_csharp_1.TerminalCase(powershell_declarations_1.Events.Error.value, function* () {
1334
+ (0, codegen_csharp_1.TerminalCase)(powershell_declarations_1.Events.Error.value, function* () {
1254
1335
  yield 'WriteError(new global::System.Management.Automation.ErrorRecord( new global::System.Exception(messageData().Message), string.Empty, global::System.Management.Automation.ErrorCategory.NotSpecified, null ) );';
1255
- yield codegen_csharp_1.Return();
1336
+ yield (0, codegen_csharp_1.Return)();
1256
1337
  }),
1257
- codegen_csharp_1.TerminalCase(powershell_declarations_1.Events.Progress.value, function* () {
1338
+ (0, codegen_csharp_1.TerminalCase)(powershell_declarations_1.Events.Progress.value, function* () {
1258
1339
  yield 'var data = messageData();';
1259
1340
  yield 'int progress = (int)data.Value;';
1260
1341
  yield 'string activityMessage, statusDescription;';
@@ -1277,14 +1358,14 @@ class CmdletClass extends codegen_csharp_1.Class {
1277
1358
  yield ' PercentComplete = progress,';
1278
1359
  yield 'RecordType = recordType';
1279
1360
  yield '});';
1280
- yield codegen_csharp_1.Return();
1361
+ yield (0, codegen_csharp_1.Return)();
1281
1362
  }),
1282
1363
  ]);
1283
1364
  if ($this.operation.asjob) {
1284
1365
  // if we support -AsJob, we support -NoWait
1285
- sw.add(codegen_csharp_1.Case(powershell_declarations_1.Events.DelayBeforePolling.value, function* () {
1366
+ sw.add((0, codegen_csharp_1.Case)(powershell_declarations_1.Events.DelayBeforePolling.value, function* () {
1286
1367
  yield 'var data = messageData();';
1287
- yield codegen_csharp_1.If('true == MyInvocation?.BoundParameters?.ContainsKey("NoWait")', function* () {
1368
+ yield (0, codegen_csharp_1.If)('true == MyInvocation?.BoundParameters?.ContainsKey("NoWait")', function* () {
1288
1369
  yield 'if (data.ResponseMessage is System.Net.Http.HttpResponseMessage response)';
1289
1370
  yield '{';
1290
1371
  yield ' var asyncOperation = response.GetFirstHeader(@"Azure-AsyncOperation");';
@@ -1296,7 +1377,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1296
1377
  yield ' return;';
1297
1378
  yield '}';
1298
1379
  });
1299
- yield codegen_csharp_1.Else(function* () {
1380
+ yield (0, codegen_csharp_1.Else)(function* () {
1300
1381
  yield 'if (data.ResponseMessage is System.Net.Http.HttpResponseMessage response)';
1301
1382
  yield '{';
1302
1383
  yield ' int delay = (int)(response.Headers.RetryAfter?.Delta?.TotalSeconds ?? 30);';
@@ -1319,12 +1400,12 @@ class CmdletClass extends codegen_csharp_1.Class {
1319
1400
  if ($this.state.project.azure) {
1320
1401
  // in azure mode, we signal the AzAccount module with every event that makes it here.
1321
1402
  yield `await ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.Signal(${id.value}, ${token.value}, ${messageData.value}, (i, t, m) => ((${exports_1.ClientRuntime.IEventListener})this).Signal(i, t, () => ${exports_1.ClientRuntime.EventDataConverter}.ConvertFrom(m()) as ${exports_1.ClientRuntime.EventData}), ${$this.invocationInfo.value}, this.ParameterSetName, ${$this.correlationId.value}, ${$this.processRecordId.value}, null );`;
1322
- yield codegen_csharp_1.If(`${token.value}.IsCancellationRequested`, codegen_csharp_1.Return());
1403
+ yield (0, codegen_csharp_1.If)(`${token.value}.IsCancellationRequested`, (0, codegen_csharp_1.Return)());
1323
1404
  }
1324
1405
  else {
1325
1406
  // In Non-Azure Modes, emit the Signal method without coorelation and processrecordid
1326
1407
  yield `await ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.Signal(${id.value}, ${token.value}, ${messageData.value}, (i, t, m) => ((${exports_1.ClientRuntime.IEventListener})this).Signal(i, t, () => ${exports_1.ClientRuntime.EventDataConverter}.ConvertFrom(m()) as ${exports_1.ClientRuntime.EventData}), ${$this.invocationInfo.value}, this.ParameterSetName, null ); `;
1327
- yield codegen_csharp_1.If(`${token.value}.IsCancellationRequested`, codegen_csharp_1.Return());
1408
+ yield (0, codegen_csharp_1.If)(`${token.value}.IsCancellationRequested`, (0, codegen_csharp_1.Return)());
1328
1409
  }
1329
1410
  yield `WriteDebug($"{id}: {(messageData().Message ?? ${codegen_csharp_1.System.String.Empty})}");`;
1330
1411
  // any handling of the signal on our side...
@@ -1336,7 +1417,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1336
1417
  body: [],
1337
1418
  operation: [],
1338
1419
  };
1339
- for (const parameter of linq_1.values(operation.parameters)) {
1420
+ for (const parameter of (0, linq_1.values)(operation.parameters)) {
1340
1421
  // these are the parameters that this command expects
1341
1422
  parameter.schema;
1342
1423
  const td = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(parameter.schema, true, this.state);
@@ -1370,11 +1451,11 @@ class CmdletClass extends codegen_csharp_1.Class {
1370
1451
  *get() {
1371
1452
  const metadata = operation.extensions['x-ms-metadata'];
1372
1453
  const profiles = metadata.profiles || new linq_1.Dictionary();
1373
- yield codegen_csharp_1.Switch(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.Profile`, function* () {
1374
- for (const { key: profileName, value: apiVersion } of linq_1.items(profiles)) {
1375
- yield codegen_csharp_1.TerminalCase(`"${profileName}"`, codegen_csharp_1.Return(`"${apiVersion}"`));
1454
+ yield (0, codegen_csharp_1.Switch)(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.Profile`, function* () {
1455
+ for (const { key: profileName, value: apiVersion } of (0, linq_1.items)(profiles)) {
1456
+ yield (0, codegen_csharp_1.TerminalCase)(`"${profileName}"`, (0, codegen_csharp_1.Return)(`"${apiVersion}"`));
1376
1457
  }
1377
- yield codegen_csharp_1.TerminalDefaultCase(codegen_csharp_1.Return(`"${metadata.apiVersions[0]}"`));
1458
+ yield (0, codegen_csharp_1.TerminalDefaultCase)((0, codegen_csharp_1.Return)(`"${metadata.apiVersions[0]}"`));
1378
1459
  });
1379
1460
  }
1380
1461
  }));
@@ -1382,7 +1463,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1382
1463
  }
1383
1464
  if (this.dropBodyParameter && parameter.details.csharp.isBodyParameter) {
1384
1465
  // we're supposed to use parameters for the body parameter instead of a big object
1385
- const expandedBodyParameter = this.add(new codegen_csharp_1.Field('_' + codegen_1.camelCase(parameter.details.csharp.name), td, {
1466
+ const expandedBodyParameter = this.add(new codegen_csharp_1.Field('_' + (0, codegen_1.camelCase)(parameter.details.csharp.name), td, {
1386
1467
  description: parameter.details.csharp.description,
1387
1468
  initialValue: (parameter.schema.type === codemodel_1.SchemaType.Array) ? codegen_csharp_1.dotnet.Null : `new ${(_a = parameter.schema.language.csharp) === null || _a === void 0 ? void 0 : _a.fullname}()`,
1388
1469
  access: codegen_csharp_1.Access.Private
@@ -1397,17 +1478,17 @@ class CmdletClass extends codegen_csharp_1.Class {
1397
1478
  let cmdletParameter;
1398
1479
  if (propertyType.schema.type !== codemodel_1.SchemaType.Array) {
1399
1480
  cmdletParameter = new codegen_csharp_1.Property(vParam.name, propertyType, {
1400
- get: codegen_csharp_1.toExpression(`${expandedBodyParameter.value}.${model_class_1.getVirtualPropertyName(vParam.origin) || vParam.origin.name}${!nullable ? '' : ` ?? ${propertyType.defaultOfType}`}`),
1481
+ get: (0, codegen_csharp_1.toExpression)(`${expandedBodyParameter.value}.${(0, model_class_1.getVirtualPropertyName)(vParam.origin) || vParam.origin.name}${!nullable ? '' : ` ?? ${propertyType.defaultOfType}`}`),
1401
1482
  // get: toExpression(`null == ${expandedBodyParameter.value}.${vParam.origin.name} ? ${propertyType.defaultOfType} : (${propertyType.declaration}) ${expandedBodyParameter.value}.${vParam.origin.name}`),
1402
- set: codegen_csharp_1.toExpression(`${expandedBodyParameter.value}.${model_class_1.getVirtualPropertyName(vParam.origin) || vParam.origin.name} = value`),
1483
+ set: (0, codegen_csharp_1.toExpression)(`${expandedBodyParameter.value}.${(0, model_class_1.getVirtualPropertyName)(vParam.origin) || vParam.origin.name} = value`),
1403
1484
  new: PropertiesRequiringNew.has(vParam.name) ? codegen_csharp_1.Modifier.New : codegen_csharp_1.Modifier.None
1404
1485
  });
1405
1486
  }
1406
1487
  else {
1407
1488
  const fixedArrayPropertyType = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(vSchema, true, this.state, true);
1408
1489
  cmdletParameter = new codegen_csharp_1.Property(vParam.name, fixedArrayPropertyType, {
1409
- get: codegen_csharp_1.toExpression(`${expandedBodyParameter.value}.${model_class_1.getVirtualPropertyName(vParam.origin) || vParam.origin.name}?.ToArray()${` ?? ${fixedArrayPropertyType.defaultOfType}`}`),
1410
- set: codegen_csharp_1.toExpression(`${expandedBodyParameter.value}.${model_class_1.getVirtualPropertyName(vParam.origin) || vParam.origin.name} = (value != null ? new ${propertyType.declaration}(value) : null)`),
1490
+ get: (0, codegen_csharp_1.toExpression)(`${expandedBodyParameter.value}.${(0, model_class_1.getVirtualPropertyName)(vParam.origin) || vParam.origin.name}?.ToArray()${` ?? ${fixedArrayPropertyType.defaultOfType}`}`),
1491
+ set: (0, codegen_csharp_1.toExpression)(`${expandedBodyParameter.value}.${(0, model_class_1.getVirtualPropertyName)(vParam.origin) || vParam.origin.name} = (value != null ? new ${propertyType.declaration}(value) : null)`),
1411
1492
  new: PropertiesRequiringNew.has(vParam.name) ? codegen_csharp_1.Modifier.New : codegen_csharp_1.Modifier.None
1412
1493
  });
1413
1494
  }
@@ -1430,7 +1511,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1430
1511
  // we have to figure out if this is a standalone dictionary or a hybrid object/dictionary.
1431
1512
  // if it's a hybrid, we have to create another parameter like -<XXX>AdditionalProperties and have that dump the contents into the dictionary
1432
1513
  // if it's a standalone dictionary, we can just use hashtable instead
1433
- if (linq_1.length(vSchema.properties) === 0) {
1514
+ if ((0, linq_1.length)(vSchema.properties) === 0) {
1434
1515
  // it's a pure dictionary
1435
1516
  // add an attribute for changing the exported type.
1436
1517
  cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ExportAsAttribute, { parameters: [`typeof(${codegen_csharp_1.System.Collections.Hashtable})`] }));
@@ -1447,29 +1528,29 @@ class CmdletClass extends codegen_csharp_1.Class {
1447
1528
  cmdletParameter.setAccess = codegen_csharp_1.Access.Internal;
1448
1529
  cmdletParameter.getAccess = codegen_csharp_1.Access.Internal;
1449
1530
  // create a InputFileXXX for the parameter
1450
- const ifname = vParam.name.toLowerCase() === 'value' ? 'InputFile' : codegen_1.pascalCase([vParam.name, 'Input', 'File']);
1531
+ const ifname = vParam.name.toLowerCase() === 'value' ? 'InputFile' : (0, codegen_1.pascalCase)([vParam.name, 'Input', 'File']);
1451
1532
  const inputFileParameter = new codegen_csharp_1.Property(ifname, codegen_csharp_1.dotnet.String, {
1452
1533
  // get: toExpression(`${expandedBodyParameter.value}.${vParam.origin.name}${vParam.required ? '' : ` ?? ${propertyType.defaultOfType}`}`),
1453
1534
  set: function* () {
1454
- const provider = codegen_csharp_2.Local('provider');
1535
+ const provider = (0, codegen_csharp_2.Local)('provider');
1455
1536
  provider.initializer = undefined;
1456
- const paths = codegen_csharp_2.Local('paths', `this.SessionState.Path.GetResolvedProviderPathFromPSPath(value, out ${provider.declarationExpression})`);
1537
+ const paths = (0, codegen_csharp_2.Local)('paths', `this.SessionState.Path.GetResolvedProviderPathFromPSPath(value, out ${provider.declarationExpression})`);
1457
1538
  yield paths.declarationStatement;
1458
- yield codegen_csharp_1.If(`${provider.value}.Name != "FileSystem" || ${paths.value}.Count == 0`, 'ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Invalid input path."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, value) );');
1459
- yield codegen_csharp_1.If(`${paths.value}.Count > 1`, 'ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Multiple input paths not allowed."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, value) );');
1539
+ yield (0, codegen_csharp_1.If)(`${provider.value}.Name != "FileSystem" || ${paths.value}.Count == 0`, 'ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Invalid input path."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, value) );');
1540
+ yield (0, codegen_csharp_1.If)(`${paths.value}.Count > 1`, 'ThrowTerminatingError( new System.Management.Automation.ErrorRecord(new global::System.Exception("Multiple input paths not allowed."),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, value) );');
1460
1541
  yield cmdletParameter.assign(`global::System.IO.File.ReadAllBytes(${paths.value}[0])`);
1461
1542
  },
1462
- description: `Input File for ${cmdletParameter.name} (${codegen_1.escapeString(desc)})`
1543
+ description: `Input File for ${cmdletParameter.name} (${(0, codegen_1.escapeString)(desc)})`
1463
1544
  });
1464
- inputFileParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "Input File for ${cmdletParameter.name} (${codegen_1.escapeString(desc || '.')})"`)] }));
1545
+ inputFileParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "Input File for ${cmdletParameter.name} (${(0, codegen_1.escapeString)(desc || '.')})"`)] }));
1465
1546
  inputFileParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.Body`] }));
1466
- if (linq_1.length(vParam.alias) > 0) {
1547
+ if ((0, linq_1.length)(vParam.alias) > 0) {
1467
1548
  inputFileParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.Alias, { parameters: vParam.alias.map(x => '"' + x + '"') }));
1468
1549
  }
1469
1550
  $this.add(inputFileParameter);
1470
1551
  }
1471
1552
  else {
1472
- cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "${codegen_1.escapeString(desc || '.')}"`)] }));
1553
+ cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters: [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "${(0, codegen_1.escapeString)(desc || '.')}"`)] }));
1473
1554
  cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.Body`] }));
1474
1555
  NewAddInfoAttribute(cmdletParameter, propertyType, !!vParam.required, false, desc, vParam.origin.property.serializedName);
1475
1556
  NewAddCompleterInfo(cmdletParameter, vParam);
@@ -1483,7 +1564,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1483
1564
  addPSArgumentCompleterAttribute(cmdletParameter, vParam.schema);
1484
1565
  }
1485
1566
  // add aliases if there is any
1486
- if (linq_1.length(vParam.alias) > 0) {
1567
+ if ((0, linq_1.length)(vParam.alias) > 0) {
1487
1568
  cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.Alias, { parameters: vParam.alias.map(x => '"' + x + '"') }));
1488
1569
  }
1489
1570
  this.add(cmdletParameter);
@@ -1523,7 +1604,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1523
1604
  const viaIdentityRegex = /ViaIdentity\d?/g;
1524
1605
  this.inputObjectParameterName = `${this.name.split(viaIdentityRegex)[1].split('Expanded')[0]}InputObject`;
1525
1606
  // add in the pipeline parameter for the identity
1526
- const idschema = linq_1.values(this.state.project.model.schemas.objects).first(each => each.language.default.uid === 'universal-parameter-type');
1607
+ const idschema = (0, linq_1.values)(this.state.project.model.schemas.objects).first(each => each.language.default.uid === 'universal-parameter-type');
1527
1608
  const idtd = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(idschema, true, this.state);
1528
1609
  const idParam = this.add(new codegen_csharp_1.BackedProperty(this.inputObjectParameterName, idtd, {
1529
1610
  description: 'Identity Parameter'
@@ -1532,7 +1613,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1532
1613
  idParam.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters }));
1533
1614
  idParam.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.Path`] }));
1534
1615
  }
1535
- for (const vParam of linq_1.values(vps.operation)) {
1616
+ for (const vParam of (0, linq_1.values)(vps.operation)) {
1536
1617
  if (vParam.name === 'Host') {
1537
1618
  // skip 'Host'
1538
1619
  continue;
@@ -1572,7 +1653,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1572
1653
  // we have to figure out if this is a standalone dictionary or a hybrid object/dictionary.
1573
1654
  // if it's a hybrid, we have to create another parameter like -<XXX>AdditionalProperties and have that dump the contents into the dictionary
1574
1655
  // if it's a standalone dictionary, we can just use hashtable instead
1575
- if (linq_1.length(vSchema.properties) === 0) {
1656
+ if ((0, linq_1.length)(vSchema.properties) === 0) {
1576
1657
  // it's a pure dictionary
1577
1658
  // change the property type to hashtable.
1578
1659
  // add an attribute to change the exported type.
@@ -1584,7 +1665,7 @@ class CmdletClass extends codegen_csharp_1.Class {
1584
1665
  }
1585
1666
  }
1586
1667
  this.thingsToSerialize.push(regularCmdletParameter);
1587
- const parameters = [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "${codegen_1.escapeString(vParam.description) || '.'}"`)];
1668
+ const parameters = [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "${(0, codegen_1.escapeString)(vParam.description) || '.'}"`)];
1588
1669
  if (!!origin && origin.details.csharp.isBodyParameter) {
1589
1670
  parameters.push(new codegen_csharp_1.LiteralExpression('ValueFromPipeline = true'));
1590
1671
  this.bodyParameter = regularCmdletParameter;
@@ -1602,16 +1683,16 @@ class CmdletClass extends codegen_csharp_1.Class {
1602
1683
  addDefaultInfo(regularCmdletParameter, vParam);
1603
1684
  this.addDoNotExport(regularCmdletParameter, vParam);
1604
1685
  // add aliases if there is any
1605
- if (linq_1.length(vParam.alias) > 0) {
1686
+ if ((0, linq_1.length)(vParam.alias) > 0) {
1606
1687
  regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.Alias, { parameters: vParam.alias.map(x => '"' + x + '"') }));
1607
1688
  }
1608
1689
  const httpParam = origin ? origin.details.csharp.httpParameter : null;
1609
1690
  //const uid = httpParam ? httpParam.details.csharp.uid : 'no-parameter';
1610
1691
  if (httpParam) {
1611
1692
  // xichen: Is it safe to compare by csharp serializedName? Because we no longer have uid
1612
- const cat = (_l = operation.callGraph[0].parameters) === null || _l === void 0 ? void 0 : _l.find((param) => { var _a, _b, _c; return !((_a = param.language.csharp) === null || _a === void 0 ? void 0 : _a.constantValue) && ((_b = param.language.csharp) === null || _b === void 0 ? void 0 : _b.serializedName) === ((_c = httpParam.language.csharp) === null || _c === void 0 ? void 0 : _c.serializedName); });
1693
+ const cat = (_l = this.apiCall.parameters) === null || _l === void 0 ? void 0 : _l.find((param) => { var _a, _b, _c; return !((_a = param.language.csharp) === null || _a === void 0 ? void 0 : _a.constantValue) && ((_b = param.language.csharp) === null || _b === void 0 ? void 0 : _b.serializedName) === ((_c = httpParam.language.csharp) === null || _c === void 0 ? void 0 : _c.serializedName); });
1613
1694
  if (cat) {
1614
- regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.${codegen_1.pascalCase(((_m = cat.protocol.http) === null || _m === void 0 ? void 0 : _m.in))}`] }));
1695
+ regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CategoryAttribute, { parameters: [`${powershell_declarations_1.ParameterCategory}.${(0, codegen_1.pascalCase)(((_m = cat.protocol.http) === null || _m === void 0 ? void 0 : _m.in))}`] }));
1615
1696
  }
1616
1697
  }
1617
1698
  else {
@@ -1641,19 +1722,19 @@ class CmdletClass extends codegen_csharp_1.Class {
1641
1722
  addDoNotExport(cmdletParameter, vParam) {
1642
1723
  if (vParam.hidden) {
1643
1724
  this.state.message({
1644
- Channel: autorest_extension_base_1.Channel.Debug,
1725
+ Channel: extension_base_1.Channel.Debug,
1645
1726
  Text: `[DIRECTIVE] Applied 'hide' directive to parameter ${cmdletParameter.name}. Added attribute ${powershell_declarations_1.DoNotExportAttribute.declaration} to parameter.`,
1646
1727
  });
1647
1728
  cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.DoNotExportAttribute));
1648
1729
  }
1649
1730
  }
1650
1731
  NewAddClassAttributes(operation, variantName) {
1651
- var _a, _b, _c, _d, _e, _f, _g, _h;
1732
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1652
1733
  const cmdletAttribParams = [
1653
- category[operation.details.csharp.verb] ? powershell_declarations_1.verbEnum(category[operation.details.csharp.verb], operation.details.csharp.verb) : `"${operation.details.csharp.verb}"`,
1734
+ category[operation.details.csharp.verb] ? (0, powershell_declarations_1.verbEnum)(category[operation.details.csharp.verb], operation.details.csharp.verb) : `"${operation.details.csharp.verb}"`,
1654
1735
  new codegen_csharp_1.StringExpression(variantName)
1655
1736
  ];
1656
- if (this.NewIsWritableCmdlet(operation)) {
1737
+ if ((0, command_operation_1.isWritableCmdlet)(operation) && !operation.details.csharp.supportShouldProcess) {
1657
1738
  cmdletAttribParams.push('SupportsShouldProcess = true');
1658
1739
  }
1659
1740
  if (this.clientsidePagination) {
@@ -1663,21 +1744,21 @@ class CmdletClass extends codegen_csharp_1.Class {
1663
1744
  this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.InternalExportAttribute));
1664
1745
  const noun = `${operation.details.csharp.subjectPrefix}${operation.details.csharp.subject}`;
1665
1746
  const cmdletName = `${operation.details.csharp.verb}-${noun}${operation.details.csharp.name ? `_${operation.details.csharp.name}` : ''}`;
1666
- this.state.message({ Channel: autorest_extension_base_1.Channel.Debug, Text: `[DIRECTIVE] Applied 'hide' directive to ${cmdletName}. Added attribute ${powershell_declarations_1.InternalExportAttribute.declaration} to cmdlet.` });
1747
+ this.state.message({ Channel: extension_base_1.Channel.Debug, Text: `[DIRECTIVE] Applied 'hide' directive to ${cmdletName}. Added attribute ${powershell_declarations_1.InternalExportAttribute.declaration} to cmdlet.` });
1667
1748
  }
1668
1749
  this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.CmdletAttribute, { parameters: cmdletAttribParams }));
1669
1750
  // add alias attribute if there is any aliases for this cmdlet
1670
- if (linq_1.length(operation.details.csharp.alias) > 0) {
1751
+ if ((0, linq_1.length)(operation.details.csharp.alias) > 0) {
1671
1752
  this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.Alias, { parameters: operation.details.csharp.alias.map((x) => '"' + x + '"') }));
1672
1753
  }
1673
1754
  let shouldAddPassThru = false;
1674
1755
  // set to hold the output types
1675
1756
  const outputTypes = new Set();
1676
- for (const httpOperation of linq_1.values(operation.callGraph)) {
1757
+ for (const httpOperation of (0, linq_1.values)(operation.callGraph)) {
1677
1758
  const pageableInfo = (_a = httpOperation.language.csharp) === null || _a === void 0 ? void 0 : _a.pageable;
1678
1759
  const v = httpOperation.responses && httpOperation.responses.length > 0 && httpOperation.responses[0] instanceof codemodel_1.SchemaResponse;
1679
1760
  // Add this for binary response in m4
1680
- for (const binary of linq_1.values(httpOperation.responses).selectNonNullable(each => each.binary)) {
1761
+ for (const binary of (0, linq_1.values)(httpOperation.responses).selectNonNullable(each => each.binary)) {
1681
1762
  if (binary) {
1682
1763
  // if this is a stream, skip the output type.
1683
1764
  this.hasStreamOutput = true;
@@ -1685,10 +1766,10 @@ class CmdletClass extends codegen_csharp_1.Class {
1685
1766
  outputTypes.add(`typeof(${codegen_csharp_1.dotnet.Bool})`);
1686
1767
  }
1687
1768
  }
1688
- for (const schema of linq_1.values(httpOperation.responses).selectNonNullable(each => each.schema)) {
1689
- const props = schema_1.getAllProperties(schema);
1769
+ for (const schema of (0, linq_1.values)(httpOperation.responses).selectNonNullable(each => each.schema)) {
1770
+ const props = (0, schema_1.getAllProperties)(schema);
1690
1771
  // does the target type just wrap a single output?
1691
- const resultSchema = linq_1.length(props) !== 1 ? schema : props[0].schema;
1772
+ const resultSchema = schema;
1692
1773
  // make sure return type for boolean stays boolean!
1693
1774
  if (resultSchema.type === codemodel_1.SchemaType.Boolean ||
1694
1775
  (resultSchema.type === codemodel_1.SchemaType.Choice && resultSchema.choiceType.type === codemodel_1.SchemaType.Boolean && resultSchema.choices.length === 1) ||
@@ -1731,8 +1812,8 @@ class CmdletClass extends codegen_csharp_1.Class {
1731
1812
  }
1732
1813
  // if any response does not return,
1733
1814
  // the cmdlet should have a PassThru parameter
1734
- shouldAddPassThru = shouldAddPassThru || linq_1.values(operation.callGraph)
1735
- .selectMany(httpOperation => linq_1.values((httpOperation.responses || []).concat(httpOperation.exceptions || [])))
1815
+ shouldAddPassThru = shouldAddPassThru || (0, linq_1.values)(operation.callGraph)
1816
+ .selectMany(httpOperation => (0, linq_1.values)((httpOperation.responses || []).concat(httpOperation.exceptions || [])))
1736
1817
  //.selectMany(responsesItem => responsesItem.value)
1737
1818
  .any(value => value.schema === undefined);
1738
1819
  if (outputTypes.size === 0) {
@@ -1743,11 +1824,13 @@ class CmdletClass extends codegen_csharp_1.Class {
1743
1824
  const breakingChange = operation.details.csharp.breakingChange;
1744
1825
  if (breakingChange.cmdlet) {
1745
1826
  const parameters = [];
1746
- if (breakingChange.cmdlet.deprecateByVersion) {
1747
- parameters.push(`"${breakingChange.cmdlet.deprecateByVersion}"`);
1748
- if (breakingChange.cmdlet.changeInEfectByDate)
1749
- parameters.push(`"${breakingChange.cmdlet.changeInEfectByDate}"`);
1827
+ if (!breakingChange.cmdlet.deprecateByVersion || !breakingChange.cmdlet.deprecateByAzVersion) {
1828
+ throw new Error('Cmdlet breaking change requires both \'deprecateByVersion\' and \'deprecateByAzVersion\', please refer to https://github.com/Azure/azure-powershell/blob/main/documentation/development-docs/breakingchange-for-autogen-module.md for more details.');
1750
1829
  }
1830
+ parameters.push(`"${breakingChange.cmdlet.deprecateByVersion}"`);
1831
+ parameters.push(`"${breakingChange.cmdlet.deprecateByAzVersion}"`);
1832
+ if (breakingChange.cmdlet.changeInEfectByDate)
1833
+ parameters.push(`"${breakingChange.cmdlet.changeInEfectByDate}"`);
1751
1834
  if (breakingChange.cmdlet.replacement)
1752
1835
  parameters.push(`ReplacementCmdletName = "${breakingChange.cmdlet.replacement}"`);
1753
1836
  if (breakingChange.cmdlet.changeDescription)
@@ -1757,11 +1840,13 @@ class CmdletClass extends codegen_csharp_1.Class {
1757
1840
  if (breakingChange.variant) {
1758
1841
  const parameters = [];
1759
1842
  parameters.push(`new string[] {"${breakingChange.variant.name}"}`);
1760
- if (breakingChange.variant.deprecateByVersion) {
1761
- parameters.push(`"${breakingChange.variant.deprecateByVersion}"`);
1762
- if (breakingChange.variant.changeInEfectByDate)
1763
- parameters.push(`"${breakingChange.variant.changeInEfectByDate}"`);
1843
+ if (!breakingChange.output.deprecateByVersion || !breakingChange.output.deprecateByAzVersion) {
1844
+ throw new Error('Cmdlet breaking change requires both \'deprecateByVersion\' and \'deprecateByAzVersion\', please refer to https://github.com/Azure/azure-powershell/blob/main/documentation/development-docs/breakingchange-for-autogen-module.md for more details.');
1764
1845
  }
1846
+ parameters.push(`"${breakingChange.output.deprecateByVersion}"`);
1847
+ parameters.push(`"${breakingChange.output.deprecateByAzVersion}"`);
1848
+ if (breakingChange.output.changeInEfectByDate)
1849
+ parameters.push(`"${breakingChange.output.changeInEfectByDate}"`);
1765
1850
  if (breakingChange.variant.changeDescription)
1766
1851
  parameters.push(`ChangeDescription = "${breakingChange.variant.changeDescription}"`);
1767
1852
  this.add(new codegen_csharp_1.Attribute(exports_1.ClientRuntime.ParameterSetBreakingChangeAttribute, { parameters: parameters }));
@@ -1775,11 +1860,13 @@ class CmdletClass extends codegen_csharp_1.Class {
1775
1860
  else {
1776
1861
  parameters.push(`"${outputTypes.values().next().value.replace(/typeof\((.*)\)/, '$1')}"`);
1777
1862
  }
1778
- if (breakingChange.output.deprecateByVersion) {
1779
- parameters.push(`"${breakingChange.output.deprecateByVersion}"`);
1780
- if (breakingChange.output.changeInEfectByDate)
1781
- parameters.push(`"${breakingChange.output.changeInEfectByDate}"`);
1863
+ if (!breakingChange.output.deprecateByVersion || !breakingChange.output.deprecateByAzVersion) {
1864
+ throw new Error('Cmdlet breaking change requires both \'deprecateByVersion\' and \'deprecateByAzVersion\', please refer to https://github.com/Azure/azure-powershell/blob/main/documentation/development-docs/breakingchange-for-autogen-module.md for more details.');
1782
1865
  }
1866
+ parameters.push(`"${breakingChange.output.deprecateByVersion}"`);
1867
+ parameters.push(`"${breakingChange.output.deprecateByAzVersion}"`);
1868
+ if (breakingChange.output.changeInEfectByDate)
1869
+ parameters.push(`"${breakingChange.output.changeInEfectByDate}"`);
1783
1870
  if (breakingChange.output.replacement)
1784
1871
  parameters.push(`ReplacementCmdletOutputType = "${breakingChange.output.replacement}"`);
1785
1872
  if (breakingChange.output.deprecatedOutputProperties) {
@@ -1824,17 +1911,12 @@ class CmdletClass extends codegen_csharp_1.Class {
1824
1911
  });
1825
1912
  this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ProfileAttribute, { parameters: [...profileNames] }));
1826
1913
  }
1827
- this.operation.callGraph.forEach((operationInfo) => {
1828
- var _a;
1829
- let apiVersion = 'null';
1830
- if (operationInfo.apiVersions) {
1831
- apiVersion = operationInfo.apiVersions[0].version;
1832
- }
1833
- (_a = operationInfo.requests) === null || _a === void 0 ? void 0 : _a.forEach((request) => {
1834
- var _a, _b;
1835
- this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.HttpPathAttribute, { parameters: [`Path = "${(_b = (_a = request.protocol) === null || _a === void 0 ? void 0 : _a.http) === null || _b === void 0 ? void 0 : _b.path}"`, `ApiVersion = "${apiVersion}"`] }));
1836
- });
1837
- });
1914
+ if (this.operation.callGraph.length === 1) {
1915
+ this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.HttpPathAttribute, { parameters: [`Path = "${(_l = (_k = (_j = this.apiCall.requests) === null || _j === void 0 ? void 0 : _j[0].protocol) === null || _k === void 0 ? void 0 : _k.http) === null || _l === void 0 ? void 0 : _l.path}"`, `ApiVersion = "${(_m = this.apiCall.apiVersions) === null || _m === void 0 ? void 0 : _m[0].version}"`] }));
1916
+ }
1917
+ if (variantName.includes('ViaJsonString') || variantName.includes('ViaJsonFilePath')) {
1918
+ this.add(new codegen_csharp_1.Attribute(powershell_declarations_1.NotSuggestDefaultParameterSetAttribute));
1919
+ }
1838
1920
  }
1839
1921
  }
1840
1922
  exports.CmdletClass = CmdletClass;