-
Notifications
You must be signed in to change notification settings - Fork 341
Add pagination support to GetVideos and GetVideosAsync in the VideoClient #789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ShivangiReja
merged 3 commits into
openai:main
from
ShivangiReja:shreja/Video_Pagination
Oct 29, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| import "../../base/typespec/videos/main.tsp"; | ||
| import "./common.models.tsp"; | ||
| import "@azure-tools/typespec-client-generator-core"; | ||
|
|
||
| using Azure.ClientGenerator.Core; | ||
| using TypeSpec.Http; | ||
|
|
||
| namespace OpenAI; | ||
|
|
||
| alias VideoItemCollectionOrderQueryParameter = { | ||
| /** | ||
| * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` | ||
| * for descending order. | ||
| */ | ||
| @query order?: VideoItemCollectionOrder; | ||
| }; | ||
|
|
||
| union VideoItemCollectionOrder { | ||
| string, | ||
| Ascending: "asc", | ||
| Descending: "desc", | ||
| } | ||
|
|
||
| @access(Access.public) | ||
| @usage(Usage.input) | ||
| model VideoItemCollectionOptions { | ||
| ...DotNetCollectionAfterQueryParameter, | ||
| ...DotNetCollectionLimitQueryParameter, | ||
| ...VideoItemCollectionOrderQueryParameter, | ||
| } | ||
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
src/Custom/Videos/Internal/InternaVideoItemCollectionOptions.cs
This file contains hidden or 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,9 @@ | ||
| namespace OpenAI.Videos; | ||
|
|
||
| // CUSTOM: | ||
| // - Renamed. | ||
| // - Made internal until we support the convenience methods. | ||
| [CodeGenType("VideoItemCollectionOptions")] | ||
| internal partial class InternaVideoItemCollectionOptions | ||
| { | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/Custom/Videos/Internal/InternalVideoItemCollectionOrder.cs
This file contains hidden or 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,9 @@ | ||
| namespace OpenAI.Videos; | ||
|
|
||
| // CUSTOM: | ||
| // - Renamed. | ||
| // - Made internal until we support the convenience methods. | ||
| [CodeGenType("VideoItemCollectionOrder")] | ||
| internal readonly partial struct InternalVideoItemCollectionOrder | ||
| { | ||
| } |
This file contains hidden or 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
115 changes: 115 additions & 0 deletions
115
src/Generated/Models/Videos/InternaVideoItemCollectionOptions.Serialization.cs
This file contains hidden or 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,115 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using OpenAI; | ||
|
|
||
| namespace OpenAI.Videos | ||
| { | ||
| internal partial class InternaVideoItemCollectionOptions : IJsonModel<InternaVideoItemCollectionOptions> | ||
| { | ||
| void IJsonModel<InternaVideoItemCollectionOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | ||
| { | ||
| writer.WriteStartObject(); | ||
| JsonModelWriteCore(writer, options); | ||
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) | ||
| { | ||
| string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; | ||
| if (format != "J") | ||
| { | ||
| throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support writing '{format}' format."); | ||
| } | ||
| // Plugin customization: remove options.Format != "W" check | ||
| if (_additionalBinaryDataProperties != null) | ||
| { | ||
| foreach (var item in _additionalBinaryDataProperties) | ||
| { | ||
| if (ModelSerializationExtensions.IsSentinelValue(item.Value)) | ||
| { | ||
| continue; | ||
| } | ||
| writer.WritePropertyName(item.Key); | ||
| #if NET6_0_OR_GREATER | ||
| writer.WriteRawValue(item.Value); | ||
| #else | ||
| using (JsonDocument document = JsonDocument.Parse(item.Value)) | ||
| { | ||
| JsonSerializer.Serialize(writer, document.RootElement); | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
|
|
||
| InternaVideoItemCollectionOptions IJsonModel<InternaVideoItemCollectionOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); | ||
|
|
||
| protected virtual InternaVideoItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) | ||
| { | ||
| string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; | ||
| if (format != "J") | ||
| { | ||
| throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support reading '{format}' format."); | ||
| } | ||
| using JsonDocument document = JsonDocument.ParseValue(ref reader); | ||
| return DeserializeInternaVideoItemCollectionOptions(document.RootElement, options); | ||
| } | ||
|
|
||
| internal static InternaVideoItemCollectionOptions DeserializeInternaVideoItemCollectionOptions(JsonElement element, ModelReaderWriterOptions options) | ||
| { | ||
| if (element.ValueKind == JsonValueKind.Null) | ||
| { | ||
| return null; | ||
| } | ||
| string afterId = default; | ||
| int? pageSizeLimit = default; | ||
| InternalVideoItemCollectionOrder? order = default; | ||
| IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>(); | ||
| foreach (var prop in element.EnumerateObject()) | ||
| { | ||
| // Plugin customization: remove options.Format != "W" check | ||
| additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); | ||
| } | ||
| return new InternaVideoItemCollectionOptions(afterId, pageSizeLimit, order, additionalBinaryDataProperties); | ||
| } | ||
|
|
||
| BinaryData IPersistableModel<InternaVideoItemCollectionOptions>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); | ||
|
|
||
| protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) | ||
| { | ||
| string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; | ||
| switch (format) | ||
| { | ||
| case "J": | ||
| return ModelReaderWriter.Write(this, options, OpenAIContext.Default); | ||
| default: | ||
| throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support writing '{options.Format}' format."); | ||
| } | ||
| } | ||
|
|
||
| InternaVideoItemCollectionOptions IPersistableModel<InternaVideoItemCollectionOptions>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); | ||
|
|
||
| protected virtual InternaVideoItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) | ||
| { | ||
| string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format; | ||
| switch (format) | ||
| { | ||
| case "J": | ||
| using (JsonDocument document = JsonDocument.Parse(data)) | ||
| { | ||
| return DeserializeInternaVideoItemCollectionOptions(document.RootElement, options); | ||
| } | ||
| default: | ||
| throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support reading '{options.Format}' format."); | ||
| } | ||
| } | ||
|
|
||
| string IPersistableModel<InternaVideoItemCollectionOptions>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/Generated/Models/Videos/InternaVideoItemCollectionOptions.cs
This file contains hidden or 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,38 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace OpenAI.Videos | ||
| { | ||
| internal partial class InternaVideoItemCollectionOptions | ||
| { | ||
| private protected IDictionary<string, BinaryData> _additionalBinaryDataProperties; | ||
|
|
||
| public InternaVideoItemCollectionOptions() | ||
| { | ||
| } | ||
|
|
||
| internal InternaVideoItemCollectionOptions(string afterId, int? pageSizeLimit, InternalVideoItemCollectionOrder? order, IDictionary<string, BinaryData> additionalBinaryDataProperties) | ||
| { | ||
| AfterId = afterId; | ||
| PageSizeLimit = pageSizeLimit; | ||
| Order = order; | ||
| _additionalBinaryDataProperties = additionalBinaryDataProperties; | ||
| } | ||
|
|
||
| public string AfterId { get; set; } | ||
|
|
||
| public int? PageSizeLimit { get; set; } | ||
|
|
||
| internal InternalVideoItemCollectionOrder? Order { get; set; } | ||
|
|
||
| internal IDictionary<string, BinaryData> SerializedAdditionalRawData | ||
| { | ||
| get => _additionalBinaryDataProperties; | ||
| set => _additionalBinaryDataProperties = value; | ||
| } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/Generated/Models/Videos/InternalVideoItemCollectionOrder.cs
This file contains hidden or 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,46 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ComponentModel; | ||
| using OpenAI; | ||
|
|
||
| namespace OpenAI.Videos | ||
| { | ||
| internal readonly partial struct InternalVideoItemCollectionOrder : IEquatable<InternalVideoItemCollectionOrder> | ||
| { | ||
| private readonly string _value; | ||
| private const string AscendingValue = "asc"; | ||
| private const string DescendingValue = "desc"; | ||
|
|
||
| public InternalVideoItemCollectionOrder(string value) | ||
| { | ||
| Argument.AssertNotNull(value, nameof(value)); | ||
|
|
||
| _value = value; | ||
| } | ||
|
|
||
| internal static InternalVideoItemCollectionOrder Ascending { get; } = new InternalVideoItemCollectionOrder(AscendingValue); | ||
|
|
||
| internal static InternalVideoItemCollectionOrder Descending { get; } = new InternalVideoItemCollectionOrder(DescendingValue); | ||
|
|
||
| public static bool operator ==(InternalVideoItemCollectionOrder left, InternalVideoItemCollectionOrder right) => left.Equals(right); | ||
|
|
||
| public static bool operator !=(InternalVideoItemCollectionOrder left, InternalVideoItemCollectionOrder right) => !left.Equals(right); | ||
|
|
||
| public static implicit operator InternalVideoItemCollectionOrder(string value) => new InternalVideoItemCollectionOrder(value); | ||
|
|
||
| public static implicit operator InternalVideoItemCollectionOrder?(string value) => value == null ? null : new InternalVideoItemCollectionOrder(value); | ||
|
|
||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public override bool Equals(object obj) => obj is InternalVideoItemCollectionOrder other && Equals(other); | ||
|
|
||
| public bool Equals(InternalVideoItemCollectionOrder other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); | ||
|
|
||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; | ||
|
|
||
| public override string ToString() => _value; | ||
| } | ||
| } |
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
src/Generated/VideoClientGetVideosAsyncCollectionResult.cs
This file contains hidden or 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,39 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace OpenAI.Videos | ||
| { | ||
| internal partial class VideoClientGetVideosAsyncCollectionResult : AsyncCollectionResult | ||
| { | ||
| private readonly VideoClient _client; | ||
| private readonly long? _limit; | ||
| private readonly string _order; | ||
| private readonly string _after; | ||
| private readonly RequestOptions _options; | ||
|
|
||
| public VideoClientGetVideosAsyncCollectionResult(VideoClient client, long? limit, string order, string after, RequestOptions options) | ||
| { | ||
| _client = client; | ||
| _limit = limit; | ||
| _order = order; | ||
| _after = after; | ||
| _options = options; | ||
| } | ||
|
|
||
| public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync() | ||
| { | ||
| PipelineMessage message = _client.CreateGetVideosRequest(_limit, _order, _after, _options); | ||
| yield return ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); | ||
| } | ||
|
|
||
| public override ContinuationToken GetContinuationToken(ClientResult page) | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.