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
3 changes: 3 additions & 0 deletions PSSwagger/Definitions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function Get-SwaggerSpecDefinitionInfo

$FunctionDetails['Name'] = $Name
$FunctionDetails['Description'] = $FunctionDescription
# Definition doesn't have Summary property, so using specifying Description as Function Synopsis.
$FunctionDetails['Synopsis'] = $FunctionDescription
$FunctionDetails['ParametersTable'] = $ParametersTable
$FunctionDetails['x_ms_Client_flatten_DefinitionNames'] = $x_ms_Client_flatten_DefinitionNames
$FunctionDetails['AllOf_DefinitionNames'] = $AllOf_DefinitionNames
Expand Down Expand Up @@ -802,6 +804,7 @@ function New-SwaggerSpecDefinitionCommand
$commandName = "New-$($FunctionDetails.Name)Object"

$description = $FunctionDetails.description
$synopsis = $FunctionDetails.synopsis
$commandHelp = $executionContext.InvokeCommand.ExpandString($helpDescStr)

[string]$paramHelp = ""
Expand Down
3 changes: 3 additions & 0 deletions PSSwagger/PSSwagger.Constants.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#########################################################################################

$helpDescStr = @'
.SYNOPSIS
$synopsis

.DESCRIPTION
$description
'@
Expand Down
24 changes: 17 additions & 7 deletions PSSwagger/Paths.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function Get-SwaggerSpecPathInfo
if((Get-Member -InputObject $_.value -Name 'description') -and $_.value.description) {
$FunctionDescription = $_.value.description
}

$FunctionSynopsis = ''
if((Get-Member -InputObject $_.value -Name 'Summary') -and $_.value.Summary) {
$FunctionSynopsis = $_.value.Summary
}

$ParametersTable = @{}
# Add Path common parameters to the operation's parameters list.
Expand Down Expand Up @@ -193,15 +198,16 @@ function Get-SwaggerSpecPathInfo
}

$ParameterSetDetail = @{
Description = $FunctionDescription
ParameterDetails = $ParametersTable
Responses = $responses
OperationId = $operationId
OperationType = $operationType
Description = $FunctionDescription
Synopsis = $FunctionSynopsis
ParameterDetails = $ParametersTable
Responses = $responses
OperationId = $operationId
OperationType = $operationType
EndpointRelativePath = $EndpointRelativePath
PathCommonParameters = $PathCommonParameters
Priority = 100 # Default
'x-ms-pageable' = $x_ms_pageableObject
Priority = 100 # Default
'x-ms-pageable' = $x_ms_pageableObject
}

if ((Get-Member -InputObject $_.Value -Name 'x-ms-odata') -and $_.Value.'x-ms-odata') {
Expand Down Expand Up @@ -420,6 +426,7 @@ function New-SwaggerPath
$UseAzureCsharpGenerator = $SwaggerMetaDict['UseAzureCsharpGenerator']

$description = ''
$synopsis = ''
$paramBlock = ''
$paramHelp = ''
$parametersToAdd = @{}
Expand Down Expand Up @@ -827,16 +834,19 @@ function New-SwaggerPath
$defaultParameterSet = $nonUniqueParameterSets | Sort-Object -Property Priority | Select-Object -First 1
$DefaultParameterSetName = $defaultParameterSet.OperationId
$description = $defaultParameterSet.Description
$synopsis = $defaultParameterSet.Synopsis
Write-Warning -Message ($LocalizedData.CmdletHasAmbiguousParameterSets -f ($commandName))
} elseif ($nonUniqueParameterSets.Length -eq 1) {
# If there's only one non-unique, we can prevent errors by making this the default
$DefaultParameterSetName = $nonUniqueParameterSets[0].OperationId
$description = $nonUniqueParameterSets[0].Description
$synopsis = $nonUniqueParameterSets[0].Synopsis
} else {
# Pick the highest priority set among all sets
$defaultParameterSet = $parameterSetDetails | Sort-Object @{e = {$_.Priority -as [int] }} | Select-Object -First 1
$DefaultParameterSetName = $defaultParameterSet.OperationId
$description = $defaultParameterSet.Description
$synopsis = $defaultParameterSet.Synopsis
}

$oDataExpression = ""
Expand Down
11 changes: 11 additions & 0 deletions Tests/PSSwaggerScenario.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ Describe "ParameterTypes tests" -Tag @('ParameterTypes','ScenarioTest') {
$CommandList.Name -CContains $_ | Should be $True
}
}

It "Test 'Synopsis' and 'Description' help contents of generated commands" {
$HelpInfo1 = Get-Help -Name 'Get-Cupcake'
$HelpInfo1.Description.Text | Should BeExactly 'Make a cupcake or update an existing one.'
$HelpInfo1.Synopsis | Should BeExactly 'List all cupcakes matching parameters'

$HelpInfo2 = Get-Help -Name 'New-DefWithDummyRefObject'
$ExpectedText = 'The workflow properties.'
$HelpInfo2.Description.Text | Should BeExactly $ExpectedText
$HelpInfo2.Synopsis | Should BeExactly $ExpectedText
}
}

AfterAll {
Expand Down