@@ -15,12 +15,22 @@ function global:GetTemplateParameter {
1515 process {
1616 $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
1717 foreach ($property in $template.parameters.PSObject.Properties ) {
18- [PSCustomObject ]@ {
18+ $result = [PSCustomObject ]@ {
1919 Name = $property.Name
20- Description = $property .Value.metadata.description
21- DefaultValue = $property .Value.defaultValue
22- AllowedValues = $property .Value.allowedValues
20+ Description = ' '
21+ DefaultValue = $Null
22+ AllowedValues = $Null
2323 }
24+ if ([bool ]$property.Value.PSObject.Properties [' metadata' ] -and [bool ]$property.Value.metadata.PSObject.Properties [' description' ]) {
25+ $result.Description = $property.Value.metadata.description ;
26+ }
27+ if ([bool ]$property.Value.PSObject.Properties [' defaultValue' ]) {
28+ $result.DefaultValue = $property.Value.defaultValue ;
29+ }
30+ if ([bool ]$property.Value.PSObject.Properties [' allowedValues' ]) {
31+ $result.AllowedValues = $property.Value.allowedValues ;
32+ }
33+ $result ;
2434 }
2535 }
2636}
@@ -52,8 +62,9 @@ function global:GetTemplateExample {
5262 }
5363 foreach ($property in $template.parameters.PSObject.Properties ) {
5464 $propertyValue = $Null ;
65+ $hasMetadata = [bool ]$property.Value.PSObject.Properties [' metadata' ];
5566
56- if ($True -eq $property.Value.metadata.ignore ) {
67+ if ($hasMetadata -and [ bool ] $property .Value.metadata.PSObject.Properties [ ' ignore ' ] -and $ True -eq $property.Value.metadata.ignore ) {
5768 continue ;
5869 }
5970
@@ -70,10 +81,10 @@ function global:GetTemplateExample {
7081 continue ;
7182 }
7283
73- if ($Null -ne $property.Value.metadata.example ) {
84+ if ($hasMetadata -and [ bool ] $property .Value.metadata.PSObject.Properties [ ' example ' ] -and $ Null -ne $property.Value.metadata.example ) {
7485 $propertyValue = $property.Value.metadata.example ;
7586 }
76- elseif ($Null -ne $property.Value.defaultValue ) {
87+ elseif ([ bool ] $property .Value.PSObject.Properties [ ' defaultValue ' ] -and $Null -ne $property.Value.defaultValue ) {
7788 $propertyValue = $property.Value.defaultValue ;
7889 }
7990 elseif ($property.Value.type -eq ' array' ) {
@@ -106,7 +117,33 @@ function global:GetTemplateMetadata {
106117 [String ]$Path
107118 )
108119 process {
109- return (Get-Content - Path $Path - Raw | ConvertFrom-Json ).metadata;
120+ $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
121+ if ([bool ]$template.PSObject.Properties [' metadata' ]) {
122+ return $template.metadata ;
123+ }
124+ }
125+ }
126+
127+ # A function to import outputs
128+ function global :GetTemplateOutput {
129+ [CmdletBinding ()]
130+ param (
131+ [Parameter (Mandatory = $True )]
132+ [String ]$Path
133+ )
134+ process {
135+ $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
136+ foreach ($property in $template.outputs.PSObject.Properties ) {
137+ $output = [PSCustomObject ]@ {
138+ Name = $property.Name
139+ Type = $property.Value.type
140+ Description = ' '
141+ }
142+ if ([bool ]$property.Value.PSObject.Properties [' metadata' ] -and [bool ]$property.Value.metadata.PSObject.Properties [' description' ]) {
143+ $output.Description = $property.Value.metadata.description
144+ }
145+ $output ;
146+ }
110147 }
111148}
112149
@@ -117,16 +154,25 @@ Document 'README' {
117154 $templatePath = $InputObject ;
118155 $parameters = GetTemplateParameter - Path $templatePath ;
119156 $metadata = GetTemplateMetadata - Path $templatePath ;
157+ $outputs = GetTemplateOutput - Path $templatePath ;
120158
121159 # Set document title
122- Title $metadata.name
160+ if ($Null -ne $metadata -and [bool ]$metadata.PSObject.Properties [' name' ]) {
161+ Title $metadata.name
162+ }
163+ else {
164+ Title $LocalizedData.DefaultTitle
165+ }
123166
124167 # Write opening line
125- $metadata.Description
168+ if ($Null -ne $metadata -and [bool ]$metadata.PSObject.Properties [' description' ]) {
169+ $metadata.description
170+ }
126171
127- # Add each parameter to a table
172+ # Add table and detail for each parameter
128173 Section $LocalizedData.Parameters {
129- $parameters | Table - Property @ { Name = $LocalizedData.ParameterName ; Expression = { $_.Name }}, $LocalizedData.Description
174+ $parameters | Table - Property @ { Name = $LocalizedData.ParameterName ; Expression = { $_.Name }},
175+ @ { Name = $LocalizedData.Description ; Expression = { $_.Description }}
130176
131177 foreach ($parameter in $parameters ) {
132178 Section $parameter.Name {
@@ -145,6 +191,14 @@ Document 'README' {
145191 }
146192 }
147193
194+ # Add table for outputs
195+ Section $LocalizedData.Outputs {
196+ $outputs | Table - Property @ { Name = $LocalizedData.Name ; Expression = { $_.Name }},
197+ @ { Name = $LocalizedData.Type ; Expression = { $_.Type }},
198+ @ { Name = $LocalizedData.Description ; Expression = { $_.Description }}
199+ }
200+
201+ # Insert snippet
148202 $example = GetTemplateExample - Path $templatePath ;
149203 Section $LocalizedData.Snippets {
150204 $example | Code ' json'
0 commit comments