-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
317 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/AutoRest.CSharp.V3/Output/Models/Requests/PagingResponseInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using AutoRest.CSharp.V3.Generation.Types; | ||
using AutoRest.CSharp.V3.Input; | ||
using AutoRest.CSharp.V3.Output.Models.Types; | ||
using Azure; | ||
|
||
namespace AutoRest.CSharp.V3.Output.Models.Requests | ||
{ | ||
internal class PagingResponseInfo | ||
{ | ||
public PagingResponseInfo(Paging paging, CSharpType type) | ||
{ | ||
ResponseType = type; | ||
|
||
TypeProvider implementation = type.Implementation; | ||
if (!(implementation is ObjectType objectType)) | ||
{ | ||
throw new InvalidOperationException($"The type '{type}' has to be an object schema to be used in paging"); | ||
} | ||
|
||
string? nextLinkName = paging.NextLinkName; | ||
string itemName = paging.ItemName ?? "value"; | ||
|
||
ObjectTypeProperty itemProperty = objectType.GetPropertyBySerializedName(itemName); | ||
|
||
ObjectTypeProperty? nextLinkProperty = null; | ||
if (!string.IsNullOrWhiteSpace(nextLinkName)) | ||
{ | ||
nextLinkProperty = objectType.GetPropertyBySerializedName(nextLinkName); | ||
} | ||
|
||
if (!TypeFactory.IsList(itemProperty.Declaration.Type)) | ||
{ | ||
throw new InvalidOperationException($"{itemName} property has to be an array schema, actual {itemProperty.SchemaProperty?.Schema}"); | ||
} | ||
|
||
CSharpType itemType = TypeFactory.GetElementType(itemProperty.Declaration.Type); | ||
NextLinkProperty = nextLinkProperty; | ||
ItemProperty = itemProperty; | ||
ItemType = itemType; | ||
} | ||
|
||
public CSharpType ResponseType { get; } | ||
public ObjectTypeProperty? NextLinkProperty { get; } | ||
public ObjectTypeProperty ItemProperty { get; } | ||
public CSharpType PageType => new CSharpType(typeof(Page<>), ItemType); | ||
public CSharpType ItemType { get; } | ||
} | ||
} |
Oops, something went wrong.