@@ -17,14 +17,30 @@ public APIExtractor(FileWriter fileWriter)
17
17
this . fileWriter = fileWriter ;
18
18
}
19
19
20
- public async Task < string > GetAPIOperationsAsync ( string ApiManagementName , string ResourceGroupName , string ApiName )
20
+ private async Task < string [ ] > GetAllOperationNames ( string ApiManagementName , string ResourceGroupName , string ApiName )
21
21
{
22
- ( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
22
+ JObject oOperations = new JObject ( ) ;
23
+ int numOfOps = 0 ;
24
+ List < string > operationNames = new List < string > ( ) ;
25
+ do
26
+ {
27
+ ( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
23
28
24
- string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis/{4}/operations?api-version={5}" ,
25
- baseUrl , azSubId , ResourceGroupName , ApiManagementName , ApiName , GlobalConstants . APIVersion ) ;
29
+ string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis/{4}/operations?$skip={5}&api-version={6}" ,
30
+ baseUrl , azSubId , ResourceGroupName , ApiManagementName , ApiName , numOfOps , GlobalConstants . APIVersion ) ;
31
+ numOfOps += GlobalConstants . NumOfRecords ;
26
32
27
- return await CallApiManagementAsync ( azToken , requestUrl ) ;
33
+ string operations = await CallApiManagementAsync ( azToken , requestUrl ) ;
34
+
35
+ oOperations = JObject . Parse ( operations ) ;
36
+
37
+ foreach ( var item in oOperations [ "value" ] )
38
+ {
39
+ operationNames . Add ( ( ( JValue ) item [ "name" ] ) . Value . ToString ( ) ) ;
40
+ }
41
+ }
42
+ while ( oOperations [ "nextLink" ] != null ) ;
43
+ return operationNames . ToArray ( ) ;
28
44
}
29
45
30
46
public async Task < string > GetAPIOperationDetailsAsync ( string ApiManagementName , string ResourceGroupName , string ApiName , string OperationName )
@@ -67,14 +83,30 @@ public async Task<string> GetAPIDetailsAsync(string ApiManagementName, string Re
67
83
return await CallApiManagementAsync ( azToken , requestUrl ) ;
68
84
}
69
85
70
- public async Task < string > GetAPIsAsync ( string ApiManagementName , string ResourceGroupName )
86
+ public async Task < JToken [ ] > GetAllAPIObjsAsync ( string ApiManagementName , string ResourceGroupName )
71
87
{
72
- ( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
88
+ JObject oApi = new JObject ( ) ;
89
+ int numOfApis = 0 ;
90
+ List < JToken > apiObjs = new List < JToken > ( ) ;
91
+ do
92
+ {
93
+ ( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
73
94
74
- string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis?api-version={4}" ,
75
- baseUrl , azSubId , ResourceGroupName , ApiManagementName , GlobalConstants . APIVersion ) ;
95
+ string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis?$skip={4}&api-version={5}" ,
96
+ baseUrl , azSubId , ResourceGroupName , ApiManagementName , numOfApis , GlobalConstants . APIVersion ) ;
97
+ numOfApis += GlobalConstants . NumOfRecords ;
76
98
77
- return await CallApiManagementAsync ( azToken , requestUrl ) ;
99
+ string apis = await CallApiManagementAsync ( azToken , requestUrl ) ;
100
+
101
+ oApi = JObject . Parse ( apis ) ;
102
+
103
+ foreach ( var item in oApi [ "value" ] )
104
+ {
105
+ apiObjs . Add ( item ) ;
106
+ }
107
+ }
108
+ while ( oApi [ "nextLink" ] != null ) ;
109
+ return apiObjs . ToArray ( ) ;
78
110
}
79
111
80
112
public async Task < string > GetAPIChangeLogAsync ( string ApiManagementName , string ResourceGroupName , string ApiName )
@@ -199,12 +231,10 @@ public async Task<List<TemplateResource>> GenerateSingleAPIResourceAsync(string
199
231
#region Operations
200
232
201
233
// pull api operations for service
202
- string operations = await GetAPIOperationsAsync ( apimname , resourceGroup , apiName ) ;
203
- JObject oOperations = JObject . Parse ( operations ) ;
234
+ string [ ] operationNames = await GetAllOperationNames ( apimname , resourceGroup , apiName ) ;
204
235
205
- foreach ( var item in oOperations [ "value" ] )
236
+ foreach ( string operationName in operationNames )
206
237
{
207
- string operationName = ( ( JValue ) item [ "name" ] ) . Value . ToString ( ) ;
208
238
string operationDetails = await GetAPIOperationDetailsAsync ( apimname , resourceGroup , apiName , operationName ) ;
209
239
210
240
Console . WriteLine ( "'{0}' Operation found" , operationName ) ;
@@ -422,7 +452,7 @@ public async Task<Template> GenerateAPIRevisionTemplateAsync(string currentRevis
422
452
{
423
453
// add other API revision resources to template
424
454
apiResources = await GenerateSingleAPIResourceAsync ( curApi , exc . sourceApimName , exc . resourceGroup , exc . fileFolder , exc . policyXMLBaseUrl ) ;
425
-
455
+
426
456
// make current API a dependency to other revisions, in case destination apim doesn't have the this API
427
457
TemplateResource apiResource = apiResources . FirstOrDefault ( resource => resource . type == ResourceTypeConstants . API ) as TemplateResource ;
428
458
List < TemplateResource > newResourcesList = ExtractorUtils . removeResourceType ( ResourceTypeConstants . API , apiResources ) ;
@@ -483,12 +513,10 @@ public async Task<List<TemplateResource>> GenerateCurrentRevisionAPIResourceAsyn
483
513
#region Operations
484
514
485
515
// pull api operations for service
486
- string operations = await GetAPIOperationsAsync ( apimname , resourceGroup , apiName ) ;
487
- JObject oOperations = JObject . Parse ( operations ) ;
516
+ string [ ] operationNames = await GetAllOperationNames ( apimname , resourceGroup , apiName ) ;
488
517
489
- foreach ( var item in oOperations [ "value" ] )
518
+ foreach ( string operationName in operationNames )
490
519
{
491
- string operationName = ( ( JValue ) item [ "name" ] ) . Value . ToString ( ) ;
492
520
string operationDetails = await GetAPIOperationDetailsAsync ( apimname , resourceGroup , apiName , operationName ) ;
493
521
494
522
Console . WriteLine ( "'{0}' Operation found" , operationName ) ;
@@ -715,12 +743,12 @@ public async Task<Template> GenerateAPIsARMTemplateAsync(string apimname, string
715
743
// when extract all APIs and generate one master template
716
744
else
717
745
{
718
- JObject oApi = await GetAllAPIsFromAPIM ( apimname , resourceGroup , policyXMLBaseUrl ) ;
719
- Console . WriteLine ( "{0} APIs found ..." , ( ( JContainer ) oApi [ "value" ] ) . Count . ToString ( ) ) ;
746
+ JToken [ ] oApis = await GetAllAPIObjsAsync ( apimname , resourceGroup ) ;
747
+ Console . WriteLine ( "{0} APIs found ..." , ( oApis . Count ( ) . ToString ( ) ) ) ;
720
748
721
- for ( int i = 0 ; i < ( ( JContainer ) oApi [ "value" ] ) . Count ; i ++ )
749
+ foreach ( JToken oApi in oApis )
722
750
{
723
- string apiName = ( ( JValue ) oApi [ "value" ] [ i ] [ " name"] ) . Value . ToString ( ) ;
751
+ string apiName = ( ( JValue ) oApi [ "name" ] ) . Value . ToString ( ) ;
724
752
templateResources . AddRange ( await GenerateSingleAPIResourceAsync ( apiName , apimname , resourceGroup , fileFolder , policyXMLBaseUrl ) ) ;
725
753
}
726
754
}
@@ -761,14 +789,6 @@ private static bool CheckAPIExist(string singleApiName, JObject oApi)
761
789
return false ;
762
790
}
763
791
764
- public async Task < JObject > GetAllAPIsFromAPIM ( string apimname , string resourceGroup , string policyXMLBaseUrl )
765
- {
766
- // pull all apis from service
767
- string apis = await GetAPIsAsync ( apimname , resourceGroup ) ;
768
- JObject oApi = JObject . Parse ( apis ) ;
769
- return oApi ;
770
- }
771
-
772
792
private async Task < List < TemplateResource > > GenerateSchemasARMTemplate ( string apimServiceName , string apiName , string resourceGroup , string fileFolder )
773
793
{
774
794
List < TemplateResource > templateResources = new List < TemplateResource > ( ) ;
0 commit comments