Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions PSSwagger/Paths.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1288,7 +1295,7 @@ function Convert-GenericTypeToString {
)

if (-not $Type.IsGenericType) {
return $Type.FullName.Trim('[]')
return $Type.FullName
}

$genericTypeStr = ''
Expand Down
2 changes: 1 addition & 1 deletion Tests/PSSwagger.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down