Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/upgrade_tcgc-2024-6-26-10-43-24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: dependencies
packages:
- "@azure-tools/typespec-python"
---

upgrade to tcgc 0.44.2
10 changes: 5 additions & 5 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.44.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.44.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.44.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.44.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.44.1 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.44.0 <3.0.0",
"@typespec/compiler": ">=0.58.0 <1.0.0",
"@typespec/compiler": ">=0.58.1 <1.0.0",
"@typespec/http": ">=0.58.0 <1.0.0",
"@typespec/rest": ">=0.58.0 <1.0.0",
"@typespec/versioning": ">=0.58.0 <1.0.0",
Expand All @@ -69,7 +69,7 @@
},
"devDependencies": {
"@azure-tools/typespec-azure-resource-manager": "~0.44.0",
"@azure-tools/typespec-autorest": "~0.44.0",
"@azure-tools/typespec-autorest": "~0.44.1",
"@azure-tools/cadl-ranch-expect": "~0.14.1",
"@azure-tools/cadl-ranch-specs": "~0.34.5",
"@types/js-yaml": "~4.0.5",
Expand All @@ -83,8 +83,8 @@
"rimraf": "~5.0.0",
"typescript": "~5.1.3",
"@azure-tools/typespec-azure-core": "~0.44.0",
"@azure-tools/typespec-client-generator-core": "~0.44.1",
"@typespec/compiler": "~0.58.0",
"@azure-tools/typespec-client-generator-core": "~0.44.3",
"@typespec/compiler": "~0.58.1",
"@typespec/http": "~0.58.0",
"@typespec/rest": "~0.58.0",
"@typespec/versioning": "~0.58.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-python/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ function addDefaultOptions(sdkContext: SdkContext) {
}
}

function createPythonSdkContext<TServiceOperation extends SdkServiceOperation>(
async function createPythonSdkContext<TServiceOperation extends SdkServiceOperation>(
context: EmitContext<PythonEmitterOptions>,
): PythonSdkContext<TServiceOperation> {
): Promise<PythonSdkContext<TServiceOperation>> {
return {
...createSdkContext<PythonEmitterOptions, TServiceOperation>(context, "@azure-tools/typespec-python"),
...(await createSdkContext<PythonEmitterOptions, TServiceOperation>(context, "@azure-tools/typespec-python")),
__endpointPathParameters: [],
};
}

export async function $onEmit(context: EmitContext<PythonEmitterOptions>) {
const program = context.program;
const sdkContext = createPythonSdkContext<SdkHttpOperation>(context);
const sdkContext = await createPythonSdkContext<SdkHttpOperation>(context);
const root = path.join(dirname(fileURLToPath(import.meta.url)), "..", "..");
const outputDir = context.emitterOutputDir;
const yamlMap = emitCodeModel(sdkContext);
Expand Down
30 changes: 11 additions & 19 deletions packages/typespec-python/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,7 @@ export function getType<TServiceOperation extends SdkServiceOperation>(
case "decimal":
case "decimal128":
case "string":
case "password":
case "guid":
case "url":
case "uri":
case "uuid":
case "eTag":
case "armId":
case "ipAddress":
case "azureLocation":
return emitBuiltInType(type);
case "any":
return KnownTypes.any;
Expand Down Expand Up @@ -182,19 +174,19 @@ function visibilityMapping(visibility?: Visibility[]): string[] | undefined {

function emitProperty<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
type: SdkBodyModelPropertyType,
property: SdkBodyModelPropertyType,
): Record<string, any> {
return {
clientName: camelToSnakeCase(type.name),
wireName: type.serializedName,
type: getType(context, type.type),
optional: type.optional,
description: type.description,
addedOn: getAddedOn(context, type),
visibility: visibilityMapping(type.visibility),
isDiscriminator: type.discriminator,
flatten: type.flatten,
isMultipartFileInput: type.isMultipartFileInput,
clientName: camelToSnakeCase(property.name),
wireName: property.serializedName,
type: getType(context, property.type),
optional: property.optional,
description: property.description,
addedOn: getAddedOn(context, property),
visibility: visibilityMapping(property.visibility),
isDiscriminator: property.discriminator,
flatten: property.flatten,
isMultipartFileInput: property.isMultipartFileInput,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"client.naming.models.PythonModel": "Client.Naming.Model.ModelWithLanguageClientName",
"client.naming.models.ClientExtensibleEnum": "Client.Naming.UnionEnum.ServerExtensibleEnum",
"client.naming.models.ExtensibleEnum": "Client.Naming.UnionEnum.ExtensibleEnum",
"client.naming.NamingClient.model.client": "Client.Naming.Model.client",
"client.naming.NamingClient.model.language": "Client.Naming.Model.language",
"client.naming.NamingClient.client_model.client": "Client.Naming.Model.client",
"client.naming.NamingClient.client_model.language": "Client.Naming.Model.language",
"client.naming.NamingClient.union_enum.union_enum_name": "Client.Naming.UnionEnum.unionEnumName",
"client.naming.NamingClient.union_enum.union_enum_member_name": "Client.Naming.UnionEnum.unionEnumMemberName",
"client.naming.NamingClient.client_name": "Client.Naming.operation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

from ._configuration import NamingClientConfiguration
from ._serialization import Deserializer, Serializer
from .operations import ModelOperations, NamingClientOperationsMixin, UnionEnumOperations
from .operations import ClientModelOperations, NamingClientOperationsMixin, UnionEnumOperations


class NamingClient(NamingClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
"""Describe changing names of types in a client with ``@clientName``.

:ivar model: ModelOperations operations
:vartype model: client.naming.operations.ModelOperations
:ivar client_model: ClientModelOperations operations
:vartype client_model: client.naming.operations.ClientModelOperations
:ivar union_enum: UnionEnumOperations operations
:vartype union_enum: client.naming.operations.UnionEnumOperations
:keyword endpoint: Service host. Default value is "http://localhost:3000".
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.model = ModelOperations(self._client, self._config, self._serialize, self._deserialize)
self.client_model = ClientModelOperations(self._client, self._config, self._serialize, self._deserialize)
Comment thread
tadelesh marked this conversation as resolved.
self.union_enum = UnionEnumOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

from .._serialization import Deserializer, Serializer
from ._configuration import NamingClientConfiguration
from .operations import ModelOperations, NamingClientOperationsMixin, UnionEnumOperations
from .operations import ClientModelOperations, NamingClientOperationsMixin, UnionEnumOperations


class NamingClient(NamingClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
"""Describe changing names of types in a client with ``@clientName``.

:ivar model: ModelOperations operations
:vartype model: client.naming.aio.operations.ModelOperations
:ivar client_model: ClientModelOperations operations
:vartype client_model: client.naming.aio.operations.ClientModelOperations
:ivar union_enum: UnionEnumOperations operations
:vartype union_enum: client.naming.aio.operations.UnionEnumOperations
:keyword endpoint: Service host. Default value is "http://localhost:3000".
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.model = ModelOperations(self._client, self._config, self._serialize, self._deserialize)
self.client_model = ClientModelOperations(self._client, self._config, self._serialize, self._deserialize)
self.union_enum = UnionEnumOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(
Expand Down
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 ._operations import ModelOperations
from ._operations import ClientModelOperations
from ._operations import UnionEnumOperations
from ._operations import NamingClientOperationsMixin

Expand All @@ -15,7 +15,7 @@
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"ModelOperations",
"ClientModelOperations",
"UnionEnumOperations",
"NamingClientOperationsMixin",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from ... import models as _models
from ..._model_base import SdkJSONEncoder
from ...operations._operations import (
build_model_client_request,
build_model_language_request,
build_client_model_client_request,
build_client_model_language_request,
build_naming_client_name_request,
build_naming_client_request,
build_naming_compatible_with_encoded_name_request,
Expand All @@ -50,14 +50,14 @@
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]


class ModelOperations:
class ClientModelOperations:
"""
.. warning::
**DO NOT** instantiate this class directly.

Instead, you should access the following operations through
:class:`~client.naming.aio.NamingClient`'s
:attr:`model` attribute.
:attr:`client_model` attribute.
"""

def __init__(self, *args, **kwargs) -> None:
Expand Down Expand Up @@ -164,7 +164,7 @@ async def client( # pylint: disable=inconsistent-return-statements
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_model_client_request(
_request = build_client_model_client_request(
content_type=content_type,
content=_content,
headers=_headers,
Expand Down Expand Up @@ -283,7 +283,7 @@ async def language( # pylint: disable=inconsistent-return-statements
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_model_language_request(
_request = build_client_model_language_request(
content_type=content_type,
content=_content,
headers=_headers,
Expand Down
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 ._operations import ModelOperations
from ._operations import ClientModelOperations
from ._operations import UnionEnumOperations
from ._operations import NamingClientOperationsMixin

Expand All @@ -15,7 +15,7 @@
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"ModelOperations",
"ClientModelOperations",
"UnionEnumOperations",
"NamingClientOperationsMixin",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
_SERIALIZER.client_side_validation = False


def build_model_client_request(**kwargs: Any) -> HttpRequest:
def build_client_model_client_request(**kwargs: Any) -> HttpRequest:
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
Expand All @@ -55,7 +55,7 @@ def build_model_client_request(**kwargs: Any) -> HttpRequest:
return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)


def build_model_language_request(**kwargs: Any) -> HttpRequest:
def build_client_model_language_request(**kwargs: Any) -> HttpRequest:
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
Expand Down Expand Up @@ -175,14 +175,14 @@ def build_naming_response_request(**kwargs: Any) -> HttpRequest:
return HttpRequest(method="GET", url=_url, **kwargs)


class ModelOperations:
class ClientModelOperations:
"""
.. warning::
**DO NOT** instantiate this class directly.

Instead, you should access the following operations through
:class:`~client.naming.NamingClient`'s
:attr:`model` attribute.
:attr:`client_model` attribute.
"""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -289,7 +289,7 @@ def client( # pylint: disable=inconsistent-return-statements
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_model_client_request(
_request = build_client_model_client_request(
content_type=content_type,
content=_content,
headers=_headers,
Expand Down Expand Up @@ -408,7 +408,7 @@ def language( # pylint: disable=inconsistent-return-statements
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_model_language_request(
_request = build_client_model_language_request(
content_type=content_type,
content=_content,
headers=_headers,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils import recorded_by_proxy
from testpreparer import NamingClientTestBase, NamingPreparer


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestNamingClientModelOperations(NamingClientTestBase):
@NamingPreparer()
@recorded_by_proxy
def test_client(self, naming_endpoint):
client = self.create_client(endpoint=naming_endpoint)
response = client.client_model.client(
body={"defaultName": bool},
)

# please add some check logic here by yourself
# ...

@NamingPreparer()
@recorded_by_proxy
def test_language(self, naming_endpoint):
client = self.create_client(endpoint=naming_endpoint)
response = client.client_model.language(
body={"defaultName": bool},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils.aio import recorded_by_proxy_async
from testpreparer import NamingPreparer
from testpreparer_async import NamingClientTestBaseAsync


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestNamingClientModelOperationsAsync(NamingClientTestBaseAsync):
@NamingPreparer()
@recorded_by_proxy_async
async def test_client(self, naming_endpoint):
client = self.create_async_client(endpoint=naming_endpoint)
response = await client.client_model.client(
body={"defaultName": bool},
)

# please add some check logic here by yourself
# ...

@NamingPreparer()
@recorded_by_proxy_async
async def test_language(self, naming_endpoint):
client = self.create_async_client(endpoint=naming_endpoint)
response = await client.client_model.language(
body={"defaultName": bool},
)

# please add some check logic here by yourself
# ...
Loading