From 2550c90a64376c0ff9edf50f5a472f3540f4ea0c Mon Sep 17 00:00:00 2001 From: MrMCake Date: Mon, 26 Sep 2022 09:20:50 +0200 Subject: [PATCH 1/4] Enabled no-param blocks --- utilities/tools/Set-ModuleReadMe.ps1 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 2f11c50319..4850cd4c97 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -166,7 +166,6 @@ 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 +649,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 +970,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 + 1)].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 +997,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 += @( '', From 9be0c892257b55cb71ffed927877b278c59bdaac Mon Sep 17 00:00:00 2001 From: MrMCake Date: Mon, 26 Sep 2022 09:22:58 +0200 Subject: [PATCH 2/4] Update to latest --- utilities/tools/Set-ModuleReadMe.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 4850cd4c97..4edc3d24fd 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -166,6 +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 ? ':-- | ' : '')) ) From ee130bf43b836468f48e9414c903e47501ae7652 Mon Sep 17 00:00:00 2001 From: Erika Gressi Date: Tue, 27 Sep 2022 18:44:06 +0200 Subject: [PATCH 3/4] regenerated readmes --- modules/Microsoft.KeyVault/vaults/readme.md | 6 +----- modules/Microsoft.Resources/resourceGroups/readme.md | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/modules/Microsoft.KeyVault/vaults/readme.md b/modules/Microsoft.KeyVault/vaults/readme.md index d3b2e45a79..8446624d0e 100644 --- a/modules/Microsoft.KeyVault/vaults/readme.md +++ b/modules/Microsoft.KeyVault/vaults/readme.md @@ -692,11 +692,7 @@ module vaults './Microsoft.KeyVault/vaults/deploy.bicep' = { { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>kvvmin001" - } - } + "parameters": {} } ``` diff --git a/modules/Microsoft.Resources/resourceGroups/readme.md b/modules/Microsoft.Resources/resourceGroups/readme.md index 056ed6fef7..70fe5ffc51 100644 --- a/modules/Microsoft.Resources/resourceGroups/readme.md +++ b/modules/Microsoft.Resources/resourceGroups/readme.md @@ -262,11 +262,7 @@ module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = { { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>rrgmin001" - } - } + "parameters": {} } ``` From 2096b394d3f0b4f00d64f04ee3098438a23df506 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Tue, 27 Sep 2022 19:17:32 +0200 Subject: [PATCH 4/4] Small fix --- modules/Microsoft.KeyVault/vaults/readme.md | 6 +++++- modules/Microsoft.Resources/resourceGroups/readme.md | 6 +++++- utilities/tools/Set-ModuleReadMe.ps1 | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/Microsoft.KeyVault/vaults/readme.md b/modules/Microsoft.KeyVault/vaults/readme.md index 8446624d0e..d3b2e45a79 100644 --- a/modules/Microsoft.KeyVault/vaults/readme.md +++ b/modules/Microsoft.KeyVault/vaults/readme.md @@ -692,7 +692,11 @@ module vaults './Microsoft.KeyVault/vaults/deploy.bicep' = { { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", - "parameters": {} + "parameters": { + "name": { + "value": "<>kvvmin001" + } + } } ``` diff --git a/modules/Microsoft.Resources/resourceGroups/readme.md b/modules/Microsoft.Resources/resourceGroups/readme.md index 70fe5ffc51..056ed6fef7 100644 --- a/modules/Microsoft.Resources/resourceGroups/readme.md +++ b/modules/Microsoft.Resources/resourceGroups/readme.md @@ -262,7 +262,11 @@ module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = { { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", - "parameters": {} + "parameters": { + "name": { + "value": "<>rrgmin001" + } + } } ``` diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 4edc3d24fd..2a097d2015 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -971,7 +971,7 @@ 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 - if ($rawBicepExampleArray[($paramsStartIndex + 1)].Trim() -ne '}') { + 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()