@autorest/powershell 4.0.0-dev.7 → 4.0.0-dev.9

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 (115) hide show
  1. package/.rush/temp/package-deps_build.json +58 -54
  2. package/autorest-configuration.md +1 -1
  3. package/dist/cmdlets/class.d.ts +7 -0
  4. package/dist/cmdlets/class.d.ts.map +1 -1
  5. package/dist/cmdlets/class.js +248 -81
  6. package/dist/cmdlets/class.js.map +1 -1
  7. package/dist/cmdlets/namespace.d.ts.map +1 -1
  8. package/dist/cmdlets/namespace.js +1 -0
  9. package/dist/cmdlets/namespace.js.map +1 -1
  10. package/dist/generators/psm1.js +1 -1
  11. package/dist/generators/script-cmdlet.js +1 -1
  12. package/dist/internal/powershell-declarations.d.ts +1 -0
  13. package/dist/internal/powershell-declarations.d.ts.map +1 -1
  14. package/dist/internal/powershell-declarations.js +2 -1
  15. package/dist/internal/powershell-declarations.js.map +1 -1
  16. package/dist/internal/project.d.ts +9 -4
  17. package/dist/internal/project.d.ts.map +1 -1
  18. package/dist/internal/project.js +7 -9
  19. package/dist/internal/project.js.map +1 -1
  20. package/dist/llcsharp/clientruntime.d.ts +1 -0
  21. package/dist/llcsharp/clientruntime.d.ts.map +1 -1
  22. package/dist/llcsharp/clientruntime.js +1 -0
  23. package/dist/llcsharp/clientruntime.js.map +1 -1
  24. package/dist/llcsharp/csharp-declarations.d.ts +1 -0
  25. package/dist/llcsharp/csharp-declarations.d.ts.map +1 -1
  26. package/dist/llcsharp/csharp-declarations.js +2 -1
  27. package/dist/llcsharp/csharp-declarations.js.map +1 -1
  28. package/dist/llcsharp/model/interface.d.ts.map +1 -1
  29. package/dist/llcsharp/model/interface.js +14 -0
  30. package/dist/llcsharp/model/interface.js.map +1 -1
  31. package/dist/llcsharp/model/model-class.d.ts.map +1 -1
  32. package/dist/llcsharp/model/model-class.js +27 -11
  33. package/dist/llcsharp/model/model-class.js.map +1 -1
  34. package/dist/llcsharp/model/namespace.d.ts.map +1 -1
  35. package/dist/llcsharp/model/namespace.js +3 -11
  36. package/dist/llcsharp/model/namespace.js.map +1 -1
  37. package/dist/llcsharp/project.d.ts +2 -1
  38. package/dist/llcsharp/project.d.ts.map +1 -1
  39. package/dist/llcsharp/project.js +5 -3
  40. package/dist/llcsharp/project.js.map +1 -1
  41. package/dist/llcsharp/schema/array.js +7 -7
  42. package/dist/llcsharp/schema/array.js.map +1 -1
  43. package/dist/llcsharp/schema/fixed-array.d.ts +42 -0
  44. package/dist/llcsharp/schema/fixed-array.d.ts.map +1 -0
  45. package/dist/llcsharp/schema/fixed-array.js +251 -0
  46. package/dist/llcsharp/schema/fixed-array.js.map +1 -0
  47. package/dist/llcsharp/schema/schema-resolver.d.ts +1 -1
  48. package/dist/llcsharp/schema/schema-resolver.d.ts.map +1 -1
  49. package/dist/llcsharp/schema/schema-resolver.js +12 -10
  50. package/dist/llcsharp/schema/schema-resolver.js.map +1 -1
  51. package/dist/plugins/create-commands-v2.d.ts +1 -0
  52. package/dist/plugins/create-commands-v2.d.ts.map +1 -1
  53. package/dist/plugins/create-commands-v2.js +39 -6
  54. package/dist/plugins/create-commands-v2.js.map +1 -1
  55. package/dist/plugins/cs-namer-v2.d.ts.map +1 -1
  56. package/dist/plugins/cs-namer-v2.js +10 -7
  57. package/dist/plugins/cs-namer-v2.js.map +1 -1
  58. package/dist/plugins/llcsharp-v2.d.ts.map +1 -1
  59. package/dist/plugins/llcsharp-v2.js +4 -1
  60. package/dist/plugins/llcsharp-v2.js.map +1 -1
  61. package/dist/plugins/modifiers-v2.d.ts.map +1 -1
  62. package/dist/plugins/modifiers-v2.js +21 -2
  63. package/dist/plugins/modifiers-v2.js.map +1 -1
  64. package/dist/plugins/plugin-tweak-m4-model.d.ts.map +1 -1
  65. package/dist/plugins/plugin-tweak-m4-model.js +12 -0
  66. package/dist/plugins/plugin-tweak-m4-model.js.map +1 -1
  67. package/dist/plugins/sdk-create-inline-properties.d.ts.map +1 -1
  68. package/dist/plugins/sdk-create-inline-properties.js +26 -0
  69. package/dist/plugins/sdk-create-inline-properties.js.map +1 -1
  70. package/dist/plugins/sdk-cs-namer.d.ts.map +1 -1
  71. package/dist/plugins/sdk-cs-namer.js +17 -9
  72. package/dist/plugins/sdk-cs-namer.js.map +1 -1
  73. package/dist/plugins/sdk-tweak-model.d.ts.map +1 -1
  74. package/dist/plugins/sdk-tweak-model.js +13 -5
  75. package/dist/plugins/sdk-tweak-model.js.map +1 -1
  76. package/dist/utils/resourceName.d.ts +3 -0
  77. package/dist/utils/resourceName.d.ts.map +1 -0
  78. package/dist/utils/resourceName.js +29 -0
  79. package/dist/utils/resourceName.js.map +1 -0
  80. package/dist/utils/sort-parameters.d.ts +3 -0
  81. package/dist/utils/sort-parameters.d.ts.map +1 -0
  82. package/dist/utils/sort-parameters.js +33 -0
  83. package/dist/utils/sort-parameters.js.map +1 -0
  84. package/package.json +1 -1
  85. package/resources/assets/build-module.ps1 +4 -4
  86. package/resources/assets/check-dependencies.ps1 +3 -3
  87. package/resources/assets/create-model-cmdlets.ps1 +84 -15
  88. package/resources/assets/custom/README.md +1 -1
  89. package/resources/assets/docs/README.md +1 -1
  90. package/resources/assets/export-surface.ps1 +3 -3
  91. package/resources/assets/exports/README.md +1 -1
  92. package/resources/assets/generate-help.ps1 +3 -3
  93. package/resources/assets/generate-portal-ux.ps1 +3 -3
  94. package/resources/assets/how-to.md +1 -1
  95. package/resources/assets/internal/README.md +1 -1
  96. package/resources/assets/run-module.ps1 +4 -4
  97. package/resources/assets/test-module.ps1 +6 -6
  98. package/resources/assets/tools/Resources/custom/New-AzDeployment.ps1 +1 -1
  99. package/resources/assets/tools/Resources/docs/README.md +1 -1
  100. package/resources/assets/tools/Resources/how-to.md +1 -1
  101. package/resources/modules/Az.Accounts/2.7.5/Az.Accounts.nuspec +1 -1
  102. package/resources/modules/Az.Accounts/2.7.5/Az.Accounts.psd1 +1 -1
  103. package/resources/modules/Az.Accounts/2.7.5/Microsoft.Azure.PowerShell.Cmdlets.Accounts.dll-Help.xml +34 -34
  104. package/resources/modules/Az.Accounts/2.7.5/en-US/about_az.help.txt +1 -1
  105. package/resources/modules/Az.Accounts/2.7.5/package/services/metadata/core-properties/1aa0749a068a4238881858013f1a5b7f.psmdcp +1 -1
  106. package/resources/psruntime/Attributes/PSArgumentCompleterAttribute.cs +52 -0
  107. package/resources/psruntime/BuildTime/Cmdlets/ExportFormatPs1xml.cs +3 -1
  108. package/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs +18 -1
  109. package/resources/psruntime/BuildTime/Models/PsProxyTypes.cs +15 -2
  110. package/resources/psruntime/BuildTime/PsAttributes.cs +5 -0
  111. package/resources/psruntime/BuildTime/PsExtensions.cs +7 -0
  112. package/resources/psruntime/TypeConverterExtensions.cs +50 -0
  113. package/resources/runtime/csharp/json/Nodes/Collections/XNodeArray.cs +5 -0
  114. package/resources/runtime/csharp/pipeline/ISendAsync.cs +113 -0
  115. package/resources/templates/methodBodyRestCall.ejs +1 -1
@@ -11,6 +11,8 @@ namespace Microsoft.Rest.ClientRuntime
11
11
  using System.Threading.Tasks;
12
12
  using System.Collections;
13
13
  using System.Linq;
14
+ using System;
15
+
14
16
 
15
17
  /// <summary>
16
18
  /// The interface for sending an HTTP request across the wire.
@@ -70,6 +72,7 @@ namespace Microsoft.Rest.ClientRuntime
70
72
 
71
73
  public partial class HttpPipeline : ISendAsync
72
74
  {
75
+ private const int DefaultMaxRetry = 3;
73
76
  private ISendAsync pipeline;
74
77
  private ISendAsyncTerminalFactory terminal;
75
78
  private List<ISendAsyncFactory> steps = new List<ISendAsyncFactory>();
@@ -92,6 +95,111 @@ namespace Microsoft.Rest.ClientRuntime
92
95
  /// </summary>
93
96
  public HttpPipeline Clone() => new HttpPipeline(terminal) { steps = this.steps.ToList(), pipeline = this.pipeline };
94
97
 
98
+ private bool shouldRetry429(HttpResponseMessage response)
99
+ {
100
+ if (response.StatusCode == (System.Net.HttpStatusCode)429)
101
+ {
102
+ var retryAfter = response.Headers.RetryAfter;
103
+ if (retryAfter != null && retryAfter.Delta.HasValue)
104
+ {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ /// <summary>
111
+ /// The step to handle 429 response with retry-after header.
112
+ /// </summary>
113
+ public async Task<HttpResponseMessage> Retry429(HttpRequestMessage request, IEventListener callback, ISendAsync next)
114
+ {
115
+ int retryCount = int.MaxValue;
116
+
117
+ try
118
+ {
119
+ try
120
+ {
121
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("PS_HTTP_MAX_RETRIES_FOR_429"));
122
+ }
123
+ finally
124
+ {
125
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("AZURE_PS_HTTP_MAX_RETRIES_FOR_429"));
126
+ }
127
+ }
128
+ catch (System.Exception)
129
+ {
130
+ //no action
131
+ }
132
+ var cloneRequest = await request.CloneWithContent();
133
+ var response = await next.SendAsync(request, callback);
134
+ int count = 0;
135
+ while (shouldRetry429(response) && count++ < retryCount)
136
+ {
137
+ request = await cloneRequest.CloneWithContent();
138
+ var retryAfter = response.Headers.RetryAfter;
139
+ await Task.Delay(retryAfter.Delta.Value, callback.Token);
140
+ await callback.Signal("Debug", $"Start to retry {count} time(s) on status code 429 after waiting {retryAfter.Delta.Value.TotalSeconds} seconds.");
141
+ response = await next.SendAsync(request, callback);
142
+ }
143
+ return response;
144
+ }
145
+
146
+ private bool shouldRetryError(HttpResponseMessage response)
147
+ {
148
+ if (response.StatusCode >= System.Net.HttpStatusCode.InternalServerError)
149
+ {
150
+ if (response.StatusCode != System.Net.HttpStatusCode.NotImplemented &&
151
+ response.StatusCode != System.Net.HttpStatusCode.HttpVersionNotSupported)
152
+ {
153
+ return true;
154
+ }
155
+ }
156
+ else if (response.StatusCode == System.Net.HttpStatusCode.RequestTimeout)
157
+ {
158
+ return true;
159
+ }
160
+ else if (response.StatusCode == (System.Net.HttpStatusCode)429 && response.Headers.RetryAfter == null)
161
+ {
162
+ return true;
163
+ }
164
+ return false;
165
+ }
166
+
167
+ /// <summary>
168
+ /// Returns true if status code in HttpRequestExceptionWithStatus exception is greater
169
+ /// than or equal to 500 and not NotImplemented (501) or HttpVersionNotSupported (505).
170
+ /// Or it's 429 (TOO MANY REQUESTS) without Retry-After header.
171
+ /// </summary>
172
+ public async Task<HttpResponseMessage> RetryError(HttpRequestMessage request, IEventListener callback, ISendAsync next)
173
+ {
174
+ int retryCount = DefaultMaxRetry;
175
+
176
+ try
177
+ {
178
+ try
179
+ {
180
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("PS_HTTP_MAX_RETRIES"));
181
+ }
182
+ finally
183
+ {
184
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("AZURE_PS_HTTP_MAX_RETRIES"));
185
+ }
186
+ }
187
+ catch (System.Exception)
188
+ {
189
+ //no action
190
+ }
191
+ var cloneRequest = await request.CloneWithContent();
192
+ var response = await next.SendAsync(request, callback);
193
+ int count = 0;
194
+ while (shouldRetryError(response) && count++ < retryCount)
195
+ {
196
+ await callback.Signal("Debug", $"Start to retry {count} time(s) on status code {response.StatusCode}");
197
+ request = await cloneRequest.CloneWithContent();
198
+ response = await next.SendAsync(request, callback);
199
+ }
200
+ return response;
201
+ }
202
+
95
203
  public ISendAsyncTerminalFactory TerminalFactory
96
204
  {
97
205
  get => terminal;
@@ -117,6 +225,11 @@ namespace Microsoft.Rest.ClientRuntime
117
225
 
118
226
  // create the pipeline from scratch.
119
227
  var next = terminal.Create();
228
+ if (Convert.ToBoolean(@"${$project.enableApiRetry}"))
229
+ {
230
+ next = (new SendAsyncFactory(Retry429)).Create(next) ?? next;
231
+ next = (new SendAsyncFactory(RetryError)).Create(next) ?? next;
232
+ }
120
233
  foreach (var factory in steps)
121
234
  {
122
235
  // skip factories that return null.
@@ -52,7 +52,7 @@ if (method.extensions && method.extensions['x-ms-request-id']) {
52
52
  <%# ToDo: add support for BuildInputMappings -%>
53
53
  <% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body').forEach(function(parameter){-%>
54
54
  <%if(parameter.extensions && parameter.extensions['x-ms-client-flatten']) {-%>
55
- <%-method.language.default.returnType%> <%-parameter.language.default.name%> = new <%-method.language.default.returnType%>();
55
+ <%-parameter.schema.language.default.name%> <%-parameter.language.default.name%> = new <%-parameter.schema.language.default.name%>();
56
56
  <% var vps = project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties)-%>
57
57
  if(<%-vps.map(vp=>`${vp.property.language.default.name} != null`).join('||')%>)
58
58
  {