Skip to content

Commit

Permalink
[formrecognizer] Update generated code for preview.3 (#16833)
Browse files Browse the repository at this point in the history
* Adding generated code

* update api-version dependent code

* update test_receipt.py recordings

* update generated code

* update msrest dependency, add pages to custom form calls

* skipping tests for undeployed endpoints

* update pages doc comment

* fix async operations and testcase handling

* clean up response urls

* adding content recordings

* adding invoice test recordings

* adding receipt recordings

* update multiapi tests

* update testcase and recordings

* updating mgmt tests

* update msrest requirement

* update async client
  • Loading branch information
catalinaperalta authored Mar 5, 2021
1 parent 622b1e8 commit 40813ad
Show file tree
Hide file tree
Showing 218 changed files with 16,202 additions and 10,421 deletions.
3 changes: 3 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 3.1.0b4 (Unreleased)

**Dependency Updates**

- Bumped `msrest` requirement from `0.6.12` to `0.6.21`.

## 3.1.0b3 (2021-02-09)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FormRecognizerApiVersion(str, Enum):
"""Form Recognizer API versions supported by this package"""

#: This is the default version
V2_1_PREVIEW = "2.1-preview.2"
V2_1_PREVIEW = "2.1-preview.3"
V2_0 = "2.0"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ def begin_recognize_receipts(self, receipt, **kwargs):
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword str locale: Locale of the receipt. Supported locales include: en-US, en-AU, en-CA, en-GB,
and en-IN.
:keyword list[str] pages: Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
`pages=["1-3", "5-6"]`. Separate each page number or range with a comma.
:return: An instance of an LROPoller. Call `result()` on the poller
object to return a list[:class:`~azure.ai.formrecognizer.RecognizedForm`].
:rtype: ~azure.core.polling.LROPoller[list[~azure.ai.formrecognizer.RecognizedForm]]
:raises ~azure.core.exceptions.HttpResponseError:
.. versionadded:: v2.1-preview
The *locale* keyword argument and support for image/bmp content
The *locale* and *pages* keyword arguments and support for image/bmp content
.. admonition:: Example:
Expand All @@ -110,6 +113,7 @@ def begin_recognize_receipts(self, receipt, **kwargs):
:caption: Recognize sales receipt fields.
"""
locale = kwargs.pop("locale", None)
pages = kwargs.pop("pages", None)
content_type = kwargs.pop("content_type", None)
include_field_elements = kwargs.pop("include_field_elements", False)
if content_type == "application/json":
Expand All @@ -129,7 +133,15 @@ def begin_recognize_receipts(self, receipt, **kwargs):
raise ValueError(
"'locale' is only available for API version V2_1_PREVIEW and up"
)

# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1_PREVIEW and up"
)
return self._client.begin_analyze_receipt_async( # type: ignore
file_stream=receipt,
content_type=content_type,
Expand Down Expand Up @@ -158,13 +170,16 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs):
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword str locale: Locale of the receipt. Supported locales include: en-US, en-AU, en-CA, en-GB,
and en-IN.
:keyword list[str] pages: Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
`pages=["1-3", "5-6"]`. Separate each page number or range with a comma.
:return: An instance of an LROPoller. Call `result()` on the poller
object to return a list[:class:`~azure.ai.formrecognizer.RecognizedForm`].
:rtype: ~azure.core.polling.LROPoller[list[~azure.ai.formrecognizer.RecognizedForm]]
:raises ~azure.core.exceptions.HttpResponseError:
.. versionadded:: v2.1-preview
The *locale* keyword argument and support for image/bmp content
The *locale* and *pages* keyword arguments and support for image/bmp content
.. admonition:: Example:
Expand All @@ -176,6 +191,7 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs):
:caption: Recognize sales receipt fields from a URL.
"""
locale = kwargs.pop("locale", None)
pages = kwargs.pop("pages", None)
include_field_elements = kwargs.pop("include_field_elements", False)
cls = kwargs.pop("cls", self._prebuilt_callback)

Expand All @@ -188,6 +204,15 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs):
raise ValueError(
"'locale' is only available for API version V2_1_PREVIEW and up"
)
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1_PREVIEW and up"
)
return self._client.begin_analyze_receipt_async( # type: ignore
file_stream={"source": receipt_url},
include_text_details=include_field_elements,
Expand Down Expand Up @@ -584,6 +609,9 @@ def begin_recognize_custom_forms(self, model_id, form, **kwargs):
auto-detected, but can be overridden by passing this keyword argument. For options,
see :class:`~azure.ai.formrecognizer.FormContentType`.
:paramtype content_type: str or ~azure.ai.formrecognizer.FormContentType
:keyword list[str] pages: Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
`pages=["1-3", "5-6"]`. Separate each page number or range with a comma.
:keyword int polling_interval: Waiting time between two polls for LRO operations
if no Retry-After header is present. Defaults to 5 seconds.
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
Expand All @@ -605,6 +633,16 @@ def begin_recognize_custom_forms(self, model_id, form, **kwargs):
if not model_id:
raise ValueError("model_id cannot be None or empty.")

pages = kwargs.pop("pages", None)
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1_PREVIEW and up"
)
polling_interval = kwargs.pop(
"polling_interval", self._client._config.polling_interval
)
Expand Down Expand Up @@ -653,6 +691,9 @@ def begin_recognize_custom_forms_from_url(self, model_id, form_url, **kwargs):
:keyword bool include_field_elements:
Whether or not to include all lines per page and field elements such as lines, words,
and selection marks for each form field.
:keyword list[str] pages: Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
`pages=["1-3", "5-6"]`. Separate each page number or range with a comma.
:keyword int polling_interval: Waiting time between two polls for LRO operations
if no Retry-After header is present. Defaults to 5 seconds.
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
Expand All @@ -665,6 +706,16 @@ def begin_recognize_custom_forms_from_url(self, model_id, form_url, **kwargs):
if not model_id:
raise ValueError("model_id cannot be None or empty.")

pages = kwargs.pop("pages", None)
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1_PREVIEW and up"
)
polling_interval = kwargs.pop(
"polling_interval", self._client._config.polling_interval
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from typing import Any
from typing import TYPE_CHECKING

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

from ._version import VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any

from azure.core.credentials import TokenCredential

class FormRecognizerClientConfiguration(Configuration):
"""Configuration for FormRecognizerClient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
# regenerated.
# --------------------------------------------------------------------------

from azure.core import PipelineClient
from msrest import Serializer, Deserializer
from typing import TYPE_CHECKING

from azure.core import PipelineClient
from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from msrest import Deserializer, Serializer

from ._configuration import FormRecognizerClientConfiguration
from ._operations_mixin import FormRecognizerClientOperationsMixin

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional

from azure.core.credentials import TokenCredential

class _SDKClient(object):
def __init__(self, *args, **kwargs):
"""This is a fake class to support current implemetation of MultiApiClientMixin."
Expand All @@ -38,14 +47,14 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
:type credential: ~azure.core.credentials.TokenCredential
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
:type endpoint: str
:param str api_version: API version to use if no profile is provided, or if
missing in profile.
:param api_version: API version to use if no profile is provided, or if missing in profile.
:type api_version: str
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

DEFAULT_API_VERSION = '2.1-preview.2'
DEFAULT_API_VERSION = '2.1-preview.3'
_PROFILE_TAG = "azure.ai.formrecognizer.FormRecognizerClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
Expand All @@ -58,14 +67,14 @@ def __init__(
self,
credential, # type: "TokenCredential"
endpoint, # type: str
api_version=None,
profile=KnownProfiles.default,
api_version=None, # type: Optional[str]
profile=KnownProfiles.default, # type: KnownProfiles
**kwargs # type: Any
):
if api_version == '2.0':
base_url = '{endpoint}/formrecognizer/v2.0'
elif api_version == '2.1-preview.2':
base_url = '{endpoint}/formrecognizer/v2.1-preview.2'
elif api_version == '2.1-preview.3':
base_url = '{endpoint}/formrecognizer/v2.1-preview.3'
else:
raise ValueError("API version {} is not available".format(api_version))
self._config = FormRecognizerClientConfiguration(credential, endpoint, **kwargs)
Expand All @@ -84,13 +93,13 @@ def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 2.0: :mod:`v2_0.models<azure.ai.formrecognizer.v2_0.models>`
* 2.1-preview.2: :mod:`v2_1_preview_2.models<azure.ai.formrecognizer.v2_1_preview_2.models>`
* 2.1-preview.3: :mod:`v2_1_preview_3.models<azure.ai.formrecognizer.v2_1_preview_3.models>`
"""
if api_version == '2.0':
from .v2_0 import models
return models
elif api_version == '2.1-preview.2':
from .v2_1_preview_2 import models
elif api_version == '2.1-preview.3':
from .v2_1_preview_3 import models
return models
raise ValueError("API version {} is not available".format(api_version))

Expand Down
Loading

0 comments on commit 40813ad

Please sign in to comment.