@autorest/powershell 4.0.0-dev.1 → 4.0.0-dev.4
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.
- package/.rush/temp/package-deps_build.json +37 -34
- package/.rush/temp/shrinkwrap-deps.json +13 -19
- package/dist/cmdlets/class.d.ts +1 -0
- package/dist/cmdlets/class.d.ts.map +1 -1
- package/dist/cmdlets/class.js +143 -76
- package/dist/cmdlets/class.js.map +1 -1
- package/dist/cmdlets/namespace.d.ts.map +1 -1
- package/dist/cmdlets/namespace.js +2 -1
- package/dist/cmdlets/namespace.js.map +1 -1
- package/dist/enums/namespace.js.map +1 -1
- package/dist/generators/inputhandler.custom.d.ts +3 -0
- package/dist/generators/inputhandler.custom.d.ts.map +1 -0
- package/dist/generators/inputhandler.custom.js +32 -0
- package/dist/generators/inputhandler.custom.js.map +1 -0
- package/dist/generators/psm1.js +1 -1
- package/dist/generators/psm1.js.map +1 -1
- package/dist/internal/project.d.ts +11 -9
- package/dist/internal/project.d.ts.map +1 -1
- package/dist/internal/project.js +5 -2
- package/dist/internal/project.js.map +1 -1
- package/dist/llcsharp/clientruntime.d.ts +2 -0
- package/dist/llcsharp/clientruntime.d.ts.map +1 -1
- package/dist/llcsharp/clientruntime.js +2 -0
- package/dist/llcsharp/clientruntime.js.map +1 -1
- package/dist/llcsharp/enums/enum.js +1 -1
- package/dist/llcsharp/enums/enum.js.map +1 -1
- package/dist/llcsharp/model/interface.d.ts.map +1 -1
- package/dist/llcsharp/model/interface.js.map +1 -1
- package/dist/llcsharp/model/model-class-json.d.ts.map +1 -1
- package/dist/llcsharp/model/model-class-json.js +11 -2
- package/dist/llcsharp/model/model-class-json.js.map +1 -1
- package/dist/llcsharp/model/model-class.js +7 -8
- package/dist/llcsharp/model/model-class.js.map +1 -1
- package/dist/llcsharp/operation/method.d.ts.map +1 -1
- package/dist/llcsharp/operation/method.js +6 -6
- package/dist/llcsharp/operation/method.js.map +1 -1
- package/dist/llcsharp/project.d.ts.map +1 -1
- package/dist/llcsharp/project.js +2 -1
- package/dist/llcsharp/project.js.map +1 -1
- package/dist/llcsharp/schema/date-time.d.ts.map +1 -1
- package/dist/llcsharp/schema/date-time.js.map +1 -1
- package/dist/llcsharp/schema/password.js +1 -1
- package/dist/llcsharp/schema/password.js.map +1 -1
- package/dist/llcsharp/schema/primitive.js.map +1 -1
- package/dist/llcsharp/schema/string.d.ts.map +1 -1
- package/dist/llcsharp/schema/string.js.map +1 -1
- package/dist/models/model-extensions.js +6 -6
- package/dist/models/model-extensions.js.map +1 -1
- package/dist/module/module-class.js.map +1 -1
- package/dist/plugins/create-commands-v2.d.ts.map +1 -1
- package/dist/plugins/create-commands-v2.js +2 -2
- package/dist/plugins/create-commands-v2.js.map +1 -1
- package/dist/plugins/cs-namer-v2.js +1 -1
- package/dist/plugins/cs-namer-v2.js.map +1 -1
- package/dist/plugins/modifiers-v2.d.ts +4 -0
- package/dist/plugins/modifiers-v2.d.ts.map +1 -1
- package/dist/plugins/modifiers-v2.js +65 -10
- package/dist/plugins/modifiers-v2.js.map +1 -1
- package/dist/plugins/plugin-tweak-m4-model.js +2 -2
- package/dist/plugins/plugin-tweak-m4-model.js.map +1 -1
- package/dist/plugins/plugin-tweak-model-azure-v2.js.map +1 -1
- package/dist/plugins/plugin-tweak-model.js +2 -2
- package/dist/plugins/plugin-tweak-model.js.map +1 -1
- package/dist/plugins/powershell-v2.d.ts.map +1 -1
- package/dist/plugins/powershell-v2.js +2 -0
- package/dist/plugins/powershell-v2.js.map +1 -1
- package/dist/utils/command-operation.d.ts +1 -0
- package/dist/utils/command-operation.d.ts.map +1 -1
- package/dist/utils/command-operation.js.map +1 -1
- package/dist/utils/powershell-comment.js +10 -10
- package/dist/utils/powershell-comment.js.map +1 -1
- package/package.json +3 -3
- package/resources/psruntime/BuildTime/Models/PsMarkdownTypes.cs +2 -2
- package/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs +5 -1
- package/resources/psruntime/BuildTime/Models/PsProxyTypes.cs +2 -0
- package/resources/runtime/csharp/client/Context.cs +33 -0
- package/resources/runtime/csharp/client/InfoAttribute.cs +1 -0
- package/resources/runtime/csharp/client/InputHandler.cs +22 -0
package/dist/cmdlets/class.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const codemodel_1 = require("@azure-tools/codemodel");
|
|
8
8
|
const codemodel_v3_1 = require("@azure-tools/codemodel-v3");
|
|
9
|
+
const command_operation_1 = require("../utils/command-operation");
|
|
9
10
|
const schema_1 = require("../utils/schema");
|
|
10
11
|
const codegen_1 = require("@azure-tools/codegen");
|
|
11
12
|
const linq_1 = require("@azure-tools/linq");
|
|
@@ -159,7 +160,7 @@ function NewAddCompleterInfo(targetProperty, parameter) {
|
|
|
159
160
|
exports.NewAddCompleterInfo = NewAddCompleterInfo;
|
|
160
161
|
function addParameterBreakingChange(targetProperty, parameter) {
|
|
161
162
|
if (parameter.breakingChange) {
|
|
162
|
-
|
|
163
|
+
const parameters = [];
|
|
163
164
|
parameters.push(`"${parameter.breakingChange.parameterName}"`);
|
|
164
165
|
if (parameter.breakingChange.deprecateByVersion) {
|
|
165
166
|
parameters.push(`"${parameter.breakingChange.deprecateByVersion}"`);
|
|
@@ -179,7 +180,7 @@ function addParameterBreakingChange(targetProperty, parameter) {
|
|
|
179
180
|
}
|
|
180
181
|
else {
|
|
181
182
|
// for primitive types, should use name, otherwise use fullname which contains namespace
|
|
182
|
-
parameters.push(`OldParamaterType="${parameter.schema.language.csharp.fullname.startsWith(
|
|
183
|
+
parameters.push(`OldParamaterType="${parameter.schema.language.csharp.fullname.startsWith('<') ? parameter.schema.language.csharp.name : parameter.schema.language.csharp.fullname}"`);
|
|
183
184
|
}
|
|
184
185
|
parameters.push(`NewParameterType="${parameter.breakingChange.newParameterType}"`);
|
|
185
186
|
}
|
|
@@ -201,7 +202,8 @@ function addDefaultInfo(targetProperty, parameter) {
|
|
|
201
202
|
parameters: [
|
|
202
203
|
new codegen_csharp_1.LiteralExpression(`\nName = ${new codegen_csharp_1.StringExpression(parameter.defaultInfo.name || '').value}`),
|
|
203
204
|
new codegen_csharp_1.LiteralExpression(`\nDescription =${new codegen_csharp_1.StringExpression(parameter.defaultInfo.description || '').value}`),
|
|
204
|
-
new codegen_csharp_1.LiteralExpression(`\nScript = ${new codegen_csharp_1.StringExpression(parameter.defaultInfo.script).value}`)
|
|
205
|
+
new codegen_csharp_1.LiteralExpression(`\nScript = ${new codegen_csharp_1.StringExpression(parameter.defaultInfo.script).value}`),
|
|
206
|
+
new codegen_csharp_1.LiteralExpression(`\nSetCondition = ${new codegen_csharp_1.StringExpression(parameter.defaultInfo['set-condition'] || '').value}`)
|
|
205
207
|
]
|
|
206
208
|
}));
|
|
207
209
|
}
|
|
@@ -321,6 +323,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
321
323
|
this.variantName = variantName;
|
|
322
324
|
this.hasStreamOutput = false;
|
|
323
325
|
this.interfaces.push(exports_1.ClientRuntime.IEventListener);
|
|
326
|
+
this.interfaces.push(exports_1.ClientRuntime.IContext);
|
|
324
327
|
this.eventListener = new exports_1.EventListener(new codegen_csharp_1.LiteralExpression(`((${exports_1.ClientRuntime.IEventListener})this)`), true);
|
|
325
328
|
this.isViaIdentity = variantName.indexOf('ViaIdentity') > 0;
|
|
326
329
|
this.clientsidePagination = !!operation.details.csharp.clientsidePagination && !!((_a = operation.callGraph[0].language.csharp) === null || _a === void 0 ? void 0 : _a.pageable);
|
|
@@ -337,7 +340,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
337
340
|
*body() {
|
|
338
341
|
if ($this.state.project.azure) {
|
|
339
342
|
yield `var telemetryId = ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.GetTelemetryId.Invoke();`;
|
|
340
|
-
yield codegen_csharp_1.If('telemetryId != "" && telemetryId != "internal"',
|
|
343
|
+
yield codegen_csharp_1.If('telemetryId != "" && telemetryId != "internal"', '__correlationId = telemetryId;');
|
|
341
344
|
}
|
|
342
345
|
yield 'Module.Instance.SetProxyConfiguration(Proxy, ProxyCredential, ProxyUseDefaultCredentials);';
|
|
343
346
|
yield codegen_csharp_1.If($this.$('Break'), `${exports_1.ClientRuntime.AttachDebugger}.Break();`);
|
|
@@ -355,6 +358,8 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
355
358
|
this.NewAddPowershellParameters(this.operation);
|
|
356
359
|
// implement IEventListener
|
|
357
360
|
this.implementIEventListener();
|
|
361
|
+
// implement part of the IContext
|
|
362
|
+
this.implementIContext();
|
|
358
363
|
// add constructors
|
|
359
364
|
this.implementConstructors();
|
|
360
365
|
// processRecord
|
|
@@ -410,7 +415,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
410
415
|
this.processRecordId = this.add(new codegen_csharp_1.Field('__processRecordId', codegen_csharp_1.dotnet.String, { description: 'A unique id generatd for the this cmdlet when ProcessRecord() is called.', access: codegen_csharp_1.Access.Private }));
|
|
411
416
|
}
|
|
412
417
|
// pipeline property
|
|
413
|
-
this.add(new codegen_csharp_1.Property('Pipeline', exports_1.ClientRuntime.HttpPipeline, { getAccess: codegen_csharp_1.Access.
|
|
418
|
+
this.add(new codegen_csharp_1.Property('Pipeline', exports_1.ClientRuntime.HttpPipeline, { getAccess: codegen_csharp_1.Access.Public, setAccess: codegen_csharp_1.Access.Public, description: `The instance of the <see cref="${exports_1.ClientRuntime.HttpPipeline}" /> that the remote call will use.` }));
|
|
414
419
|
// client API property (gs01: fill this in correctly)
|
|
415
420
|
const clientAPI = new codegen_csharp_1.ClassType((_a = this.state.model.language.csharp) === null || _a === void 0 ? void 0 : _a.namespace, ((_b = this.state.model.language.csharp) === null || _b === void 0 ? void 0 : _b.name) || '');
|
|
416
421
|
this.add(new codegen_csharp_1.LambdaProperty('Client', clientAPI, new codegen_csharp_1.LiteralExpression(`${this.state.project.serviceNamespace.moduleClass.declaration}.Instance.ClientAPI`), { description: 'The reference to the client API class.' }));
|
|
@@ -562,14 +567,37 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
562
567
|
yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletGetPipeline);
|
|
563
568
|
const pipeline = $this.$('Pipeline');
|
|
564
569
|
if ($this.state.project.azure) {
|
|
565
|
-
yield pipeline.assign(new codegen_csharp_1.LiteralExpression(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.CreatePipeline(${$this.invocationInfo}, ${$this.correlationId}, ${$this.processRecordId}, this.ParameterSetName)`));
|
|
570
|
+
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)`));
|
|
566
571
|
}
|
|
567
572
|
else {
|
|
568
|
-
yield pipeline.assign(new codegen_csharp_1.LiteralExpression(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.CreatePipeline(${$this.invocationInfo}, this.ParameterSetName)`));
|
|
573
|
+
yield pipeline.assign(new codegen_csharp_1.LiteralExpression(`${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.CreatePipeline(${$this.invocationInfo}, this.ParameterSetName, this.ExtensibleParameters)`));
|
|
569
574
|
}
|
|
570
575
|
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')}`)));
|
|
571
576
|
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')}`)));
|
|
572
577
|
yield '// get the client instance';
|
|
578
|
+
// Add input pipeline if it is configured by developers.
|
|
579
|
+
if ($this.operation.extensions.inputPipe) {
|
|
580
|
+
const handlers = $this.operation.extensions.inputPipe;
|
|
581
|
+
// default priority is 100
|
|
582
|
+
handlers.sort((a, b) => { return (a.priority || 100) - (b.priority || 100); });
|
|
583
|
+
for (const { index, handler } of handlers.map((handler, index) => ({ index, handler }))) {
|
|
584
|
+
yield `var handler_${index} = new ${handler.name}();`;
|
|
585
|
+
if (index > 0) {
|
|
586
|
+
yield `handler_${index - 1}.SetNextHandler(handler_${index});`;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
yield 'handler_0.Process(this);';
|
|
590
|
+
}
|
|
591
|
+
const vps = $this.operation.details.csharp.virtualParameters || {
|
|
592
|
+
body: [],
|
|
593
|
+
operation: [],
|
|
594
|
+
};
|
|
595
|
+
for (const vParam of [...vps.body, ...vps.operation]) {
|
|
596
|
+
if (vParam.hidden) {
|
|
597
|
+
const td = $this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(vParam.schema, true, $this.state);
|
|
598
|
+
yield codegen_csharp_1.If(`true == this.MyInvocation?.BoundParameters?.ContainsKey("${vParam.name}")`, `${vParam.name} = (${td.declaration})this.MyInvocation.BoundParameters["${vParam.name}"];`);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
573
601
|
const apiCall = operation.callGraph[0];
|
|
574
602
|
// find each parameter to the method, and find out where the value is going to come from.
|
|
575
603
|
const operationParameters = linq_1.values(apiCall.parameters).
|
|
@@ -625,7 +653,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
625
653
|
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` }));
|
|
626
654
|
}
|
|
627
655
|
if (isBinary) {
|
|
628
|
-
parameters.push(new codegen_csharp_1.Parameter('response', codegen_csharp_1.System.Threading.Tasks.Task({ declaration: 'global::System.IO.Stream' }), { description:
|
|
656
|
+
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' }));
|
|
629
657
|
}
|
|
630
658
|
const override = `override${codegen_1.pascalCase(((_f = each.language.csharp) === null || _f === void 0 ? void 0 : _f.name) || '')}`;
|
|
631
659
|
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 )` });
|
|
@@ -727,15 +755,15 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
727
755
|
const vp = schema_1.getVirtualPropertyFromPropertyName((_m = schema.language.csharp) === null || _m === void 0 ? void 0 : _m.virtualProperties, valueProperty.serializedName);
|
|
728
756
|
if (vp) {
|
|
729
757
|
if ($this.clientsidePagination) {
|
|
730
|
-
yield (codegen_csharp_1.If(
|
|
731
|
-
yield (
|
|
758
|
+
yield (codegen_csharp_1.If('(ulong)result.Value.Length <= this.PagingParameters.Skip', function* () {
|
|
759
|
+
yield ('this.PagingParameters.Skip = this.PagingParameters.Skip - (ulong)result.Value.Length;');
|
|
732
760
|
}));
|
|
733
761
|
yield codegen_csharp_1.Else(function* () {
|
|
734
|
-
yield (
|
|
735
|
-
yield (
|
|
736
|
-
yield (
|
|
737
|
-
yield (
|
|
738
|
-
yield (
|
|
762
|
+
yield ('ulong toRead = Math.Min(this.PagingParameters.First, (ulong)result.Value.Length - this.PagingParameters.Skip);');
|
|
763
|
+
yield ('var requiredResult = result.Value.SubArray((int)this.PagingParameters.Skip, (int)toRead);');
|
|
764
|
+
yield ('WriteObject(requiredResult, true);');
|
|
765
|
+
yield ('this.PagingParameters.Skip = 0;');
|
|
766
|
+
yield ('this.PagingParameters.First = this.PagingParameters.First <= toRead ? 0 : this.PagingParameters.First - toRead;');
|
|
739
767
|
});
|
|
740
768
|
}
|
|
741
769
|
else {
|
|
@@ -746,18 +774,18 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
746
774
|
if (nl) {
|
|
747
775
|
$this.add(new codegen_csharp_1.Field('_isFirst', codegen_csharp_1.dotnet.Bool, {
|
|
748
776
|
access: codegen_csharp_1.Access.Private,
|
|
749
|
-
initialValue: new codegen_csharp_1.LiteralExpression(
|
|
750
|
-
description:
|
|
777
|
+
initialValue: new codegen_csharp_1.LiteralExpression('true'),
|
|
778
|
+
description: 'A flag to tell whether it is the first onOK call.'
|
|
751
779
|
}));
|
|
752
780
|
$this.add(new codegen_csharp_1.Field('_nextLink', codegen_csharp_1.dotnet.String, {
|
|
753
781
|
access: codegen_csharp_1.Access.Private,
|
|
754
|
-
description:
|
|
782
|
+
description: 'Link to retrieve next page.'
|
|
755
783
|
}));
|
|
756
784
|
const nextLinkName = `${result.value}.${nl.name}`;
|
|
757
785
|
yield `_nextLink = ${nextLinkName};`;
|
|
758
|
-
|
|
759
|
-
yield (codegen_csharp_1.If(
|
|
760
|
-
yield
|
|
786
|
+
const nextLinkCondition = $this.clientsidePagination ? '_nextLink != null && this.PagingParameters.First > 0' : '_nextLink != null';
|
|
787
|
+
yield (codegen_csharp_1.If('_isFirst', function* () {
|
|
788
|
+
yield '_isFirst = false;';
|
|
761
789
|
yield (codegen_csharp_1.While(nextLinkCondition, codegen_csharp_1.If('responseMessage.RequestMessage is System.Net.Http.HttpRequestMessage requestMessage ', function* () {
|
|
762
790
|
var _a;
|
|
763
791
|
yield `requestMessage = requestMessage.Clone(new global::System.Uri( _nextLink ),${exports_1.ClientRuntime.Method.Get} );`;
|
|
@@ -823,21 +851,21 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
823
851
|
}
|
|
824
852
|
// in m4, there will be no schema deinfed for the binary response, instead, we will have a field called binary with value true.
|
|
825
853
|
if ('binary' in each) {
|
|
826
|
-
yield
|
|
854
|
+
yield '// (await response) // should be global::System.IO.Stream';
|
|
827
855
|
if ($this.hasStreamOutput && $this.outFileParameter) {
|
|
828
856
|
const outfile = $this.outFileParameter;
|
|
829
857
|
const provider = codegen_csharp_2.Local('provider');
|
|
830
858
|
provider.initializer = undefined;
|
|
831
|
-
const paths = codegen_csharp_2.Local('paths',
|
|
859
|
+
const paths = codegen_csharp_2.Local('paths', 'new global::System.Collections.ObjectModel.Collection<global::System.String>()');
|
|
832
860
|
yield paths.declarationStatement;
|
|
833
861
|
yield codegen_csharp_1.Try(function* () {
|
|
834
862
|
yield `${paths.value} = this.SessionState.Path.GetResolvedProviderPathFromPSPath(${outfile.value}, out ${provider.declarationExpression});`;
|
|
835
863
|
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}) );`);
|
|
836
864
|
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}) );`);
|
|
837
865
|
});
|
|
838
|
-
const notfound = new codegen_csharp_1.Parameter('', { declaration:
|
|
866
|
+
const notfound = new codegen_csharp_1.Parameter('', { declaration: 'global::System.Management.Automation.ItemNotFoundException' });
|
|
839
867
|
yield codegen_csharp_1.Catch(notfound, function* () {
|
|
840
|
-
yield
|
|
868
|
+
yield '// If the file does not exist, we will try to create it';
|
|
841
869
|
yield `${paths.value}.Add(${outfile.value});`;
|
|
842
870
|
});
|
|
843
871
|
// this is a stream output. write to outfile
|
|
@@ -867,6 +895,15 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
867
895
|
yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletBeforeAPICall);
|
|
868
896
|
const idOpParams = operationParameters.filter(each => !each.isPathParam);
|
|
869
897
|
const idschema = linq_1.values($this.state.project.model.schemas.objects).first(each => each.language.default.uid === 'universal-parameter-type');
|
|
898
|
+
let serializationMode = null;
|
|
899
|
+
if ($this.bodyParameter) {
|
|
900
|
+
if ($this.operation.operationType === command_operation_1.OperationType.Create) {
|
|
901
|
+
serializationMode = exports_1.ClientRuntime.SerializationMode.IncludeCreate;
|
|
902
|
+
}
|
|
903
|
+
else if ($this.operation.operationType === command_operation_1.OperationType.Update) {
|
|
904
|
+
serializationMode = exports_1.ClientRuntime.SerializationMode.IncludeUpdate;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
870
907
|
if ($this.isViaIdentity) {
|
|
871
908
|
const identityFromPathParams = function* () {
|
|
872
909
|
var _a, _b;
|
|
@@ -916,7 +953,11 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
916
953
|
}
|
|
917
954
|
};
|
|
918
955
|
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'; })) {
|
|
919
|
-
|
|
956
|
+
const parameters = [codegen_csharp_1.toExpression('InputObject.Id'), ...idOpParams.map(each => each.expression), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
|
|
957
|
+
if (serializationMode) {
|
|
958
|
+
parameters.push(serializationMode);
|
|
959
|
+
}
|
|
960
|
+
yield codegen_csharp_1.If('InputObject?.Id != null', `await this.${$this.$('Client').invokeMethod(`${(_a = apiCall.language.csharp) === null || _a === void 0 ? void 0 : _a.name}ViaIdentity`, ...parameters).implementation}`);
|
|
920
961
|
yield codegen_csharp_1.Else(identityFromPathParams);
|
|
921
962
|
}
|
|
922
963
|
else {
|
|
@@ -924,7 +965,11 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
924
965
|
}
|
|
925
966
|
}
|
|
926
967
|
else {
|
|
927
|
-
|
|
968
|
+
const parameters = [...operationParameters.map(each => each.expression), ...callbackMethods, codegen_csharp_1.dotnet.This, pipeline];
|
|
969
|
+
if (serializationMode) {
|
|
970
|
+
parameters.push(serializationMode);
|
|
971
|
+
}
|
|
972
|
+
yield `await this.${$this.$('Client').invokeMethod(`${(_b = apiCall.language.csharp) === null || _b === void 0 ? void 0 : _b.name}`, ...parameters).implementation}`;
|
|
928
973
|
}
|
|
929
974
|
yield $this.eventListener.signal(powershell_declarations_1.Events.CmdletAfterAPICall);
|
|
930
975
|
};
|
|
@@ -984,6 +1029,16 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
984
1029
|
// default constructor
|
|
985
1030
|
this.add(new codegen_csharp_1.Constructor(this, { description: `Intializes a new instance of the <see cref="${this.name}" /> cmdlet class.` }));
|
|
986
1031
|
}
|
|
1032
|
+
implementIContext() {
|
|
1033
|
+
const extensibleParameters = this.add(new codegen_csharp_1.Field('_extensibleParameters', codegen_csharp_1.System.Collections.Generic.Dictionary(codegen_csharp_1.System.String, codegen_csharp_1.System.Object), {
|
|
1034
|
+
access: codegen_csharp_1.Access.Private,
|
|
1035
|
+
initialValue: new codegen_csharp_1.LiteralExpression('new System.Collections.Generic.Dictionary<string, object>()'),
|
|
1036
|
+
description: 'A dictionary to carry over additional data for pipeline.'
|
|
1037
|
+
}));
|
|
1038
|
+
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.' });
|
|
1039
|
+
extensibleParametersProp.get = codegen_csharp_1.toExpression(`${extensibleParameters.value} `);
|
|
1040
|
+
this.add(extensibleParametersProp);
|
|
1041
|
+
}
|
|
987
1042
|
implementIEventListener() {
|
|
988
1043
|
const $this = this;
|
|
989
1044
|
const cts = this.add(new codegen_csharp_1.Field('_cancellationTokenSource', codegen_csharp_1.System.Threading.CancellationTokenSource, {
|
|
@@ -991,6 +1046,10 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
991
1046
|
initialValue: new codegen_csharp_1.LiteralExpression(`new ${codegen_csharp_1.System.Threading.CancellationTokenSource.declaration}()`),
|
|
992
1047
|
description: `The <see cref="${codegen_csharp_1.System.Threading.CancellationTokenSource}" /> for this operation.`
|
|
993
1048
|
}));
|
|
1049
|
+
const cancellationTokenSource = new codegen_csharp_1.Property('CancellationTokenSource', codegen_csharp_1.System.Threading.CancellationTokenSource, { description: 'Accessor for cancellationTokenSource.' });
|
|
1050
|
+
cancellationTokenSource.get = codegen_csharp_1.toExpression(`${cts.value} `);
|
|
1051
|
+
cancellationTokenSource.set = new codegen_csharp_1.Statements(cts.assign('value'));
|
|
1052
|
+
this.add(cancellationTokenSource);
|
|
994
1053
|
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.` }));
|
|
995
1054
|
this.cancellationToken = codegen_csharp_1.toExpression(`((${exports_1.ClientRuntime.IEventListener})this).Token`);
|
|
996
1055
|
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.` }));
|
|
@@ -1124,7 +1183,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1124
1183
|
}
|
|
1125
1184
|
if (this.dropBodyParameter && parameter.details.csharp.isBodyParameter) {
|
|
1126
1185
|
// we're supposed to use parameters for the body parameter instead of a big object
|
|
1127
|
-
const expandedBodyParameter = this.add(new codegen_csharp_1.Field(
|
|
1186
|
+
const expandedBodyParameter = this.add(new codegen_csharp_1.Field('_' + codegen_1.camelCase(parameter.details.csharp.name), td, {
|
|
1128
1187
|
description: parameter.details.csharp.description,
|
|
1129
1188
|
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}()`,
|
|
1130
1189
|
access: codegen_csharp_1.Access.Private
|
|
@@ -1210,7 +1269,6 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1210
1269
|
this.addDoNotExport(cmdletParameter, vParam);
|
|
1211
1270
|
}
|
|
1212
1271
|
const isEnum = propertyType instanceof exports_1.EnumImplementation;
|
|
1213
|
-
;
|
|
1214
1272
|
const hasEnum = propertyType instanceof exports_1.ArrayOf && propertyType.elementType instanceof exports_1.EnumImplementation;
|
|
1215
1273
|
if (isEnum || hasEnum) {
|
|
1216
1274
|
cmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ArgumentCompleterAttribute, { parameters: [`typeof(${hasEnum ? propertyType.elementType.declaration : propertyType.declaration})`] }));
|
|
@@ -1268,52 +1326,65 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1268
1326
|
// skip 'Host'
|
|
1269
1327
|
continue;
|
|
1270
1328
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
//
|
|
1276
|
-
this.add(new codegen_csharp_1.BackedProperty(vParam.name, codegen_csharp_1.
|
|
1277
|
-
metadata: {
|
|
1278
|
-
parameterDefinition: origin.details.csharp.httpParameter
|
|
1279
|
-
},
|
|
1280
|
-
description: vParam.description
|
|
1281
|
-
})) :
|
|
1282
|
-
// everything else
|
|
1283
|
-
this.add(new codegen_csharp_1.BackedProperty(vParam.name, propertyType, {
|
|
1284
|
-
metadata: {
|
|
1285
|
-
parameterDefinition: origin.details.csharp.httpParameter
|
|
1286
|
-
},
|
|
1329
|
+
let regularCmdletParameter;
|
|
1330
|
+
let origin = null;
|
|
1331
|
+
let propertyType = null;
|
|
1332
|
+
if (vParam.type) {
|
|
1333
|
+
// Handle parameters added through directives
|
|
1334
|
+
regularCmdletParameter = this.add(new codegen_csharp_1.BackedProperty(vParam.name, new codegen_csharp_1.ClassType('', vParam.type), {
|
|
1287
1335
|
description: vParam.description
|
|
1288
1336
|
}));
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1337
|
+
}
|
|
1338
|
+
else {
|
|
1339
|
+
const vSchema = vParam.schema;
|
|
1340
|
+
propertyType = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration(vSchema, true, this.state);
|
|
1341
|
+
origin = vParam.origin;
|
|
1342
|
+
regularCmdletParameter = (this.state.project.azure && vParam.name === 'SubscriptionId' && operation.details.csharp.verb.toLowerCase() === 'get') ?
|
|
1343
|
+
// special case for subscription id
|
|
1344
|
+
this.add(new codegen_csharp_1.BackedProperty(vParam.name, codegen_csharp_1.dotnet.StringArray, {
|
|
1345
|
+
metadata: {
|
|
1346
|
+
parameterDefinition: origin.details.csharp.httpParameter
|
|
1347
|
+
},
|
|
1348
|
+
description: vParam.description
|
|
1349
|
+
})) :
|
|
1350
|
+
// everything else
|
|
1351
|
+
this.add(new codegen_csharp_1.BackedProperty(vParam.name, propertyType, {
|
|
1352
|
+
metadata: {
|
|
1353
|
+
parameterDefinition: origin.details.csharp.httpParameter
|
|
1354
|
+
},
|
|
1355
|
+
description: vParam.description
|
|
1356
|
+
}));
|
|
1357
|
+
const dictSchema = vSchema.type === codemodel_1.SchemaType.Dictionary ? vSchema :
|
|
1358
|
+
vSchema.type === codemodel_1.SchemaType.Object ? (_j = (_h = vSchema.parents) === null || _h === void 0 ? void 0 : _h.immediate) === null || _j === void 0 ? void 0 : _j.find((s) => s.type === codemodel_1.SchemaType.Dictionary) :
|
|
1359
|
+
undefined;
|
|
1360
|
+
if (dictSchema) {
|
|
1361
|
+
// we have to figure out if this is a standalone dictionary or a hybrid object/dictionary.
|
|
1362
|
+
// if it's a hybrid, we have to create another parameter like -<XXX>AdditionalProperties and have that dump the contents into the dictionary
|
|
1363
|
+
// if it's a standalone dictionary, we can just use hashtable instead
|
|
1364
|
+
if (linq_1.length(vSchema.properties) === 0) {
|
|
1365
|
+
// it's a pure dictionary
|
|
1366
|
+
// change the property type to hashtable.
|
|
1367
|
+
// add an attribute to change the exported type.
|
|
1368
|
+
regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ExportAsAttribute, { parameters: [`typeof(${codegen_csharp_1.System.Collections.Hashtable})`] }));
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
// it's a hybrid. We need to add an additional property that puts its items into the target container
|
|
1372
|
+
}
|
|
1304
1373
|
}
|
|
1305
1374
|
}
|
|
1306
1375
|
this.thingsToSerialize.push(regularCmdletParameter);
|
|
1307
1376
|
const parameters = [new codegen_csharp_1.LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new codegen_csharp_1.LiteralExpression(`HelpMessage = "${codegen_1.escapeString(vParam.description) || '.'}"`)];
|
|
1308
|
-
if (origin.details.csharp.isBodyParameter) {
|
|
1377
|
+
if (!!origin && origin.details.csharp.isBodyParameter) {
|
|
1309
1378
|
parameters.push(new codegen_csharp_1.LiteralExpression('ValueFromPipeline = true'));
|
|
1310
1379
|
this.bodyParameter = regularCmdletParameter;
|
|
1311
1380
|
}
|
|
1312
1381
|
regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ParameterAttribute, { parameters }));
|
|
1313
|
-
if (vParam.schema.type === codemodel_1.SchemaType.Array) {
|
|
1382
|
+
if (!vParam.type && vParam.schema.type === codemodel_1.SchemaType.Array) {
|
|
1314
1383
|
regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.AllowEmptyCollectionAttribute));
|
|
1315
1384
|
}
|
|
1316
|
-
|
|
1385
|
+
if (!!origin && !!propertyType) {
|
|
1386
|
+
NewAddInfoAttribute(regularCmdletParameter, propertyType, (_k = vParam.required, (_k !== null && _k !== void 0 ? _k : false)), false, vParam.description, origin.name);
|
|
1387
|
+
}
|
|
1317
1388
|
NewAddCompleterInfo(regularCmdletParameter, vParam);
|
|
1318
1389
|
addParameterBreakingChange(regularCmdletParameter, vParam);
|
|
1319
1390
|
addPreviewMessage(regularCmdletParameter, vParam);
|
|
@@ -1323,7 +1394,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1323
1394
|
if (linq_1.length(vParam.alias) > 0) {
|
|
1324
1395
|
regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.Alias, { parameters: vParam.alias.map(x => '"' + x + '"') }));
|
|
1325
1396
|
}
|
|
1326
|
-
const httpParam = origin.details.csharp.httpParameter;
|
|
1397
|
+
const httpParam = origin ? origin.details.csharp.httpParameter : null;
|
|
1327
1398
|
//const uid = httpParam ? httpParam.details.csharp.uid : 'no-parameter';
|
|
1328
1399
|
if (httpParam) {
|
|
1329
1400
|
// xichen: Is it safe to compare by csharp serializedName? Because we no longer have uid
|
|
@@ -1332,13 +1403,9 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1332
1403
|
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))}`] }));
|
|
1333
1404
|
}
|
|
1334
1405
|
}
|
|
1335
|
-
if (origin.details.csharp.completer) {
|
|
1336
|
-
// add the completer to this class and tag this parameter with the completer.
|
|
1337
|
-
// regularCmdletParameter.add(new Attribute(ArgumentCompleterAttribute, { parameters: [`typeof(${this.declaration})`] }));
|
|
1338
|
-
}
|
|
1339
1406
|
const isEnum = propertyType instanceof exports_1.EnumImplementation;
|
|
1340
1407
|
const hasEnum = propertyType instanceof exports_1.ArrayOf && propertyType.elementType instanceof exports_1.EnumImplementation;
|
|
1341
|
-
if (isEnum || hasEnum) {
|
|
1408
|
+
if (propertyType && (isEnum || hasEnum)) {
|
|
1342
1409
|
regularCmdletParameter.add(new codegen_csharp_1.Attribute(powershell_declarations_1.ArgumentCompleterAttribute, { parameters: [`typeof(${hasEnum ? propertyType.elementType.declaration : propertyType.declaration})`] }));
|
|
1343
1410
|
}
|
|
1344
1411
|
}
|
|
@@ -1455,9 +1522,9 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1455
1522
|
}
|
|
1456
1523
|
//add breaking change attributes for cmdlet, variant, output type
|
|
1457
1524
|
if (operation.details.csharp.breakingChange) {
|
|
1458
|
-
|
|
1525
|
+
const breakingChange = operation.details.csharp.breakingChange;
|
|
1459
1526
|
if (breakingChange.cmdlet) {
|
|
1460
|
-
|
|
1527
|
+
const parameters = [];
|
|
1461
1528
|
if (breakingChange.cmdlet.deprecateByVersion) {
|
|
1462
1529
|
parameters.push(`"${breakingChange.cmdlet.deprecateByVersion}"`);
|
|
1463
1530
|
if (breakingChange.cmdlet.changeInEfectByDate)
|
|
@@ -1470,7 +1537,7 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1470
1537
|
this.add(new codegen_csharp_1.Attribute(exports_1.ClientRuntime.CmdletBreakingChangeAttribute, { parameters: parameters }));
|
|
1471
1538
|
}
|
|
1472
1539
|
if (breakingChange.variant) {
|
|
1473
|
-
|
|
1540
|
+
const parameters = [];
|
|
1474
1541
|
parameters.push(`new string[] {"${breakingChange.variant.name}"}`);
|
|
1475
1542
|
if (breakingChange.variant.deprecateByVersion) {
|
|
1476
1543
|
parameters.push(`"${breakingChange.variant.deprecateByVersion}"`);
|
|
@@ -1482,13 +1549,13 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1482
1549
|
this.add(new codegen_csharp_1.Attribute(exports_1.ClientRuntime.ParameterSetBreakingChangeAttribute, { parameters: parameters }));
|
|
1483
1550
|
}
|
|
1484
1551
|
if (breakingChange.output) {
|
|
1485
|
-
|
|
1552
|
+
const parameters = [];
|
|
1486
1553
|
// if deprecated output types are set in directive, use it
|
|
1487
1554
|
if (breakingChange.output.deprecatedCmdLetOutputType) {
|
|
1488
1555
|
parameters.push(`"${breakingChange.output.deprecatedCmdLetOutputType}"`);
|
|
1489
1556
|
}
|
|
1490
1557
|
else {
|
|
1491
|
-
parameters.push(`"${outputTypes.values().next().value.replace(/typeof\((.*)\)/,
|
|
1558
|
+
parameters.push(`"${outputTypes.values().next().value.replace(/typeof\((.*)\)/, '$1')}"`);
|
|
1492
1559
|
}
|
|
1493
1560
|
if (breakingChange.output.deprecateByVersion) {
|
|
1494
1561
|
parameters.push(`"${breakingChange.output.deprecateByVersion}"`);
|
|
@@ -1498,12 +1565,12 @@ class CmdletClass extends codegen_csharp_1.Class {
|
|
|
1498
1565
|
if (breakingChange.output.replacement)
|
|
1499
1566
|
parameters.push(`ReplacementCmdletOutputType="${breakingChange.output.replacement}"`);
|
|
1500
1567
|
if (breakingChange.output.deprecatedOutputProperties) {
|
|
1501
|
-
|
|
1568
|
+
const properties = Object.assign([], breakingChange.output.deprecatedOutputProperties);
|
|
1502
1569
|
properties.forEach((element, index) => properties[index] = '"' + element + '"');
|
|
1503
1570
|
parameters.push(`DeprecatedOutputProperties=new string[] {${properties.join(',')}}`);
|
|
1504
1571
|
}
|
|
1505
1572
|
if (breakingChange.output.newOutputProperties) {
|
|
1506
|
-
|
|
1573
|
+
const properties = Object.assign([], breakingChange.output.newOutputProperties);
|
|
1507
1574
|
properties.forEach((element, index) => properties[index] = '"' + element + '"');
|
|
1508
1575
|
parameters.push(`NewOutputProperties=new string[] {${properties.join(',')}}`);
|
|
1509
1576
|
}
|