diff --git a/src/PSDocs.Azure/docs/Azure.Template.Doc.ps1 b/src/PSDocs.Azure/docs/Azure.Template.Doc.ps1 index b449c2f3..2ef22e9f 100644 --- a/src/PSDocs.Azure/docs/Azure.Template.Doc.ps1 +++ b/src/PSDocs.Azure/docs/Azure.Template.Doc.ps1 @@ -218,17 +218,60 @@ function global:GetTemplateOutput { foreach ($property in $InputObject.outputs.PSObject.Properties) { $output = [PSCustomObject]@{ Name = $property.Name - Type = $property.Value.type + Type = If ($null -eq $property.Value.'$ref') {$property.Value.type} Else {GetDefinitionReferenceMarkdownLink $property.Value.'$ref'} Description = '' } if ([bool]$property.Value.PSObject.Properties['metadata'] -and [bool]$property.Value.metadata.PSObject.Properties['description']) { + $output.Description = $property.Value.metadata.description + } $output; } } } +# A function to import user-defined types +function global:GetTemplateDefinition { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $True, ValueFromPipeline = $True)] + [PSObject]$InputObject + ) + process { + foreach ($property in $InputObject.definitions.PSObject.Properties) { + $definition = [PSCustomObject]@{ + Name = $property.Name + Properties = $property.PSObject.Properties + Description = '' + AdditionalProperties = $false + Discriminator = $null + } + if ([bool]$property.Value.PSObject.Properties['metadata'] -and [bool]$property.Value.metadata.PSObject.Properties['description']) { + $definition.Description = $property.Value.metadata.description + } + if($null -ne $property.Value.PSObject.Properties['additionalProperties'] -and $property.Value.PSObject.Properties['additionalProperties'] -ne $false) { + $definition.AdditionalProperties = $property.Value.additionalProperties; + } + if($null -ne $property.Value.PSObject.Properties['discriminator']) { + $definition.Discriminator = $property.Value.discriminator; + } + $definition; + } + } +} + +function global:GetDefinitionReferenceMarkdownLink { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $True)] + [String]$DefinitionPath + ) + process { + return "[$($DefinitionPath)](#$($DefinitionPath.Split('/')[-1].ToLower().Replace(' ', '-')))" + } +} + # Synopsis: A definition to generate markdown for an ARM template Document 'README' -With 'Azure.TemplateSchema' { @@ -250,6 +293,8 @@ Document 'README' -With 'Azure.TemplateSchema' { $parameters = $template | GetTemplateParameter; $metadata = $template | GetTemplateMetadata -Path $templatePath; $outputs = $template | GetTemplateOutput; + $definitions = $template | GetTemplateDefinition; + # Set document title if ($Null -ne $metadata -and $metadata.ContainsKey('name')) { @@ -298,6 +343,48 @@ Document 'README' -With 'Azure.TemplateSchema' { $metadata.details } } + Section $LocalizedData.Definitions { + foreach($definition in $definitions) { + Section $definition.Name { + + $definition.Description; + + $definitionProperties = $definition.Properties.Value.Properties; + if($null -ne $definitionProperties -and $definitionProperties.Count -gt 0) { + $definitionProperties.PSObject.Properties | Table -Property @{ Name = $LocalizedData.PropertyName; Expression = { $_.Name }}, + @{ Name = $LocalizedData.Type; Expression = { + If($null -eq $_.Value.'$ref') { $_.Value.Type } Else { GetDefinitionReferenceMarkdownLink $_.Value.'$ref' } + }}, + @{ Name = $LocalizedData.Nullable; Expression = { If($null -ne $_.Value.nullable) { $_.Value.nullable } Else { 'False' }}}, + @{ Name = $LocalizedData.Description; Expression = { If($null -ne $_.Value.Metadata.Description) { $_.Value.Metadata.Description } Else { '' }}}, + @{ Name= $LocalizedData.AllowedValues; Expression = { + If($null -eq $_.Value.allowedValues) { 'Any' } Else { + $_.Value.allowedValues -join ' | ' # | = Pipe symbol = | + } + }} + } + + if ($null -ne $definition.AdditionalProperties -and $definition.AdditionalProperties -ne $false) { + "**$($LocalizedData.AdditionalProperties)**" + If($null -eq $definition.AdditionalProperties.'$ref') {$definition.AdditionalProperties.type} Else {$(global:GetDefinitionReferenceMarkdownLink $definition.AdditionalProperties.'$ref')} + } + + if($null -ne $definition.Discriminator) { + Section $LocalizedData.UnionTypes { + "**$($LocalizedData.DiscriminatorDescription)**" + $definition.Discriminator.propertyName | Code 'text' + + if($null -ne $definition.Discriminator.mapping) { + "**$($LocalizedData.Mapping)**" + $definition.Discriminator.mapping.PSObject.Properties | Table -Property @{ Name = $LocalizedData.Type; Expression = { $_.Name }}, + @{ Name = $LocalizedData.Definition; Expression = { GetDefinitionReferenceMarkdownLink $_.Value.'$ref' }} + } + + } + } + } + } + } # Add table and detail for each parameter Section $LocalizedData.Parameters { diff --git a/src/PSDocs.Azure/en/PSDocs-strings.psd1 b/src/PSDocs.Azure/en/PSDocs-strings.psd1 index 2a15d023..52b6a977 100644 --- a/src/PSDocs.Azure/en/PSDocs-strings.psd1 +++ b/src/PSDocs.Azure/en/PSDocs-strings.psd1 @@ -3,13 +3,20 @@ @{ Parameters = 'Parameters' + Definitions = 'User-defined types definitions' Snippets = 'Snippets' Outputs = 'Outputs' DefaultValue = 'Default value' AllowedValues = 'Allowed values' + AdditionalProperties = 'Additional properties' + PropertyName = 'Property name' ParameterName = 'Parameter name' Description = 'Description' Type = 'Type' + Definition = 'Definition' + UnionTypes = 'Union types' + DiscriminatorDescription = 'Property used to discriminate between types' + Mapping = 'Mapping' Name = 'Name' DefaultTitle = 'Azure template' ParameterFile = 'Parameter file' @@ -21,4 +28,5 @@ MaxValue = 'Maximum value' MinLength = 'Minimum length' MaxLength = 'Maximum length' + Nullable = 'Nullable' }