diff --git a/powershell/cmdlets/class.ts b/powershell/cmdlets/class.ts index 7851a30634c..3d8f569cd03 100644 --- a/powershell/cmdlets/class.ts +++ b/powershell/cmdlets/class.ts @@ -11,7 +11,7 @@ import { escapeString, docComment, serialize, pascalCase, DeepPartial } from '@a import { items, values, Dictionary, length } from '@azure-tools/linq'; import { Access, Attribute, BackedProperty, Catch, Class, ClassType, Constructor, dotnet, Else, Expression, Finally, ForEach, If, LambdaProperty, LiteralExpression, LocalVariable, Method, Modifier, Namespace, OneOrMoreStatements, Parameter, Property, Return, Statements, BlockStatement, StringExpression, - Switch, System, TerminalCase, toExpression, Try, Using, valueOf, Field, IsNull, Or, ExpressionOrLiteral, TerminalDefaultCase, xmlize, TypeDeclaration, And, IsNotNull, PartialMethod, Case + Switch, System, TerminalCase, toExpression, Try, Using, valueOf, Field, IsNull, Or, ExpressionOrLiteral, TerminalDefaultCase, xmlize, TypeDeclaration, And, IsNotNull, PartialMethod, Case, While } from '@azure-tools/codegen-csharp'; import { ClientRuntime, EventListener, Schema, ArrayOf, EnumImplementation } from '../llcsharp/exports'; import { Alias, ArgumentCompleterAttribute, AsyncCommandRuntime, AsyncJob, CmdletAttribute, ErrorCategory, ErrorRecord, Events, InvocationInfo, OutputTypeAttribute, ParameterAttribute, PSCmdlet, PSCredential, SwitchParameter, ValidateNotNull, verbEnum, GeneratedAttribute, DescriptionAttribute, CategoryAttribute, ParameterCategory, ProfileAttribute, PSObject, InternalExportAttribute, ExportAsAttribute, DefaultRunspace, RunspaceFactory, AllowEmptyCollectionAttribute, DoNotExportAttribute } from '../internal/powershell-declarations'; @@ -858,15 +858,28 @@ export class CmdletClass extends Class { } const nl = NewGetVirtualPropertyFromPropertyName(schema.language.csharp?.virtualProperties, nextLinkProperty.serializedName); if (nl) { + $this.add(new Field('_isFirst', dotnet.Bool, { + access: Access.Private, + initialValue: new LiteralExpression(`true`), + description: `A flag to tell whether it is the first onOK call.` + })); + $this.add(new Field('_nextLink', dotnet.String, { + access: Access.Private, + description: `Link to retrieve next page.` + })); const nextLinkName = `${result.value}.${nl.name}`; - var nextLinkCondition = $this.clientsidePagination ? `${nextLinkName} != null && this.PagingParameters.First > 0` : `${nextLinkName} != null` - yield (If(nextLinkCondition, - If('responseMessage.RequestMessage is System.Net.Http.HttpRequestMessage requestMessage ', function* () { - yield `requestMessage = requestMessage.Clone(new global::System.Uri( ${nextLinkName} ),${ClientRuntime.Method.Get} );`; - yield $this.eventListener.signal(Events.FollowingNextLink); - yield `await this.${$this.$('Client').invokeMethod(`${apiCall.language.csharp?.name}_Call`, ...[toExpression('requestMessage'), ...callbackMethods, dotnet.This, pipeline]).implementation}`; - }) - )); + yield `_nextLink = ${nextLinkName};` + var nextLinkCondition = $this.clientsidePagination ? `_nextLink != null && this.PagingParameters.First > 0` : `_nextLink != null` + yield (If(`_isFirst`, function* () { + yield `_isFirst = false;` + yield (While(nextLinkCondition, + If('responseMessage.RequestMessage is System.Net.Http.HttpRequestMessage requestMessage ', function* () { + yield `requestMessage = requestMessage.Clone(new global::System.Uri( _nextLink ),${ClientRuntime.Method.Get} );`; + yield $this.eventListener.signal(Events.FollowingNextLink); + yield `await this.${$this.$('Client').invokeMethod(`${apiCall.language.csharp?.name}_Call`, ...[toExpression('requestMessage'), ...callbackMethods, dotnet.This, pipeline]).implementation}`; + }) + )) + })); } return; } else if (valueProperty) { @@ -1349,7 +1362,9 @@ export class CmdletClass extends Class { inputFileParameter.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "Input File for ${cmdletParameter.name} (${escapeString(desc || '.')})"`)] })); inputFileParameter.add(new Attribute(CategoryAttribute, { parameters: [`${ParameterCategory}.Body`] })); - + if (length(vParam.alias) > 0) { + inputFileParameter.add(new Attribute(Alias, { parameters: vParam.alias.map(x => '"' + x + '"') })); + } $this.add(inputFileParameter); } else { cmdletParameter.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "${escapeString(desc || '.')}"`)] }));