Skip to content

Commit

Permalink
Fix for issue #13558 (#13559)
Browse files Browse the repository at this point in the history
Closes #13558 Bicep generate-params
don't emit optional parameters with --include-params All flag
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13559)
  • Loading branch information
olegKoshmeliuk committed Mar 9, 2024
1 parent d7502b7 commit 96f8e27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
41 changes: 40 additions & 1 deletion src/Bicep.Cli.IntegrationTests/GenerateParamsCommandTests.cs
Expand Up @@ -91,7 +91,46 @@ public async Task GenerateParams_ImplicitOutputFormatJson_ExplicitIncludeParamsA
content.Should().Be(@"{
""$schema"": ""https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#"",
""contentVersion"": ""1.0.0.0"",
""parameters"": {}
""parameters"": {
""name"": {
""value"": """"
}
}
}".ReplaceLineEndings());
}
}

[TestMethod]
public async Task GenerateParams_ImplicitOutputFormatJson_ExplicitIncludeParamsAll_OneParameterWithDefaultValueAndOneRequiredParameter_Should_Succeed()
{
var bicep = $@"param optional string = 'sampleparameter'
param required string";

var tempDirectory = FileHelper.GetUniqueTestOutputPath(TestContext);
Directory.CreateDirectory(tempDirectory);

var bicepFilePath = Path.Combine(tempDirectory, "built.bicep");
File.WriteAllText(bicepFilePath, bicep);

var (output, error, result) = await Bicep("generate-params", "--include-params", "all", bicepFilePath);

var content = File.ReadAllText(Path.Combine(tempDirectory, "built.parameters.json")).ReplaceLineEndings();

using (new AssertionScope())
{
result.Should().Be(0);

content.Should().Be(@"{
""$schema"": ""https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#"",
""contentVersion"": ""1.0.0.0"",
""parameters"": {
""optional"": {
""value"": """"
},
""required"": {
""value"": """"
}
}
}".ReplaceLineEndings());
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Bicep.Core/Emit/PlaceholderParametersJsonWriter.cs
Expand Up @@ -95,8 +95,6 @@ private JToken GenerateTemplate(string contentVersion)

foreach (var parameterSymbol in filteredParameterDeclarations)
{
if (parameterSymbol.DeclaringParameter.Modifier is not ParameterDefaultValueSyntax)
{
jsonWriter.WritePropertyName(parameterSymbol.Name);

jsonWriter.WriteStartObject();
Expand All @@ -119,7 +117,6 @@ private JToken GenerateTemplate(string contentVersion)
break;
}
jsonWriter.WriteEndObject();
}
}

jsonWriter.WriteEndObject();
Expand Down

0 comments on commit 96f8e27

Please sign in to comment.