99function global :GetTemplateParameter {
1010 [CmdletBinding ()]
1111 param (
12- [Parameter (Mandatory = $True )]
13- [String ] $Path
12+ [Parameter (Mandatory = $True , ValueFromPipeline = $True )]
13+ [PSObject ] $InputObject
1414 )
1515 process {
16- $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
17- foreach ($property in $template.parameters.PSObject.Properties ) {
16+ foreach ($property in $InputObject.parameters.PSObject.Properties ) {
1817 $result = [PSCustomObject ]@ {
1918 Name = $property.Name
2019 Description = ' '
@@ -27,7 +26,7 @@ function global:GetTemplateParameter {
2726 }
2827 if ([bool ]$property.Value.PSObject.Properties [' defaultValue' ]) {
2928 $result.DefaultValue = $property.Value.defaultValue ;
30- $result.Required = " Optional"
29+ $result.Required = ' Optional'
3130 }
3231 if ([bool ]$property.Value.PSObject.Properties [' allowedValues' ]) {
3332 $result.AllowedValues = $property.Value.allowedValues ;
@@ -49,7 +48,8 @@ function global:GetTemplateExample {
4948 $Path = Join-Path - Path $PWD - ChildPath $Path ;
5049 }
5150 $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
52- $normalPath = GetTemplateRelativePath - Path $Path ;
51+ # $normalPath = GetTemplateRelativePath -Path $Path;
52+ $normalPath = $PSDocs.Source.Path ;
5353 $baseContent = [PSCustomObject ]@ {
5454 ' $schema' = " https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json`#"
5555 contentVersion = ' 1.0.0.0'
@@ -133,16 +133,18 @@ function global:GetTemplateMetadata {
133133 [CmdletBinding ()]
134134 [OutputType ([Hashtable ])]
135135 param (
136+ [Parameter (Mandatory = $True , ValueFromPipeline = $True )]
137+ [PSObject ]$InputObject ,
138+
136139 [Parameter (Mandatory = $True )]
137140 [String ]$Path
138141 )
139142 process {
140143 $metadata = @ {};
141144
142145 # Get metadata from template file
143- $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
144- if ([bool ]$template.PSObject.Properties [' metadata' ]) {
145- foreach ($property in $template.metadata.PSObject.Properties.GetEnumerator ()) {
146+ if ([bool ]$InputObject.PSObject.Properties [' metadata' ]) {
147+ foreach ($property in $InputObject.metadata.PSObject.Properties.GetEnumerator ()) {
146148 $metadata [$property.Name ] = $property.Value ;
147149 }
148150 }
@@ -175,12 +177,11 @@ function global:GetTemplateMetadata {
175177function global :GetTemplateOutput {
176178 [CmdletBinding ()]
177179 param (
178- [Parameter (Mandatory = $True )]
179- [String ] $Path
180+ [Parameter (Mandatory = $True , ValueFromPipeline = $True )]
181+ [PSObject ] $InputObject
180182 )
181183 process {
182- $template = Get-Content - Path $Path - Raw | ConvertFrom-Json ;
183- foreach ($property in $template.outputs.PSObject.Properties ) {
184+ foreach ($property in $InputObject.outputs.PSObject.Properties ) {
184185 $output = [PSCustomObject ]@ {
185186 Name = $property.Name
186187 Type = $property.Value.type
@@ -195,13 +196,26 @@ function global:GetTemplateOutput {
195196}
196197
197198# Synopsis: A definition to generate markdown for an ARM template
198- Document ' README' {
199+ Document ' README' - With ' Azure.TemplateSchema' {
200+
201+ $templatePath = $PSDocs.Source.FullName ;
202+ $template = $PSDocs.TargetObject ;
203+ if ($PSDocs.TargetObject -is [String ]) {
204+ $templatePath = (Get-Item - Path $PSDocs.TargetObject ).FullName;
205+ $template = Get-Content - Path $templatePath - Raw | ConvertFrom-Json ;
206+ $relativePath = (Split-Path (GetTemplateRelativePath - Path $templatePath ) - Parent).Replace(' \' , ' /' ).TrimStart(' /' );
207+ }
208+ else {
209+ $relativePath = Split-Path - Path $PSDocs.Source.Path - Parent;
210+ }
211+
212+ Write-Verbose - Message " Reading from template: $templatePath "
213+ Write-Verbose - Message " Reading from template: $relativePath "
199214
200215 # Read JSON files
201- $templatePath = $InputObject ;
202- $parameters = GetTemplateParameter - Path $templatePath ;
203- $metadata = GetTemplateMetadata - Path $templatePath ;
204- $outputs = GetTemplateOutput - Path $templatePath ;
216+ $parameters = $template | GetTemplateParameter;
217+ $metadata = $template | GetTemplateMetadata - Path $templatePath ;
218+ $outputs = $template | GetTemplateOutput;
205219
206220 # Set document title
207221 if ($Null -ne $metadata -and $metadata.ContainsKey (' name' )) {
@@ -217,15 +231,14 @@ Document 'README' {
217231 }
218232
219233 # Add badges
220- $relativePath = (Split-Path (GetTemplateRelativePath - Path $templatePath ) - Parent).Replace(' \' , ' /' ).TrimStart(' /' );
221234 $relativePathEncoded = [System.Web.HttpUtility ]::UrlEncode($relativePath );
222235 Include ' .ps-docs/azure-template-badges.md' - ErrorAction SilentlyContinue - BaseDirectory $PWD -Replace @ {
223236 ' {{ template_path }}' = $relativePath
224237 ' {{ template_path_encoded }}' = $relativePathEncoded
225238 }
226239
227- Write-Verbose $relativePath
228- Write-Verbose $relativePathEncoded
240+ # Write-Verbose $relativePath
241+ # Write-Verbose $relativePathEncoded
229242
230243 # Add detailed description
231244 if ($Null -ne $metadata -and $metadata.ContainsKey (' description' )) {
@@ -234,24 +247,24 @@ Document 'README' {
234247
235248 # Add table and detail for each parameter
236249 Section $LocalizedData.Parameters {
237- $parameters | Table - Property @ { Name = $LocalizedData.ParameterName ; Expression = { $_.Name }},
238- @ { Name = $LocalizedData.Required ; Expression = {
250+ $parameters | Table - Property @ { Name = $LocalizedData.ParameterName ; Expression = { $_.Name }},
251+ @ { Name = $LocalizedData.Required ; Expression = {
239252 if ($_.Required ) {
240253 $LocalizedData.RequiredNo
241- }
254+ }
242255 else {
243256 $LocalizedData.RequiredYes
244- }
257+ }
245258 }
246- },
259+ },
247260 @ { Name = $LocalizedData.Description ; Expression = { $_.Description }}
248261
249262 foreach ($parameter in $parameters ) {
250263 Section $parameter.Name {
251264 if ($parameter.Required ){
252265 " "
253266 }
254- else { " " }
267+ else { " " }
255268 $parameter.Description ;
256269
257270 if (! [String ]::IsNullOrEmpty($parameter.DefaultValue )) {
0 commit comments