Skip to content

Commit

Permalink
CodeGen from PR 24323 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
[AI.TextTranslation] Disambiguate example titles (Azure#24323)

- Causes error in TypeSpec 0.45.0
- Also change casing of textType in example to match spec
  - Fixes error ENUM_CASE_MISMATCH in Swagger ModelValidation
  • Loading branch information
SDKAuto committed Jun 6, 2023
1 parent c571872 commit 988351d
Show file tree
Hide file tree
Showing 27 changed files with 706 additions and 673 deletions.
15 changes: 15 additions & 0 deletions sdk/translation/azure-ai-translation-text/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"commit": "aa1f08c2bfb9bef613f963aaf971a25558151330",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/translation/Azure.AI.TextTranslation",
"@azure-tools/typespec-python": {
"version": "0.8.6",
"resolved": "https://registry.npmjs.org/@azure-tools/typespec-python/-/typespec-python-0.8.6.tgz",
"dependencies": {
"@autorest/python": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/@autorest/python/-/python-6.5.0.tgz"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._patch import TextTranslationClient
from ._client import TextTranslationClient
from ._version import VERSION

__version__ = VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class TextTranslationClient(TextTranslationClientOperationsMixin): # pylint: di
:param endpoint: Supported Text Translation endpoints (protocol and hostname, for example:
https://api.cognitive.microsofttranslator.com). Required.
:type endpoint: str
:keyword api_version: Default value is "3.0". Note that overriding this default value may
result in unsupported behavior.
:keyword api_version: Mandatory API version parameter. Default value is "3.0". Note that
overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

import sys
from typing import Any

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

from ._version import VERSION

if sys.version_info >= (3, 8):
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
else:
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports


class TextTranslationClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
"""Configuration for TextTranslationClient.
Expand All @@ -29,14 +23,14 @@ class TextTranslationClientConfiguration(Configuration): # pylint: disable=too-
:param endpoint: Supported Text Translation endpoints (protocol and hostname, for example:
https://api.cognitive.microsofttranslator.com). Required.
:type endpoint: str
:keyword api_version: Default value is "3.0". Note that overriding this default value may
result in unsupported behavior.
:keyword api_version: Mandatory API version parameter. Default value is "3.0". Note that
overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, **kwargs: Any) -> None:
super(TextTranslationClientConfiguration, self).__init__(**kwargs)
api_version: Literal["3.0"] = kwargs.pop("api_version", "3.0")
api_version: str = kwargs.pop("api_version", "3.0")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from azure.core.exceptions import DeserializationError
from azure.core import CaseInsensitiveEnumMeta
from azure.core.pipeline import PipelineResponse
from azure.core.serialization import NULL as AzureCoreNull
from azure.core.serialization import _Null # pylint: disable=protected-access

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
Expand All @@ -29,24 +29,9 @@

_LOGGER = logging.getLogger(__name__)

__all__ = ["NULL", "AzureJSONEncoder", "Model", "rest_field", "rest_discriminator"]
__all__ = ["AzureJSONEncoder", "Model", "rest_field", "rest_discriminator"]


class _Null(object):
"""To create a Falsy object"""

def __bool__(self):
return False

__nonzero__ = __bool__ # Python2 compatibility


NULL = _Null()
"""
A falsy sentinel object which is supposed to be used to specify attributes
with no data. This gets serialized to `null` on the wire.
"""

TZ_UTC = timezone.utc


Expand Down Expand Up @@ -74,32 +59,35 @@ def _timedelta_as_isostr(td: timedelta) -> str:
if days:
date_str = "%sD" % days

# Build time
time_str = "T"
if hours or minutes or seconds:
# Build time
time_str = "T"

# Hours
bigger_exists = date_str or hours
if bigger_exists:
time_str += "{:02}H".format(hours)
# Hours
bigger_exists = date_str or hours
if bigger_exists:
time_str += "{:02}H".format(hours)

# Minutes
bigger_exists = bigger_exists or minutes
if bigger_exists:
time_str += "{:02}M".format(minutes)
# Minutes
bigger_exists = bigger_exists or minutes
if bigger_exists:
time_str += "{:02}M".format(minutes)

# Seconds
try:
if seconds.is_integer():
seconds_string = "{:02}".format(int(seconds))
else:
# 9 chars long w/ leading 0, 6 digits after decimal
seconds_string = "%09.6f" % seconds
# Remove trailing zeros
seconds_string = seconds_string.rstrip("0")
except AttributeError: # int.is_integer() raises
seconds_string = "{:02}".format(seconds)
# Seconds
try:
if seconds.is_integer():
seconds_string = "{:02}".format(int(seconds))
else:
# 9 chars long w/ leading 0, 6 digits after decimal
seconds_string = "%09.6f" % seconds
# Remove trailing zeros
seconds_string = seconds_string.rstrip("0")
except AttributeError: # int.is_integer() raises
seconds_string = "{:02}".format(seconds)

time_str += "{}S".format(seconds_string)
time_str += "{}S".format(seconds_string)
else:
time_str = ""

return "P" + date_str + time_str

Expand Down Expand Up @@ -166,7 +154,7 @@ def default(self, o): # pylint: disable=too-many-return-statements
return {k: v for k, v in o.items() if k not in readonly_props}
if isinstance(o, (bytes, bytearray)):
return base64.b64encode(o).decode()
if o is AzureCoreNull:
if isinstance(o, _Null):
return None
try:
return super(AzureJSONEncoder, self).default(o)
Expand Down Expand Up @@ -425,7 +413,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
if non_attr_kwargs:
# actual type errors only throw the first wrong keyword arg they see, so following that.
raise TypeError(f"{class_name}.__init__() got an unexpected keyword argument '{non_attr_kwargs[0]}'")
dict_to_pass.update({self._attr_to_rest_field[k]._rest_name: _serialize(v) for k, v in kwargs.items()})
dict_to_pass.update(
{self._attr_to_rest_field[k]._rest_name: _serialize(v) for k, v in kwargs.items() if v is not None}
)
super().__init__(dict_to_pass)

def copy(self) -> "Model":
Expand Down Expand Up @@ -653,7 +643,7 @@ def __init__(
self,
*,
name: typing.Optional[str] = None,
type: typing.Optional[typing.Callable] = None,
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
is_discriminator: bool = False,
readonly: bool = False,
default: typing.Any = _UNSET,
Expand All @@ -672,7 +662,7 @@ def _rest_name(self) -> str:
raise ValueError("Rest name was never set")
return self._rest_name_input

def __get__(self, obj: Model, type=None):
def __get__(self, obj: Model, type=None): # pylint: disable=redefined-builtin
# by this point, type and rest_name will have a value bc we default
# them in __new__ of the Model class
item = obj.get(self._rest_name)
Expand Down Expand Up @@ -701,14 +691,16 @@ def _get_deserialize_callable_from_annotation(
def rest_field(
*,
name: typing.Optional[str] = None,
type: typing.Optional[typing.Callable] = None,
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
readonly: bool = False,
default: typing.Any = _UNSET,
) -> typing.Any:
return _RestField(name=name, type=type, readonly=readonly, default=default)


def rest_discriminator(
*, name: typing.Optional[str] = None, type: typing.Optional[typing.Callable] = None
*,
name: typing.Optional[str] = None,
type: typing.Optional[typing.Callable] = None, # pylint: disable=redefined-builtin
) -> typing.Any:
return _RestField(name=name, type=type, is_discriminator=True)
Loading

0 comments on commit 988351d

Please sign in to comment.