@@ -67,9 +67,11 @@ private void GenerateARMTemplate(string apimname, string resourceGroup, string f
67
67
68
68
Console . WriteLine ( "{0} API's found ..." , ( ( JContainer ) oApi [ "value" ] ) . Count . ToString ( ) ) ;
69
69
70
- // store api and operation policies as well as diagnostics for the time being in order to extract loggers correctly
70
+ // store api and operation policies as well as diagnostics for the time being in order to extract loggers correctly in case of a single api
71
71
List < PolicyTemplateResource > policyResources = new List < PolicyTemplateResource > ( ) ;
72
72
List < DiagnosticTemplateResource > diagnosticResources = new List < DiagnosticTemplateResource > ( ) ;
73
+ // store product names for the time being in order to extract products correctly in case of a single api
74
+ List < string > productNames = new List < string > ( ) ;
73
75
74
76
List < TemplateResource > templateResources = new List < TemplateResource > ( ) ;
75
77
@@ -225,6 +227,8 @@ private void GenerateARMTemplate(string apimname, string resourceGroup, string f
225
227
apiProductsResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), '{ oApiName } ')]" } ;
226
228
227
229
templateResources . Add ( apiProductsResource ) ;
230
+ // add the product name to the list used to extract products later on
231
+ productNames . Add ( apiProductName ) ;
228
232
229
233
}
230
234
}
@@ -270,13 +274,13 @@ private void GenerateARMTemplate(string apimname, string resourceGroup, string f
270
274
271
275
if ( singleApiName != null )
272
276
{
273
- GenerateProductsARMTemplate ( apimname , resourceGroup , fileFolder ) ;
274
277
fileWriter = new FileWriter ( ) ;
275
278
fileWriter . WriteJSONToFile ( armTemplate , @fileFolder + Path . DirectorySeparatorChar + apimname + "-" + oApiName + "-template.json" ) ;
276
- templateResources = new List < TemplateResource > ( ) ;
277
279
}
278
280
}
279
281
282
+ // extract resources that do not fall under api. Pass in the single api name and associated resources for the single api case
283
+ GenerateProductsARMTemplate ( apimname , resourceGroup , fileFolder , singleApiName , productNames ) ;
280
284
GenerateNamedValuesTemplate ( resourceGroup , apimname , fileFolder , singleApiName , policyResources , diagnosticResources ) ;
281
285
GenerateLoggerTemplate ( resourceGroup , apimname , fileFolder , singleApiName , policyResources , diagnosticResources ) ;
282
286
@@ -330,7 +334,7 @@ private void GenerateVersionSetARMTemplate(string apimname, string resourceGroup
330
334
fileWriter . WriteJSONToFile ( armTemplate , filePath ) ;
331
335
}
332
336
333
- private void GenerateProductsARMTemplate ( string apimname , string resourceGroup , string fileFolder )
337
+ private void GenerateProductsARMTemplate ( string apimname , string resourceGroup , string fileFolder , string singleApiName , List < string > productNames )
334
338
{
335
339
APIExtractor apiExtractor = new APIExtractor ( ) ;
336
340
Template armTemplate = GenerateEmptyTemplateWithParameters ( ) ;
@@ -358,8 +362,18 @@ private void GenerateProductsARMTemplate(string apimname, string resourceGroup,
358
362
productsDetailsResource . name = $ "[concat(parameters('ApimServiceName'), '/{ productName } ')]";
359
363
productsDetailsResource . apiVersion = "2018-06-01-preview" ;
360
364
361
- templateResources . Add ( productsDetailsResource ) ;
362
-
365
+ if ( singleApiName == null )
366
+ {
367
+ templateResources . Add ( productsDetailsResource ) ;
368
+ } else
369
+ {
370
+ // utility is extracting a single api, only extract the product if it is found in productNames (all prodct names associated with the specific api)
371
+ if ( productNames . SingleOrDefault ( p => p == productName ) != null )
372
+ {
373
+ // current product is indeed associated with the api
374
+ templateResources . Add ( productsDetailsResource ) ;
375
+ }
376
+ }
363
377
}
364
378
365
379
armTemplate . resources = templateResources . ToArray ( ) ;
0 commit comments