Skip to content

Commit

Permalink
adding support for variables, objects and arrays in extended param files
Browse files Browse the repository at this point in the history
  • Loading branch information
polatengin committed Dec 11, 2024
1 parent f0470b8 commit 4147740
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions src/Bicep.Core.IntegrationTests/ParametersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,5 +546,74 @@ param foo string
}
}"));
}

[TestMethod]
public void Using_variables_objects_arrays_in_base_parameters_file_should_succeed()
{
var result = CompilationHelper.CompileParams(
("bicepconfig.json", @"
{
""experimentalFeaturesEnabled"": {
""extendableParamFiles"": true
}
}
"),
("parameters.bicepparam", @"
using 'main.bicep'
extends 'shared.bicepparam'
"),
("shared.bicepparam", @"
using none
var var_foo = 'foo'
param foo = var_foo
var var_bar = {
a: 'a'
b: 'b'
}
param bar = var_bar
var var_baz = [
var_foo
var_bar
]
param baz = var_baz
"),
("main.bicep", @"
param foo string = ''
param bar object = {}
param baz array = []
"));

result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();

result.Parameters.Should().DeepEqual(JToken.Parse(@"{
""$schema"": ""https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#"",
""contentVersion"": ""1.0.0.0"",
""parameters"": {
""foo"": {
""value"": ""bar""
},
""bar"": {
""value"": {
""a"": ""a"",
""b"": ""b""
}
},
""baz"": {
""value"": [
""foo"",
{
""a"": ""a"",
""b"": ""b""
}
]
}
}
}"));
}
}
}
2 changes: 1 addition & 1 deletion src/Bicep.Core/Semantics/SemanticModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ private IEnumerable<IDiagnostic> GatherParameterMismatchDiagnostics(ISemanticMod

private IEnumerable<IDiagnostic> GatherTypeMismatchDiagnostics()
{
foreach (var assignmentSymbol in Root.ParameterAssignments)
foreach (var assignmentSymbol in Root.ParameterAssignments.Where(x => x.Context.SourceFile == Root.Context.SourceFile))
{
if (assignmentSymbol.Type is not ErrorType &&
assignmentSymbol.Type is not NullType && // `param x = null` is equivalent to skipping the assignment altogether
Expand Down

0 comments on commit 4147740

Please sign in to comment.