Skip to content
Open
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
89 changes: 88 additions & 1 deletion src/PSDocs.Azure/docs/Azure.Template.Doc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {

Expand All @@ -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')) {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/PSDocs.Azure/en/PSDocs-strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -21,4 +28,5 @@
MaxValue = 'Maximum value'
MinLength = 'Minimum length'
MaxLength = 'Maximum length'
Nullable = 'Nullable'
}