Skip to content

Commit

Permalink
[FR] Add API version to new methods in 2.1-preview.x (#20817)
Browse files Browse the repository at this point in the history
  • Loading branch information
maririos authored May 4, 2021
1 parent ed2164c commit f4f025c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### New Features
- Updated the `FormRecognizerModelFactory` class to support missing model types for mocking.
- Added support for service version `2.0`. This can be specified in the `FormRecognizerClientOptions` object under the `ServiceVersion` enum.
By default the SDK targets latest supported service version.

### Breaking changes
- Renamed `Id` for `Identity` in all the `StartRecognizeIdDocuments` functionalities. For example, the name of the method is now `StartRecognizeIdentityDocuments`.
Expand Down
9 changes: 9 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Install the Azure Form Recognizer client library for .NET with [NuGet][nuget]:
dotnet add package Azure.AI.FormRecognizer
```

> Note: This version of the client library defaults to the `v2.1-preview.3` version of the service.
This table shows the relationship between SDK versions and supported API versions of the service:

|SDK version|Supported API version of service
|-|-
|3.0.0 - Latest GA release | 2.0
|3.1.0-beta.4 - Latest release (beta)| 2.0, 2.1-preview.3

### Prerequisites
* An [Azure subscription][azure_sub].
* An existing Cognitive Services or Form Recognizer resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public virtual RecognizeReceiptsOperation StartRecognizeReceiptsFromUri(Uri rece
/// <param name="recognizeBusinessCardsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeBusinessCardsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeBusinessCardsOperation.Value"/> upon successful
/// completion will contain the extracted business cards.</returns>
public virtual async Task<RecognizeBusinessCardsOperation> StartRecognizeBusinessCardsAsync(Stream businessCard, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -489,6 +492,9 @@ public virtual async Task<RecognizeBusinessCardsOperation> StartRecognizeBusines
/// <param name="recognizeBusinessCardsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeBusinessCardsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeBusinessCardsOperation.Value"/> upon successful
/// completion will contain the extracted business cards.</returns>
public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCards(Stream businessCard, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -530,6 +536,9 @@ public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCards(Strea
/// <param name="recognizeBusinessCardsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeBusinessCardsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeBusinessCardsOperation.Value"/> upon successful
/// completion will contain the extracted business cards.</returns>
public virtual async Task<RecognizeBusinessCardsOperation> StartRecognizeBusinessCardsFromUriAsync(Uri businessCardUri, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -569,6 +578,9 @@ public virtual async Task<RecognizeBusinessCardsOperation> StartRecognizeBusines
/// <param name="recognizeBusinessCardsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeBusinessCardsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeBusinessCardsOperation.Value"/> upon successful
/// completion will contain the extracted business cards.</returns>
public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCardsFromUri(Uri businessCardUri, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -612,6 +624,9 @@ public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCardsFromUr
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesAsync(Stream invoice, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -653,6 +668,9 @@ public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesAsyn
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual RecognizeInvoicesOperation StartRecognizeInvoices(Stream invoice, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -694,6 +712,9 @@ public virtual RecognizeInvoicesOperation StartRecognizeInvoices(Stream invoice,
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesFromUriAsync(Uri invoiceUri, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -733,6 +754,9 @@ public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesFrom
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, the locale of the form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual RecognizeInvoicesOperation StartRecognizeInvoicesFromUri(Uri invoiceUri, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -776,6 +800,9 @@ public virtual RecognizeInvoicesOperation StartRecognizeInvoicesFromUri(Uri invo
/// <param name="recognizeIdentityDocumentsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeIdentityDocumentsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeIdentityDocumentsOperation.Value"/> upon successful
/// completion will contain the extracted identity document information.</returns>
public virtual async Task<RecognizeIdentityDocumentsOperation> StartRecognizeIdentityDocumentsAsync(Stream identityDocument, RecognizeIdentityDocumentsOptions recognizeIdentityDocumentsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -817,6 +844,9 @@ public virtual async Task<RecognizeIdentityDocumentsOperation> StartRecognizeIde
/// <param name="recognizeIdentityDocumentsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeIdentityDocumentsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeIdentityDocumentsOperation.Value"/> upon successful
/// completion will contain the extracted identity document information.</returns>
public virtual RecognizeIdentityDocumentsOperation StartRecognizeIdentityDocuments(Stream identityDocument, RecognizeIdentityDocumentsOptions recognizeIdentityDocumentsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -858,6 +888,9 @@ public virtual RecognizeIdentityDocumentsOperation StartRecognizeIdentityDocumen
/// <param name="recognizeIdentityDocumentsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeIdentityDocumentsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeIdentityDocumentsOperation.Value"/> upon successful
/// completion will contain the extracted identity document information.</returns>
public virtual async Task<RecognizeIdentityDocumentsOperation> StartRecognizeIdentityDocumentsFromUriAsync(Uri identityDocumentUri, RecognizeIdentityDocumentsOptions recognizeIdentityDocumentsOptions = default, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -897,6 +930,9 @@ public virtual async Task<RecognizeIdentityDocumentsOperation> StartRecognizeIde
/// <param name="recognizeIdentityDocumentsOptions">A set of options available for configuring the recognize request. For example, specify the content type of the
/// form, or whether or not to include form elements.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>A <see cref="RecognizeIdentityDocumentsOperation"/> to wait on this long-running operation. Its <see cref="RecognizeIdentityDocumentsOperation.Value"/> upon successful
/// completion will contain the extracted identity document information.</returns>
public virtual RecognizeIdentityDocumentsOperation StartRecognizeIdentityDocumentsFromUri(Uri identityDocumentUri, RecognizeIdentityDocumentsOptions recognizeIdentityDocumentsOptions = default, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public virtual async Task<TrainingOperation> StartTrainingAsync(Uri trainingFile
/// <param name="modelIds">List of model ids to use in the composed model.</param>
/// <param name="modelName">An optional, user-defined name to associate with the model.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>
/// <para>A <see cref="CreateComposedModelOperation"/> to wait on this long-running operation. Its Value upon successful
/// completion will contain meta-data about the composed model.</para>
Expand Down Expand Up @@ -326,6 +329,9 @@ public virtual CreateComposedModelOperation StartCreateComposedModel(IEnumerable
/// <param name="modelIds">List of model ids to use in the composed model.</param>
/// <param name="modelName">An optional, user-defined name to associate with the model.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <remarks>
/// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1_Preview_3"/> and up.
/// </remarks>
/// <returns>
/// <para>A <see cref="CreateComposedModelOperation"/> to wait on this long-running operation. Its Value upon successful
/// completion will contain meta-data about the composed model.</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,38 @@ public void FormRecognizerClientCannotAuthenticateWithFakeApiKey()
Assert.ThrowsAsync<RequestFailedException>(async () => await client.StartRecognizeContentAsync(stream));
}
}

[RecordedTest]
[ServiceVersion(Max = FormRecognizerClientOptions.ServiceVersion.V2_0)]
public void StartRecognizeBusinessCardsWithV2()
{
var client = CreateFormRecognizerClient();
var uri = FormRecognizerTestEnvironment.CreateUri(TestFile.BusinessCardJpg);

RequestFailedException ex = Assert.ThrowsAsync<RequestFailedException>(async () => await client.StartRecognizeBusinessCardsFromUriAsync(uri));
Assert.AreEqual("404", ex.ErrorCode);
}

[RecordedTest]
[ServiceVersion(Max = FormRecognizerClientOptions.ServiceVersion.V2_0)]
public void StartRecognizeIdentityDocumentsWithV2()
{
var client = CreateFormRecognizerClient();
var uri = FormRecognizerTestEnvironment.CreateUri(TestFile.DriverLicenseJpg);

RequestFailedException ex = Assert.ThrowsAsync<RequestFailedException>(async () => await client.StartRecognizeIdentityDocumentsFromUriAsync(uri));
Assert.AreEqual("404", ex.ErrorCode);
}

[RecordedTest]
[ServiceVersion(Max = FormRecognizerClientOptions.ServiceVersion.V2_0)]
public void StartRecognizeInvoicesWithV2()
{
var client = CreateFormRecognizerClient();
var uri = FormRecognizerTestEnvironment.CreateUri(TestFile.InvoiceJpg);

RequestFailedException ex = Assert.ThrowsAsync<RequestFailedException>(async () => await client.StartRecognizeInvoicesFromUriAsync(uri));
Assert.AreEqual("404", ex.ErrorCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ public async Task CheckFormTypeinSubmodelAndRecognizedForm(bool labeled)
Assert.AreEqual(form.FormType, model.Submodels.FirstOrDefault().FormType);
}

[RecordedTest]
[ServiceVersion(Max = FormRecognizerClientOptions.ServiceVersion.V2_0)]
public async Task StartCreateComposedModelWithV2()
{
var client = CreateFormTrainingClient();

await using var trainedModelA = await CreateDisposableTrainedModelAsync(useTrainingLabels: true);
await using var trainedModelB = await CreateDisposableTrainedModelAsync(useTrainingLabels: true);

var modelIds = new List<string> { trainedModelA.ModelId, trainedModelB.ModelId };

RequestFailedException ex = Assert.ThrowsAsync<RequestFailedException>(async () => await client.StartCreateComposedModelAsync(modelIds));
Assert.AreEqual("404", ex.ErrorCode);
}

[RecordedTest]
[TestCase(false)]
[TestCase(true)]
Expand Down

0 comments on commit f4f025c

Please sign in to comment.