diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 2f11c50319..2a097d2015 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -166,7 +166,7 @@ function Set-ParametersSection { # 2. Create header including optional columns $newSectionContent += @( ('**{0} parameters**' -f $category), - (''), + '', ('| Parameter Name | Type | {0}{1}Description |' -f ($hasDefault ? 'Default Value | ' : ''), ($hasAllowed ? 'Allowed Values | ' : '')), ('| :-- | :-- | {0}{1}:-- |' -f ($hasDefault ? ':-- | ' : ''), ($hasAllowed ? ':-- | ' : '')) ) @@ -650,6 +650,11 @@ function ConvertTo-FormattedJSONParameterObject { [string] $BicepParamBlock ) + if ([String]::IsNullOrEmpty($BicepParamBlock)) { + # Case: No mandatory parameters + return @{} + } + # [1/4] Detect top level params for later processing $bicepParamBlockArray = $BicepParamBlock -split '\n' $topLevelParamIndent = ([regex]::Match($bicepParamBlockArray[0], '^(\s+).*')).Captures.Groups[1].Value.Length @@ -966,8 +971,14 @@ function Set-DeploymentExamplesSection { $rawBicepExampleArray = $rawBicepExample -split '\n' $moduleDeploymentPropertyIndent = ([regex]::Match($rawBicepExampleArray[1], '^(\s+).*')).Captures.Groups[1].Value.Length $paramsStartIndex = ($rawBicepExampleArray | Select-String ("^[\s]{$moduleDeploymentPropertyIndent}params:[\s]*\{") | ForEach-Object { $_.LineNumber - 1 })[0] + 1 - $paramsEndIndex = ($rawBicepExampleArray[($paramsStartIndex + 1)..($rawBicepExampleArray.Count)] | Select-String "^[\s]{$moduleDeploymentPropertyIndent}\}" | ForEach-Object { $_.LineNumber - 1 })[0] + $paramsStartIndex - $paramBlock = ($rawBicepExampleArray[$paramsStartIndex..$paramsEndIndex] | Out-String).TrimEnd() + if ($rawBicepExampleArray[$paramsStartIndex].Trim() -ne '}') { + # Handle case where param block is empty + $paramsEndIndex = ($rawBicepExampleArray[($paramsStartIndex + 1)..($rawBicepExampleArray.Count)] | Select-String "^[\s]{$moduleDeploymentPropertyIndent}\}" | ForEach-Object { $_.LineNumber - 1 })[0] + $paramsStartIndex + $paramBlock = ($rawBicepExampleArray[$paramsStartIndex..$paramsEndIndex] | Out-String).TrimEnd() + } else { + $paramBlock = '' + $paramsEndIndex = $paramsStartIndex + } # [5/6] Convert Bicep parameter block to JSON parameter block to enable processing $conversionInputObject = @{ @@ -987,7 +998,12 @@ function Set-DeploymentExamplesSection { # --------------------- # if ($addBicep) { - $formattedBicepExample = $rawBicepExample[0..($paramsStartIndex - 1)] + ($bicepExample -split '\n') + $rawBicepExample[($paramsEndIndex + 1)..($rawBicepExample.Count)] + if ([String]::IsNullOrEmpty($paramBlock)) { + # Handle case where param block is empty + $formattedBicepExample = $rawBicepExample[0..($paramsStartIndex - 1)] + $rawBicepExample[($paramsEndIndex)..($rawBicepExample.Count)] + } else { + $formattedBicepExample = $rawBicepExample[0..($paramsStartIndex - 1)] + ($bicepExample -split '\n') + $rawBicepExample[($paramsEndIndex + 1)..($rawBicepExample.Count)] + } $SectionContent += @( '',