Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit fdd5552

Browse files
springcompMaxime LABELLERupengLiu
authored
#499 - Prevent crash when no products are associated with a particular api. (#500)
Co-authored-by: Maxime LABELLE <maxime.labelle@chanel.com> Co-authored-by: RupengLiu <rliu1211@terpmail.umd.edu>
1 parent aed2a35 commit fdd5552

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/APIM_ARMTemplate/apimtemplate/Creator/TemplateCreators/ProductAPITemplateCreator.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ public Template CreateProductAPITemplate(CreatorConfig creatorConfig)
2020
string[] dependsOn = new string[] { };
2121
foreach (APIConfig api in creatorConfig.apis)
2222
{
23-
List<ProductAPITemplateResource> apiResources = CreateProductAPITemplateResources(api, dependsOn);
24-
resources.AddRange(apiResources);
23+
if (api.products != null)
24+
{
25+
List<ProductAPITemplateResource> apiResources = CreateProductAPITemplateResources(api, dependsOn);
26+
resources.AddRange(apiResources);
2527

26-
// Add previous product/API resource as a dependency for next product/API resource(s)
27-
string productID = apiResources[apiResources.Count - 1].name.Split('/', 3)[1];
28-
dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/products/apis', parameters('{ParameterNames.ApimServiceName}'), '{productID}', '{api.name}')]" };
28+
// Add previous product/API resource as a dependency for next product/API resource(s)
29+
string productID = apiResources[apiResources.Count - 1].name.Split('/', 3)[1];
30+
dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/products/apis', parameters('{ParameterNames.ApimServiceName}'), '{productID}', '{api.name}')]" };
31+
}
2932
}
3033

3134
productTemplate.resources = resources.ToArray();
@@ -48,7 +51,7 @@ public List<ProductAPITemplateResource> CreateProductAPITemplateResources(APICon
4851
// create a products/apis association resource for each product provided in the config file
4952
List<ProductAPITemplateResource> productAPITemplates = new List<ProductAPITemplateResource>();
5053
// products is comma separated list of productIds
51-
string[] productIDs = api.products.Split(", ");
54+
string[] productIDs = (api.products ?? "").Split(", ", System.StringSplitOptions.RemoveEmptyEntries);
5255
string[] allDependsOn = dependsOn;
5356
foreach (string productID in productIDs)
5457
{

0 commit comments

Comments
 (0)