Skip to content

fix: preserve parameter declarations for names containing digits in generated README examples #405

Open

Description

Description

Running avm pre-commit with Avm.Authoring 1.2.0 generates invalid Bicep parameters-file syntax in module README examples when a parameter name contains a digit.

Observed in Azure/bicep-registry-modules, module avm/res/machine-learning-services/workspace: the v1LegacyMode parameter in the max example is rendered as v1LegacyMode: false instead of param v1LegacyMode = false. Manually correcting the README is overwritten on regeneration.

Reproduction

The installed generator can be exercised directly in PowerShell:

Import-Module Avm.Authoring -RequiredVersion 1.2.0
& (Get-Module Avm.Authoring) {
    $result = ConvertTo-AvmBicepDocsExampleParameter -Parameters ([ordered]@{
        legacyMode = @{ value = $false }
        v1LegacyMode = @{ value = $false }
    })
    $result.BicepParameterFile
}

Verified output:

param legacyMode = false
v1LegacyMode: false

Expected behavior

param legacyMode = false
param v1LegacyMode = false

Root cause and suggested fix

In src/Avm.Authoring/Private/Docs/ConvertTo-AvmBicepDocsExampleParameter.ps1, the property-to-parameter conversion uses:

$text = $line -creplace '^ {4}([a-zA-Z]*):(.*)$', 'param $1 =$2'

The name capture only accepts letters, so names containing digits (or underscores) bypass conversion. The subsequent indentation removal leaves the original property declaration in the parameters-file example.

Match valid Bicep identifiers instead, for example:

$text = $line -creplace '^ {4}([A-Za-z_][A-Za-z0-9_]*):(.*)$', 'param $1 =$2'

Add regression cases in tests/Pester/Unit/Private/Docs/ConvertTo-AvmBicepDocsExampleParameter.Tests.ps1 for names containing digits and underscores, retaining coverage that nested object properties are not converted into parameter declarations.

Environment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions