@@ -425,7 +425,7 @@ function New-SwaggerPath
425425 $parametersToAdd = @ {}
426426 $flattenedParametersOnPSCmdlet = @ {}
427427 $parameterHitCount = @ {}
428- $globalParameterBlock = ' '
428+ $globalParameters = @ ()
429429 $x_ms_pageableObject = $null
430430 foreach ($parameterSetDetail in $parameterSetDetails ) {
431431 if ($parameterSetDetail.ContainsKey (' x-ms-pageable' ) -and $parameterSetDetail .' x-ms-pageable' -and (-not $isNextPageOperation )) {
@@ -505,7 +505,7 @@ function New-SwaggerPath
505505 $globalParameterValue = $parameterDetails.ConstantValue
506506 }
507507
508- $globalParameterBlock += [ Environment ]::NewLine + $executionContext .InvokeCommand.ExpandString ( $GlobalParameterBlockStr )
508+ $globalParameters += $globalParameterName
509509 }
510510 }
511511
@@ -609,24 +609,24 @@ function New-SwaggerPath
609609 }
610610
611611 # Process security section
612- $azSubscriptionIdBlock = " "
613- $authFunctionCall = " "
614- $overrideBaseUriBlock = " "
615- $httpClientHandlerCall = " "
612+ $SubscriptionIdCommand = " "
613+ $AuthenticationCommand = " "
614+ $AuthenticationCommandArgumentName = ' '
615+ $hostOverrideCommand = ' '
616+ $AddHttpClientHandler = $false
616617 $securityParametersToAdd = @ ()
617618 $PowerShellCodeGen = $SwaggerMetaDict [' PowerShellCodeGen' ]
618619 if (($PowerShellCodeGen [' ServiceType' ] -eq ' azure' ) -or ($PowerShellCodeGen [' ServiceType' ] -eq ' azure_stack' )) {
619- $azSubscriptionIdBlock = " `$ subscriptionId = Get-AzSubscriptionId"
620+ $SubscriptionIdCommand = ' Get-AzSubscriptionId'
620621 }
621622 if ($PowerShellCodeGen [' CustomAuthCommand' ]) {
622- $authFunctionCall = $PowerShellCodeGen [' CustomAuthCommand' ]
623+ $AuthenticationCommand = $PowerShellCodeGen [' CustomAuthCommand' ]
623624 }
624625 if ($PowerShellCodeGen [' HostOverrideCommand' ]) {
625626 $hostOverrideCommand = $PowerShellCodeGen [' HostOverrideCommand' ]
626- $overrideBaseUriBlock = $executionContext.InvokeCommand.ExpandString ($HostOverrideBlock )
627627 }
628628 # If the auth function hasn't been set by metadata, try to discover it from the security and securityDefinition objects in the spec
629- if (-not $authFunctionCall ) {
629+ if (-not $AuthenticationCommand ) {
630630 if ($FunctionDetails.ContainsKey (' Security' )) {
631631 # For now, just take the first security object
632632 if ($FunctionDetails.Security.Count -gt 1 ) {
@@ -674,11 +674,12 @@ function New-SwaggerPath
674674 }
675675 # If the service is specified to not issue authentication challenges, we can't rely on HttpClientHandler
676676 if ($PowerShellCodeGen [' NoAuthChallenge' ] -and ($PowerShellCodeGen [' NoAuthChallenge' ] -eq $true )) {
677- $authFunctionCall = ' Get-AutoRestCredential -Credential $Credential'
677+ $AuthenticationCommand = ' param([pscredential]$Credential) Get-AutoRestCredential -Credential $Credential'
678+ $AuthenticationCommandArgumentName = ' Credential'
678679 } else {
679680 # Use an empty service client credentials object because we're using HttpClientHandler instead
680- $authFunctionCall = ' Get-AutoRestCredential'
681- $httpClientHandlerCall = ' $httpClientHandler = New-HttpClientHandler -Credential $Credential '
681+ $AuthenticationCommand = ' Get-AutoRestCredential'
682+ $AddHttpClientHandler = $true
682683 }
683684 } elseif ($type -eq ' apiKey' ) {
684685 if (-not (Get-Member - InputObject $securityDefinition - Name ' name' )) {
@@ -712,22 +713,18 @@ function New-SwaggerPath
712713 Parameter = $credentialParameter
713714 IsConflictingWithOperationParameter = $false
714715 }
715- $authFunctionCall = " Get-AutoRestCredential -APIKey `$ APIKey -Location '$in ' -Name '$name '"
716+ $AuthenticationCommand = " param([string]`$ APIKey) Get-AutoRestCredential -APIKey `$ APIKey -Location '$in ' -Name '$name '"
717+ $AuthenticationCommandArgumentName = ' APIKey'
716718 } else {
717719 Write-Warning - Message ($LocalizedData.UnsupportedAuthenticationType -f ($type ))
718720 }
719721 }
720722 }
721723 }
722724
723- if (-not $authFunctionCall ) {
725+ if (-not $AuthenticationCommand ) {
724726 # At this point, there was no supported security object or overridden auth function, so assume no auth
725- $authFunctionCall = ' Get-AutoRestCredential'
726- }
727-
728- $clientArgumentList = $clientArgumentListNoHandler
729- if ($httpClientHandlerCall ) {
730- $clientArgumentList = $clientArgumentListHttpClientHandler
727+ $AuthenticationCommand = ' Get-AutoRestCredential'
731728 }
732729
733730 $nonUniqueParameterSets = @ ()
@@ -961,18 +958,22 @@ function New-SwaggerPath
961958 }
962959
963960 $functionBodyParams = @ {
964- ParameterSetDetails = $parameterSetDetails
965- ODataExpressionBlock = $oDataExpressionBlock
966- ParameterGroupsExpressionBlock = $parameterGroupsExpressionBlock
967- GlobalParameterBlock = $GlobalParameterBlock
968- SwaggerDict = $SwaggerDict
969- SwaggerMetaDict = $SwaggerMetaDict
970- SecurityBlock = $executionContext.InvokeCommand.ExpandString ($securityBlockStr )
971- OverrideBaseUriBlock = $overrideBaseUriBlock
972- ClientArgumentList = $clientArgumentList
973- FlattenedParametersOnPSCmdlet = $flattenedParametersOnPSCmdlet
974- }
975-
961+ ParameterSetDetails = $parameterSetDetails
962+ ODataExpressionBlock = $oDataExpressionBlock
963+ ParameterGroupsExpressionBlock = $parameterGroupsExpressionBlock
964+ SwaggerDict = $SwaggerDict
965+ SwaggerMetaDict = $SwaggerMetaDict
966+ AddHttpClientHandler = $AddHttpClientHandler
967+ HostOverrideCommand = $hostOverrideCommand
968+ AuthenticationCommand = $AuthenticationCommand
969+ AuthenticationCommandArgumentName = $AuthenticationCommandArgumentName
970+ SubscriptionIdCommand = $SubscriptionIdCommand
971+ FlattenedParametersOnPSCmdlet = $flattenedParametersOnPSCmdlet
972+ }
973+ if ($globalParameters ) {
974+ $functionBodyParams [' GlobalParameters' ] = $globalParameters
975+ }
976+
976977 $pathGenerationPhaseResult = Get-PathFunctionBody @functionBodyParams
977978 $bodyObject = $pathGenerationPhaseResult.BodyObject
978979
0 commit comments