Skip to content

Commit

Permalink
[formrecognizer] Regenerate with latest swagger (#28668)
Browse files Browse the repository at this point in the history
* regenerate code on latest preview

* update regen

* update references to new api version+generated code

* update tests

* regen with latest updates

* update operations mixin

* update internal refs

* update swagger readme

* update tests

* update async refs

* rename admin operations

* update internal refs dmac

* regen with latest swagger

* update internal operation refs

* update version

* update sdk version in changelog

* regenerate

* update swagger readme

* update refs

* update assets.json

* update assets.json

* update swagger readme

* regen

* support multiapi in convenience layer

* add ga version back in

* update compose

* update internal method refs

* update async list operations
  • Loading branch information
catalinaperalta authored Mar 17, 2023
1 parent b62e8e7 commit 7957864
Show file tree
Hide file tree
Showing 65 changed files with 9,315 additions and 79 deletions.
2 changes: 1 addition & 1 deletion sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 3.2.2 (Unreleased)
## 3.3.0b1 (Unreleased)

### Features Added

Expand Down
2 changes: 1 addition & 1 deletion sdk/formrecognizer/azure-ai-formrecognizer/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/formrecognizer/azure-ai-formrecognizer",
"Tag": "python/formrecognizer/azure-ai-formrecognizer_153a841398"
"Tag": "python/formrecognizer/azure-ai-formrecognizer_2e1ce3f599"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DocumentAnalysisApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Form Recognizer API versions supported by DocumentAnalysisClient and DocumentModelAdministrationClient."""

#: This is the default version
V2023_02_28_PREVIEW = "2023-02-28-preview"
V2022_08_31 = "2022-08-31"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DocumentAnalysisClient(FormRecognizerClientBase):
"""

def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any) -> None:
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2022_08_31)
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2023_02_28_PREVIEW)
super().__init__(
endpoint=endpoint, credential=credential, api_version=api_version, client_kind="document", **kwargs
)
Expand Down Expand Up @@ -110,7 +110,10 @@ def begin_analyze_document(
continuation_token = kwargs.pop("continuation_token", None)

if continuation_token is not None:
return self._client.begin_analyze_document( # type: ignore
_client_op_path = self._client.document_models
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client
return _client_op_path.begin_analyze_document( # type: ignore
model_id=model_id,
analyze_request=document, # type: ignore
content_type="application/octet-stream",
Expand All @@ -123,7 +126,10 @@ def begin_analyze_document(
if not model_id:
raise ValueError("model_id cannot be None or empty.")

return self._client.begin_analyze_document( # type: ignore
_client_op_path = self._client.document_models
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client
return _client_op_path.begin_analyze_document( # type: ignore
model_id=model_id,
analyze_request=document, # type: ignore
content_type="application/octet-stream",
Expand Down Expand Up @@ -171,7 +177,10 @@ def begin_analyze_document_from_url(
# continuation token requests do not perform the same value checks as
# regular analysis requests
if continuation_token is not None:
return self._client.begin_analyze_document( # type: ignore
_client_op_path = self._client.document_models
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client
return _client_op_path.begin_analyze_document( # type: ignore
model_id=model_id,
analyze_request={"urlSource": document_url}, # type: ignore
string_index_type="unicodeCodePoint",
Expand All @@ -189,7 +198,10 @@ def begin_analyze_document_from_url(
"Please see `begin_analyze_document()` to pass a byte stream."
)

return self._client.begin_analyze_document( # type: ignore
_client_op_path = self._client.document_models
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client
return _client_op_path.begin_analyze_document( # type: ignore
model_id=model_id,
analyze_request={"urlSource": document_url}, # type: ignore
string_index_type="unicodeCodePoint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DocumentModelAdministrationClient(FormRecognizerClientBase):
"""

def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any) -> None:
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2022_08_31)
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2023_02_28_PREVIEW)
super().__init__(
endpoint=endpoint, credential=credential, api_version=api_version, client_kind="document", **kwargs
)
Expand Down Expand Up @@ -143,7 +143,10 @@ def callback(raw_response, _, headers): # pylint: disable=unused-argument
if model_id is None:
model_id = str(uuid.uuid4())

return self._client.begin_build_document_model( # type: ignore
_client_op_path = self._client.document_models.begin_build_model
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.begin_build_document_model
return _client_op_path( # type: ignore
build_request=self._generated_models.BuildDocumentModelRequest(
model_id=model_id,
build_mode=build_mode,
Expand Down Expand Up @@ -207,7 +210,10 @@ def _compose_callback(raw_response, _, headers): # pylint: disable=unused-argum
if model_id is None:
model_id = str(uuid.uuid4())

return self._client.begin_compose_document_model( # type: ignore
_client_op_path = self._client.document_models.begin_compose_model
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.begin_compose_document_model
return _client_op_path( # type: ignore
compose_request=self._generated_models.ComposeDocumentModelRequest(
model_id=model_id,
description=description,
Expand Down Expand Up @@ -251,7 +257,10 @@ def get_copy_authorization(self, **kwargs: Any) -> TargetAuthorization:
if model_id is None:
model_id = str(uuid.uuid4())

response = self._client.authorize_copy_document_model(
_client_op_path = self._client.document_models.authorize_model_copy
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.authorize_copy_document_model
response = _client_op_path(
authorize_copy_request=self._generated_models.AuthorizeCopyRequest(
model_id=model_id, description=description, tags=tags
),
Expand Down Expand Up @@ -301,7 +310,10 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument
polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval)
continuation_token = kwargs.pop("continuation_token", None)

return self._client.begin_copy_document_model_to( # type: ignore
_client_op_path = self._client.document_models.begin_copy_model_to
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.begin_copy_document_model_to
return _client_op_path( # type: ignore
model_id=model_id,
copy_to_request=self._generated_models.CopyAuthorization(
target_resource_id=target["targetResourceId"],
Expand Down Expand Up @@ -343,7 +355,10 @@ def delete_document_model(self, model_id: str, **kwargs: Any) -> None:
if not model_id:
raise ValueError("model_id cannot be None or empty.")

return self._client.delete_document_model(model_id=model_id, **kwargs)
_client_op_path = self._client.document_models.delete_model
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.delete_document_model
return _client_op_path(model_id=model_id, **kwargs)

@distributed_trace
def list_document_models(self, **kwargs: Any) -> ItemPaged[DocumentModelSummary]:
Expand All @@ -364,7 +379,10 @@ def list_document_models(self, **kwargs: Any) -> ItemPaged[DocumentModelSummary]
:caption: List all models that were built successfully under the Form Recognizer resource.
"""

return self._client.get_document_models( # type: ignore
_client_op_path = self._client.document_models.list_models
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.get_document_models
return _client_op_path( # type: ignore
cls=kwargs.pop(
"cls",
lambda objs: [DocumentModelSummary._from_generated(x) for x in objs],
Expand All @@ -390,7 +408,10 @@ def get_resource_details(self, **kwargs: Any) -> ResourceDetails:
:caption: Get model counts and limits under the Form Recognizer resource.
"""

response = self._client.get_resource_details(**kwargs)
_client_op_path = self._client.miscellaneous.get_resource_info
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.get_resource_details
response = _client_op_path(**kwargs)
return ResourceDetails._from_generated(response.custom_document_models)

@distributed_trace
Expand All @@ -415,7 +436,10 @@ def get_document_model(self, model_id: str, **kwargs: Any) -> DocumentModelDetai
if not model_id:
raise ValueError("model_id cannot be None or empty.")

response = self._client.get_document_model(model_id=model_id, **kwargs)
_client_op_path = self._client.document_models.get_model
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.get_document_model
response = _client_op_path(model_id=model_id, **kwargs)
return DocumentModelDetails._from_generated(response)

@distributed_trace
Expand All @@ -440,7 +464,10 @@ def list_operations(self, **kwargs: Any) -> ItemPaged[OperationSummary]:
:caption: List all document model operations in the past 24 hours.
"""

return self._client.get_operations( # type: ignore
_client_op_path = self._client.miscellaneous.list_operations
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.get_operations
return _client_op_path( # type: ignore
cls=kwargs.pop(
"cls",
lambda objs: [OperationSummary._from_generated(x) for x in objs],
Expand Down Expand Up @@ -474,8 +501,11 @@ def get_operation(self, operation_id: str, **kwargs: Any) -> OperationDetails:
if not operation_id:
raise ValueError("'operation_id' cannot be None or empty.")

_client_op_path = self._client.miscellaneous.get_operation
if self._api_version == DocumentAnalysisApiVersion.V2022_08_31:
_client_op_path = self._client.get_operation
return OperationDetails._from_generated(
self._client.get_operation(operation_id, **kwargs),
_client_op_path(operation_id, **kwargs),
api_version=self._api_version,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
'begin_compose_document_model': '2022-08-31',
'begin_copy_document_model_to': '2022-08-31',
'delete_document_model': '2022-08-31',
'document_classifiers': '2023-02-28-preview',
'document_models': '2023-02-28-preview',
'get_analyze_document_result': '2022-08-31',
'get_document_model': '2022-08-31',
'get_document_models': '2022-08-31',
'get_operation': '2022-08-31',
'get_operations': '2022-08-31',
'get_resource_details': '2022-08-31',
'miscellaneous': '2023-02-28-preview',
'train_custom_model_async': '2.0',
}},
_PROFILE_TAG + " latest"
Expand All @@ -85,7 +88,7 @@ def __init__(
profile=KnownProfiles.default, # type: KnownProfiles
**kwargs # type: Any
):
if api_version == '2022-08-31':
if api_version == '2022-08-31' or api_version == '2023-02-28-preview':
base_url = '{endpoint}/formrecognizer'
elif api_version == '2.0':
base_url = '{endpoint}/formrecognizer/v2.0'
Expand All @@ -109,12 +112,16 @@ def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 2022-08-31: :mod:`v2022_08_31.models<azure.ai.formrecognizer.v2022_08_31.models>`
* 2023-02-28-preview: :mod:`v2023_02_28_preview.models<azure.ai.formrecognizer.v2023_02_28_preview.models>`
* 2.0: :mod:`v2_0.models<azure.ai.formrecognizer.v2_0.models>`
* 2.1: :mod:`v2_1.models<azure.ai.formrecognizer.v2_1.models>`
"""
if api_version == '2022-08-31':
from .v2022_08_31 import models
return models
elif api_version == '2023-02-28-preview':
from .v2023_02_28_preview import models
return models
elif api_version == '2.0':
from .v2_0 import models
return models
Expand All @@ -123,6 +130,45 @@ def models(cls, api_version=DEFAULT_API_VERSION):
return models
raise ValueError("API version {} is not available".format(api_version))

@property
def document_classifiers(self):
"""Instance depends on the API version:
* 2023-02-28-preview: :class:`DocumentClassifiersOperations<azure.ai.formrecognizer.v2023_02_28_preview.operations.DocumentClassifiersOperations>`
"""
api_version = self._get_api_version('document_classifiers')
if api_version == '2023-02-28-preview':
from .v2023_02_28_preview.operations import DocumentClassifiersOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'document_classifiers'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

@property
def document_models(self):
"""Instance depends on the API version:
* 2023-02-28-preview: :class:`DocumentModelsOperations<azure.ai.formrecognizer.v2023_02_28_preview.operations.DocumentModelsOperations>`
"""
api_version = self._get_api_version('document_models')
if api_version == '2023-02-28-preview':
from .v2023_02_28_preview.operations import DocumentModelsOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'document_models'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

@property
def miscellaneous(self):
"""Instance depends on the API version:
* 2023-02-28-preview: :class:`MiscellaneousOperations<azure.ai.formrecognizer.v2023_02_28_preview.operations.MiscellaneousOperations>`
"""
api_version = self._get_api_version('miscellaneous')
if api_version == '2023-02-28-preview':
from .v2023_02_28_preview.operations import MiscellaneousOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'miscellaneous'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

def close(self):
self._client.close()
def __enter__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
'begin_compose_document_model': '2022-08-31',
'begin_copy_document_model_to': '2022-08-31',
'delete_document_model': '2022-08-31',
'document_classifiers': '2023-02-28-preview',
'document_models': '2023-02-28-preview',
'get_analyze_document_result': '2022-08-31',
'get_document_model': '2022-08-31',
'get_document_models': '2022-08-31',
'get_operation': '2022-08-31',
'get_operations': '2022-08-31',
'get_resource_details': '2022-08-31',
'miscellaneous': '2023-02-28-preview',
'train_custom_model_async': '2.0',
}},
_PROFILE_TAG + " latest"
Expand All @@ -84,7 +87,7 @@ def __init__(
profile: KnownProfiles = KnownProfiles.default,
**kwargs # type: Any
) -> None:
if api_version == '2022-08-31':
if api_version == '2022-08-31' or api_version == '2023-02-28-preview':
base_url = '{endpoint}/formrecognizer'
elif api_version == '2.0':
base_url = '{endpoint}/formrecognizer/v2.0'
Expand All @@ -108,12 +111,16 @@ def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 2022-08-31: :mod:`v2022_08_31.models<azure.ai.formrecognizer.v2022_08_31.models>`
* 2023-02-28-preview: :mod:`v2023_02_28_preview.models<azure.ai.formrecognizer.v2023_02_28_preview.models>`
* 2.0: :mod:`v2_0.models<azure.ai.formrecognizer.v2_0.models>`
* 2.1: :mod:`v2_1.models<azure.ai.formrecognizer.v2_1.models>`
"""
if api_version == '2022-08-31':
from ..v2022_08_31 import models
return models
elif api_version == '2023-02-28-preview':
from ..v2023_02_28_preview import models
return models
elif api_version == '2.0':
from ..v2_0 import models
return models
Expand All @@ -122,6 +129,45 @@ def models(cls, api_version=DEFAULT_API_VERSION):
return models
raise ValueError("API version {} is not available".format(api_version))

@property
def document_classifiers(self):
"""Instance depends on the API version:
* 2023-02-28-preview: :class:`DocumentClassifiersOperations<azure.ai.formrecognizer.v2023_02_28_preview.aio.operations.DocumentClassifiersOperations>`
"""
api_version = self._get_api_version('document_classifiers')
if api_version == '2023-02-28-preview':
from ..v2023_02_28_preview.aio.operations import DocumentClassifiersOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'document_classifiers'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

@property
def document_models(self):
"""Instance depends on the API version:
* 2023-02-28-preview: :class:`DocumentModelsOperations<azure.ai.formrecognizer.v2023_02_28_preview.aio.operations.DocumentModelsOperations>`
"""
api_version = self._get_api_version('document_models')
if api_version == '2023-02-28-preview':
from ..v2023_02_28_preview.aio.operations import DocumentModelsOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'document_models'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

@property
def miscellaneous(self):
"""Instance depends on the API version:
* 2023-02-28-preview: :class:`MiscellaneousOperations<azure.ai.formrecognizer.v2023_02_28_preview.aio.operations.MiscellaneousOperations>`
"""
api_version = self._get_api_version('miscellaneous')
if api_version == '2023-02-28-preview':
from ..v2023_02_28_preview.aio.operations import MiscellaneousOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'miscellaneous'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

async def close(self):
await self._client.close()
async def __aenter__(self):
Expand Down
Loading

0 comments on commit 7957864

Please sign in to comment.