Skip to content

Commit

Permalink
Throw code gen error if pageable operation does not return pageable t…
Browse files Browse the repository at this point in the history
…ype (Azure#1262)

Throw  error if return type for pageable operation doesn't contain a collection.
  • Loading branch information
veronicagg authored Jul 14, 2016
1 parent 62173d1 commit 34f56ea
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Net;
using System.Text;
using AutoRest.Core.ClientModel;
using AutoRest.Core.Logging;
using AutoRest.Extensions.Azure;
using AutoRest.Extensions.Azure.Model;
using AutoRest.Ruby.Azure.Properties;
Expand Down Expand Up @@ -274,8 +275,15 @@ public override string OperationReturnTypeString
{
if (Extensions.ContainsKey("nextMethodName") && !Extensions.ContainsKey(AzureExtensions.PageableExtension))
{
SequenceType sequenceType = ((CompositeType)ReturnType.Body).Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType;
return string.Format(CultureInfo.InvariantCulture, "Array<{0}>", sequenceType.ElementType.Name);
try
{
SequenceType sequenceType = ((CompositeType)ReturnType.Body).Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType;
return string.Format(CultureInfo.InvariantCulture, "Array<{0}>", sequenceType.ElementType.Name);
}
catch (NullReferenceException nr)
{
throw ErrorManager.CreateError(string.Format(CultureInfo.InvariantCulture, "No collection type exists in pageable operation return type: {0}", nr.StackTrace));
}
}
return base.OperationReturnTypeString;
}
Expand Down

0 comments on commit 34f56ea

Please sign in to comment.