Skip to content

Commit 5e37818

Browse files
authored
[FR] Modify Pages type (Azure#18260)
Changed the type for `IEnumerable` to `IList` as this is a property in an input-only object. Followed what other libraries like Search and KV do.
1 parent 5ee3df7 commit 5e37818

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Renamed the model `Appearance` to `TextAppearance`.
66
- Renamed the model `Style` to `TextStyle`.
77
- Renamed the extensible enum `TextStyle` to `TextStyleName`.
8+
- Changed object type for property `Pages` under `RecognizeContentOptions` from `IEnumerable` to `IList`.
89

910
## 3.1.0-beta.1 (2020-11-23)
1011

sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public partial class RecognizeContentOptions
7070
public RecognizeContentOptions() { }
7171
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
7272
public string Language { get { throw null; } set { } }
73-
public System.Collections.Generic.IEnumerable<string> Pages { get { throw null; } set { } }
73+
public System.Collections.Generic.IList<string> Pages { get { throw null; } }
7474
}
7575
public partial class RecognizeCustomFormsOptions
7676
{

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public virtual RecognizeContentOperation StartRecognizeContent(Stream form, Reco
142142
formContentType.ConvertToContentType1(),
143143
form,
144144
recognizeContentOptions.Language == null ? (Language?)null : recognizeContentOptions.Language,
145-
recognizeContentOptions.Pages,
145+
recognizeContentOptions.Pages.Count == 0 ? null : recognizeContentOptions.Pages,
146146
cancellationToken);
147147
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
148148

@@ -181,7 +181,7 @@ public virtual async Task<RecognizeContentOperation> StartRecognizeContentAsync(
181181
formContentType.ConvertToContentType1(),
182182
form,
183183
recognizeContentOptions.Language == null ? (Language?)null : recognizeContentOptions.Language,
184-
recognizeContentOptions.Pages,
184+
recognizeContentOptions.Pages.Count == 0 ? null : recognizeContentOptions.Pages,
185185
cancellationToken).ConfigureAwait(false);
186186
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
187187

@@ -217,7 +217,7 @@ public virtual RecognizeContentOperation StartRecognizeContentFromUri(Uri formUr
217217
SourcePath sourcePath = new SourcePath() { Source = formUri.AbsoluteUri };
218218
Response response = ServiceClient.AnalyzeLayoutAsync(
219219
recognizeContentOptions.Language == null ? (Language?)null : recognizeContentOptions.Language,
220-
recognizeContentOptions.Pages,
220+
recognizeContentOptions.Pages.Count == 0 ? null : recognizeContentOptions.Pages,
221221
sourcePath,
222222
cancellationToken);
223223
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -254,7 +254,7 @@ public virtual async Task<RecognizeContentOperation> StartRecognizeContentFromUr
254254
SourcePath sourcePath = new SourcePath() { Source = formUri.AbsoluteUri };
255255
Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(
256256
recognizeContentOptions.Language == null ? (Language?)null : recognizeContentOptions.Language,
257-
recognizeContentOptions.Pages,
257+
recognizeContentOptions.Pages.Count == 0 ? null : recognizeContentOptions.Pages,
258258
sourcePath,
259259
cancellationToken).ConfigureAwait(false);
260260
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

sdk/formrecognizer/Azure.AI.FormRecognizer/src/RecognizeContentOptions.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ public RecognizeContentOptions()
3838
public string Language { get; set; }
3939

4040
/// <summary>
41-
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the number of the
42-
/// pages you want to get OCR result. For a range of pages, use a hyphen.
43-
/// Separate each page or range with a comma.
41+
/// <para>
42+
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
43+
/// and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
44+
/// `Pages = { "1-3", "5-6" }`. Separate each page number or range with a comma.
45+
/// </para>
46+
/// <para>
47+
/// Although this collection cannot be set, it can be modified.
48+
/// See <a href="https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers">collection initializer</a>.
49+
/// </para>
4450
/// </summary>
45-
public IEnumerable<string> Pages { get; set; }
51+
public IList<string> Pages { get; } = new List<string>();
4652
}
4753
}

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/FormRecognizerClientLiveTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public async Task StartRecognizeContentWithOnePageArgument(string pages, int exp
461461
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceMultipageBlank);
462462
using (Recording.DisableRequestBodyRecording())
463463
{
464-
operation = await client.StartRecognizeContentAsync(stream, new RecognizeContentOptions() { Pages = new List<string> { pages } });
464+
operation = await client.StartRecognizeContentAsync(stream, new RecognizeContentOptions() { Pages = { pages } });
465465
}
466466

467467
FormPageCollection formPages = await operation.WaitForCompletionAsync(PollingInterval);
@@ -480,7 +480,7 @@ public async Task StartRecognizeContentWithMultiplePageArgument(string page1, st
480480
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceMultipageBlank);
481481
using (Recording.DisableRequestBodyRecording())
482482
{
483-
operation = await client.StartRecognizeContentAsync(stream, new RecognizeContentOptions() { Pages = new List<string> { page1, page2 } });
483+
operation = await client.StartRecognizeContentAsync(stream, new RecognizeContentOptions() { Pages = { page1, page2 } });
484484
}
485485

486486
FormPageCollection formPages = await operation.WaitForCompletionAsync(PollingInterval);

0 commit comments

Comments
 (0)