@@ -246,7 +246,7 @@ public async Task<List<TemplateResource>> GenerateSingleAPIResourceAsync(string
246
246
{
247
247
apiResource . properties . serviceUrl = $ "[parameters('{ ParameterNames . ServiceUrl } ').{ ExtractorUtils . GenValidParamName ( apiName , ParameterPrefix . Api ) } ]";
248
248
}
249
-
249
+
250
250
if ( apiResource . properties . apiVersionSetId != null )
251
251
{
252
252
apiResource . dependsOn = new string [ ] { } ;
@@ -334,7 +334,7 @@ public async Task<List<TemplateResource>> GenerateCurrentRevisionAPIResourceAsyn
334
334
{
335
335
apiResource . properties . serviceUrl = $ "[parameters('{ ParameterNames . ServiceUrl } ').{ ExtractorUtils . GenValidParamName ( apiName , ParameterPrefix . Api ) } ]";
336
336
}
337
-
337
+
338
338
if ( apiResource . properties . apiVersionSetId != null )
339
339
{
340
340
apiResource . dependsOn = new string [ ] { } ;
@@ -410,12 +410,21 @@ public async Task<Template> GenerateAPIsARMTemplateAsync(string singleApiName, L
410
410
411
411
private static void ArmEscapeSampleValueIfNecessary ( OperationTemplateRepresentation operationTemplateRepresentation )
412
412
{
413
- if ( ! string . IsNullOrWhiteSpace ( operationTemplateRepresentation . sample ) && operationTemplateRepresentation . contentType ? . Contains ( "application/json" , StringComparison . OrdinalIgnoreCase ) == true && operationTemplateRepresentation . sample . TryParseJson ( out JToken sampleAsJToken ) && sampleAsJToken . Type == JTokenType . Array )
413
+
414
+ if ( ! string . IsNullOrWhiteSpace ( operationTemplateRepresentation . sample ) &&
415
+ ContentTypes ( ) . Contains ( operationTemplateRepresentation . contentType ? . ToLower ( ) ) &&
416
+ operationTemplateRepresentation . sample . TryParseJson ( out JToken sampleAsJToken ) &&
417
+ sampleAsJToken . Type == JTokenType . Array )
414
418
{
415
419
operationTemplateRepresentation . sample = "[" + operationTemplateRepresentation . sample ;
416
420
}
417
421
}
418
422
423
+ private static string [ ] ContentTypes ( )
424
+ {
425
+ return new string [ ] { "application/json" , "text/json" , "application/*+json" } ;
426
+ }
427
+
419
428
private static void AddSchemaDependencyToOperationIfNecessary ( string apiName , List < string > operationDependsOn , OperationTemplateRepresentation operationTemplateRepresentation )
420
429
{
421
430
if ( operationTemplateRepresentation . schemaId != null )
@@ -528,23 +537,25 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
528
537
int numBatches = 0 ;
529
538
530
539
// create empty array for the batch operation owners
531
- List < string > batchOwners = new List < string > ( ) ;
540
+ List < string > batchOwners = new List < string > ( ) ;
532
541
533
542
// if a batch size is specified
534
- if ( exc . operationBatchSize > 0 ) {
543
+ if ( exc . operationBatchSize > 0 )
544
+ {
535
545
// store the number of batches required based on exc.operationBatchSize
536
- numBatches = ( int ) Math . Ceiling ( ( double ) operationNames . Length / ( double ) exc . operationBatchSize ) ;
546
+ numBatches = ( int ) Math . Ceiling ( ( double ) operationNames . Length / ( double ) exc . operationBatchSize ) ;
537
547
//Console.WriteLine ("Number of batches: {0}", numBatches);
538
548
}
539
-
549
+
540
550
541
551
foreach ( string operationName in operationNames )
542
552
{
543
553
int opIndex = Array . IndexOf ( operationNames , operationName ) ;
544
554
545
555
//add batch owners into array
546
556
// ensure each owner is linked to the one before
547
- if ( exc . operationBatchSize > 0 && opIndex < numBatches ) {
557
+ if ( exc . operationBatchSize > 0 && opIndex < numBatches )
558
+ {
548
559
batchOwners . Add ( operationName ) ;
549
560
//Console.WriteLine("Adding operation {0} to owner list", operationName);
550
561
}
@@ -580,18 +591,22 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
580
591
// add to batch if flagged
581
592
string batchdependsOn ;
582
593
583
- if ( exc . operationBatchSize > 0 && opIndex > 0 ) {
584
- if ( opIndex >= 1 && opIndex <= numBatches - 1 ) {
594
+ if ( exc . operationBatchSize > 0 && opIndex > 0 )
595
+ {
596
+ if ( opIndex >= 1 && opIndex <= numBatches - 1 )
597
+ {
585
598
// chain the owners to each other
586
599
batchdependsOn = $ "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('{ ParameterNames . ApimServiceName } '), '{ apiName } ', '{ batchOwners [ opIndex - 1 ] } ')]";
587
600
//Console.WriteLine("Owner chaining: this request {0} to previous {1}", operationName, batchOwners[opIndex-1]);
588
- } else {
601
+ }
602
+ else
603
+ {
589
604
// chain the operation to respective owner
590
- int ownerIndex = ( int ) Math . Floor ( ( opIndex - numBatches ) / ( ( double ) exc . operationBatchSize - 1 ) ) ;
605
+ int ownerIndex = ( int ) Math . Floor ( ( opIndex - numBatches ) / ( ( double ) exc . operationBatchSize - 1 ) ) ;
591
606
batchdependsOn = $ "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('{ ParameterNames . ApimServiceName } '), '{ apiName } ', '{ batchOwners [ ownerIndex ] } ')]";
592
607
//Console.WriteLine("Operation {0} chained to owner {1}", operationName, batchOwners[ownerIndex]);
593
608
}
594
-
609
+
595
610
operationDependsOn . Add ( batchdependsOn ) ;
596
611
}
597
612
@@ -693,7 +708,7 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
693
708
catch ( Exception ) { }
694
709
#endregion
695
710
696
- #region API Tags
711
+ #region API Tags
697
712
// add tags associated with the api to template
698
713
try
699
714
{
@@ -716,9 +731,9 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
716
731
}
717
732
}
718
733
catch ( Exception ) { }
719
- #endregion
734
+ #endregion
735
+
720
736
721
-
722
737
// add product api associations to template
723
738
#region API Products
724
739
try
@@ -764,8 +779,9 @@ private async Task<IEnumerable<TemplateResource>> GetRelatedTemplateResourcesAsy
764
779
diagnosticResource . scale = null ;
765
780
diagnosticResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/apis', parameters('{ ParameterNames . ApimServiceName } '), '{ apiName } ')]" } ;
766
781
767
- if ( exc . paramApiLoggerId ) {
768
-
782
+ if ( exc . paramApiLoggerId )
783
+ {
784
+
769
785
diagnosticResource . properties . loggerId = $ "[parameters('{ ParameterNames . ApiLoggerId } ').{ ExtractorUtils . GenValidParamName ( apiName , ParameterPrefix . Api ) } .{ ExtractorUtils . GenValidParamName ( diagnosticName , ParameterPrefix . Diagnostic ) } ]";
770
786
}
771
787
0 commit comments