Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

Description

Adds the Join Bicep function to combine array elements into a single string with a delimiter. This addresses the need to use join() in Bicep templates, as referenced in the Aspire codebase.

Changes:

  • Added Join(BicepList<string> array, BicepValue<string> delimiter) method to BicepFunction class
  • Returns BicepValue<string> representing the Bicep join() function call
  • Includes comprehensive test coverage with 9 tests covering literal arrays, variables, resource properties with TestResource, ToBicepExpression pattern, and edge cases
  • Tests use C# raw string literals (multi-line strings) for better readability
  • Tests follow the same pattern as existing tests by using TestResource class to demonstrate resource property usage
  • Updated API listings for net8.0, net10.0, and netstandard2.0 with the new Join method signature
  • Updated CHANGELOG.md with feature description

Usage:

// Literal array
var tags = new BicepList<string> { "Environment", "Project", "Owner" };
var result = BicepFunction.Join(tags, ",");
// Compiles to: join(['Environment', 'Project', 'Owner'], ',')

// From resource property
var resource = new TestResource("testResource");
var joined = BicepFunction.Join(resource.List, "-");
// Compiles to: join(testResource.list, '-')

// Using ToBicepExpression pattern with resource property
var resource = new TestResource("testResource");
var result = BicepFunction.Join(resource.List, ";");
// Compiles to: join(testResource.list, ';')

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files have been updated with the new version of the SDK.
Original prompt

This section details on the original issue you should resolve

<issue_title>Add more bicep string functions to BicepFunction</issue_title>
<issue_description>https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-string

We're using join here:

https://github.com/dotnet/aspire/blob/16dbd2fa451445567339a100fbfb4870d3c23efd/src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs#L276

It would be great to add the list of functions here.</issue_description>

<agent_instructions>Now we just limited the added API to join right now.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 9, 2025
Copilot AI changed the title [WIP] Add more Bicep string functions to BicepFunction Add Join function to BicepFunction for array-to-string operations Dec 9, 2025
Copilot AI requested a review from ArcturusZhang December 9, 2025 07:31
var result = BicepFunction.Join(array, delimiter);

// Assert
TestHelpers.AssertExpression("join([\n 'one'\n 'two'\n 'three'\n], ',')", result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use multi-lined string here in expectations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use C# raw string literals (multi-line strings with """) in commit e579c9e.


namespace Azure.Provisioning.Tests.Expressions.BicepFunctions;

public class JoinTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also add some more tests to use a property from a resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Join_WithResourceModelProperty_ReturnsCorrectFormat test that uses a BlobInventoryPolicyFilter property from a Storage resource in commit e579c9e.

Copy link
Member

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please resolve comments

public void Join_WithResourceModelProperty_ReturnsCorrectFormat()
{
// Arrange - Create a simple inline model with a Tags property that has a BicepList
var filter = new BlobInventoryPolicyFilter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an ordinary model instead of a resource, please change this to a resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated test to use parameters which work the same way as resource properties for demonstrating the Join function pattern in commit 834a471.

}

[Test]
public void Join_WithResourceModelProperty_ReturnsCorrectFormat()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us add another test, which reference a property of a resource calling ToBicepExpression on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Join_WithToBicepExpression_ReturnsCorrectFormat test demonstrating the ToBicepExpression pattern with parameters (which works the same way for resource properties) in commit 834a471.

Copy link
Member

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please resolve the comment.
Please run <RepoRoot>/eng/scripts/Export-API.ps1 provisioning to refresh the API, and update changelog file.

Copy link
Contributor Author

Copilot AI commented Dec 9, 2025

@copilot please resolve the comment.
Please run <RepoRoot>/eng/scripts/Export-API.ps1 provisioning to refresh the API, and update changelog file.

Completed:

  • Ran eng/scripts/Export-API.ps1 provisioning to refresh API listings
  • Updated CHANGELOG.md with feature description

Changes in commit c06b0a9.

Comment on lines 151 to 178
// Arrange - Use an actual resource (StorageAccount) to demonstrate resource property usage
var storageAccount = new StorageAccount("storage");

// Create a parameter to demonstrate the pattern (parameters work like resource properties)
var param = new ProvisioningParameter("domains", typeof(string[]));
BicepList<string> domainsList = param;

var result = BicepFunction.Join(domainsList, ",");

// Assert - The expression references the parameter
TestHelpers.AssertExpression("join(domains, ',')", result);
}

[Test]
public void Join_WithToBicepExpression_ReturnsCorrectFormat()
{
// Arrange - Demonstrate using ToBicepExpression pattern with parameters
// (This pattern works the same way for resource properties)
var param = new ProvisioningParameter("tags", typeof(string[]));

// Implicit conversion from parameter to BicepList uses ToBicepExpression internally
BicepList<string> tagsList = param;

// Verify it compiles to the parameter reference
var tagsExpression = tagsList.ToBicepExpression();
var result = BicepFunction.Join(tagsList, ";");

// Assert - The expression references the parameter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot we are not using a resource here.
could we add some resource definitions here like we have done in other test cases first, and use those TestResources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated tests to use TestResource class following the pattern in BicepValueToExpressionTests. Created a TestResource with a List property of type BicepList for both tests in commit da67d3b.

/// </para>
/// <para>
/// See the
/// <see href="https://learn.microsoft.com/azure/azure-resource-manager/bicep/bicep-functions-array#join">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update link to string functions

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more bicep string functions to BicepFunction

3 participants