/// <summary> /// Changes paginated method signatures to return Page type. /// </summary> /// <param name="serviceClient">The service client.</param> private void ApplyPagination(ServiceClient serviceClient) { if (serviceClient == null) { throw new ArgumentNullException(nameof(serviceClient)); } foreach (Method method in serviceClient.Methods.Where(m => m.Extensions.ContainsKey(AzureExtensions.PageableExtension))) { string nextLinkName = null; var ext = method.Extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer; if (ext == null) { continue; } nextLinkName = CodeNamer.GetPropertyName((string)ext["nextLinkName"]); string itemName = CodeNamer.GetPropertyName((string)ext["itemName"] ?? "value"); foreach (var responseStatus in method.Responses.Where(r => r.Value.Body is CompositeType).Select(s => s.Key).ToArray()) { CompositeType compositeType = (CompositeType)method.Responses[responseStatus].Body; SequenceType sequenceType = compositeType.Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType; // if the type is a wrapper over page-able response if (sequenceType != null) { compositeType.Extensions[AzureExtensions.PageableExtension] = true; PageTemplateModel pageTemplateModel = new PageTemplateModel(compositeType, serviceClient.ModelTypes, nextLinkName, itemName); if (!pageModels.Contains(pageTemplateModel)) { pageModels.Add(pageTemplateModel); } } } } }