diff --git a/PSSwagger/Paths.psm1 b/PSSwagger/Paths.psm1 index 208a82d..ec3e18a 100644 --- a/PSSwagger/Paths.psm1 +++ b/PSSwagger/Paths.psm1 @@ -445,6 +445,9 @@ function New-SwaggerPath } elseif (-not $x_ms_pageableObject) { $x_ms_pageableObject = $parameterSetDetail.'x-ms-pageable' $x_ms_pageableObject['ReturnType'] = $parameterSetDetail.ReturnType + if($parameterSetDetail.ContainsKey('PSCmdletOutputItemType')) { + $x_ms_pageableObject['PSCmdletOutputItemType'] = $parameterSetDetail.PSCmdletOutputItemType + } if ($x_ms_pageableObject.Containskey('operationName')) { # Search for the cmdlet with a parameter set with the given operationName $pagingFunctionDetails = $PathFunctionDetails.GetEnumerator() | Where-Object { $_.Value.ParameterSetDetails | Where-Object { $_.OperationId -eq $x_ms_pageableObject.operationName }} | Select-Object -First 1 @@ -561,11 +564,15 @@ function New-SwaggerPath $Cmdlet = '' $CmdletParameter = '' $CmdletArgs = '' - $pageType = '' + $pageType = 'Array' + $PSCmdletOutputItemType = '' $resultBlockStr = $resultBlockNoPaging if ($x_ms_pageableObject) { if ($x_ms_pageableObject.ReturnType -ne 'NONE') { $pageType = $x_ms_pageableObject.ReturnType + if($x_ms_pageableObject.ContainsKey('PSCmdletOutputItemType')) { + $PSCmdletOutputItemType = $x_ms_pageableObject.PSCmdletOutputItemType + } } if ($x_ms_pageableObject.ContainsKey('Operations')) { @@ -994,8 +1001,8 @@ function New-SwaggerPath $bodyObject = $pathGenerationPhaseResult.BodyObject $body = $bodyObject.Body - if($pageType){ - $fullPathDataType = $pageType + if($PSCmdletOutputItemType){ + $fullPathDataType = $PSCmdletOutputItemType $outputTypeBlock = $executionContext.InvokeCommand.ExpandString($outputTypeStr) } else { @@ -1162,12 +1169,12 @@ function Set-ExtendedCodeMetadata { $returnType = $returnType.GenericTypeArguments[0] } + # Note: ReturnType and PSCmdletOutputItemType are currently used for Swagger operations which supports x-ms-pageable. if (($returnType.Name -eq 'IPage`1') -and $returnType.GenericTypeArguments) { - $returnType = $returnType.GenericTypeArguments[0] + $PSCmdletOutputItemTypeString = Convert-GenericTypeToString -Type $returnType.GenericTypeArguments[0] + $parameterSetDetail['PSCmdletOutputItemType'] = $PSCmdletOutputItemTypeString.Trim('[]') } - # Note: ReturnType is currently used for Swagger operations which supports x-ms-pageable. - $returnTypeString = Convert-GenericTypeToString -Type $returnType - $parameterSetDetail['ReturnType'] = $returnTypeString + $parameterSetDetail['ReturnType'] = Convert-GenericTypeToString -Type $returnType $ParamList = @() $oDataQueryFound = $false @@ -1288,7 +1295,7 @@ function Convert-GenericTypeToString { ) if (-not $Type.IsGenericType) { - return $Type.FullName.Trim('[]') + return $Type.FullName } $genericTypeStr = '' diff --git a/Tests/PSSwagger.Unit.Tests.ps1 b/Tests/PSSwagger.Unit.Tests.ps1 index da4aa69..8428b1f 100644 --- a/Tests/PSSwagger.Unit.Tests.ps1 +++ b/Tests/PSSwagger.Unit.Tests.ps1 @@ -287,7 +287,7 @@ Describe "PSSwagger Unit Tests" -Tag @('BVT', 'DRT', 'UnitTest', 'P0') { Convert-GenericTypeToString -Type ('System.Int32' -as [type]) | Should BeExactly 'System.Int32' } It "Convert-GenericTypeToString with 'System.String[]' type" { - Convert-GenericTypeToString -Type ('System.String[]' -as [type]) | Should BeExactly 'System.String' + Convert-GenericTypeToString -Type ('System.String[]' -as [type]) | Should BeExactly 'System.String[]' } It "Convert-GenericTypeToString with 'System.Collections.Generic.List[string]' type" { Convert-GenericTypeToString -Type ('System.Collections.Generic.List[string]' -as [type]) | Should BeExactly 'System.Collections.Generic.List[System.String]'