From b1d637730efc14ecf35a0a7e9a14f03360e2757c Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:24:32 +0800 Subject: [PATCH 1/3] change endpoint to base_url to avoid breaking --- .../typespec-python/scripts/regenerate.ts | 6 +-- packages/typespec-python/src/types.ts | 4 +- .../commontypes/managedidentity/_client.py | 10 ++--- .../managedidentity/_configuration.py | 8 ++-- .../managedidentity/aio/_client.py | 10 ++--- .../managedidentity/aio/_configuration.py | 8 ++-- .../aio/operations/_operations.py | 6 +-- .../managedidentity/operations/_operations.py | 6 +-- .../models/resources/_client.py | 10 ++--- .../models/resources/_configuration.py | 8 ++-- .../models/resources/aio/_client.py | 10 ++--- .../models/resources/aio/_configuration.py | 8 ++-- .../resources/aio/operations/_operations.py | 40 +++++++++---------- .../resources/operations/_operations.py | 40 +++++++++---------- 14 files changed, 88 insertions(+), 86 deletions(-) diff --git a/packages/typespec-python/scripts/regenerate.ts b/packages/typespec-python/scripts/regenerate.ts index ede0c8949f1..10873ba4873 100644 --- a/packages/typespec-python/scripts/regenerate.ts +++ b/packages/typespec-python/scripts/regenerate.ts @@ -210,7 +210,7 @@ function addOptions(spec: string, generatedFolder: string, flags: RegenerateFlag } if (options["emitter-output-dir"] === undefined) { const packageName = options["package-name"] || defaultPackageName(spec); - options["emitter-output-dir"] = `${generatedFolder}/test/${flags.flavor}/generated/${packageName}`; + options["emitter-output-dir"] = toPosix(`${generatedFolder}/test/${flags.flavor}/generated/${packageName}`); } if (flags.debug) { options["debug"] = "true"; @@ -218,7 +218,7 @@ function addOptions(spec: string, generatedFolder: string, flags: RegenerateFlag if (flags.flavor === "unbranded") { options["company-name"] = "Unbranded"; } - options["examples-directory"] = join(dirname(spec), "examples"); + options["examples-directory"] = toPosix(join(dirname(spec), "examples")); const configs = Object.entries(options).flatMap(([k, v]) => { return `--option @azure-tools/typespec-python.${k}=${v}`; }); @@ -231,7 +231,7 @@ async function _regenerateSingle(spec: string, flags: RegenerateFlags): Promise< // Perform some asynchronous operation here const options = addOptions(spec, PLUGIN_DIR, flags); const commandPromises = options.map((option) => { - const command = `tsp compile ${spec} --emit=${PLUGIN_DIR} ${option}`; + const command = `tsp compile ${spec} --emit=${toPosix(PLUGIN_DIR)} ${option}`; console.log(command); return executeCommand(command); }); diff --git a/packages/typespec-python/src/types.ts b/packages/typespec-python/src/types.ts index 8ab69a9b46a..96faa07b02d 100644 --- a/packages/typespec-python/src/types.ts +++ b/packages/typespec-python/src/types.ts @@ -422,8 +422,10 @@ export function emitEndpointType( ): Record[] { const params: Record[] = []; for (const param of type.templateArguments) { + const paramBase = emitParamBase(context, param); + paramBase.clientName = context.arm ? "base_url" : paramBase.clientName; params.push({ - ...emitParamBase(context, param), + ...paramBase, optional: Boolean(param.clientDefaultValue), wireName: param.name, location: "endpointPath", diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py index 43704148965..d81d699bff3 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py @@ -34,8 +34,8 @@ class ManagedIdentityClient: # pylint: disable=client-accepts-api-version-keywo :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword endpoint: Service host. Default value is "https://management.azure.com". - :paramtype endpoint: str + :keyword base_url: Service host. Default value is "https://management.azure.com". + :paramtype base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -47,12 +47,12 @@ def __init__( credential: "TokenCredential", subscription_id: str, *, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: _endpoint = "{endpoint}" self._config = ManagedIdentityClientConfiguration( - credential=credential, subscription_id=subscription_id, endpoint=endpoint, **kwargs + credential=credential, subscription_id=subscription_id, base_url=base_url, **kwargs ) _policies = kwargs.pop("policies", None) if _policies is None: @@ -101,7 +101,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: request_copy = deepcopy(request) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_configuration.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_configuration.py index cbd3ecff191..c75644b59b0 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_configuration.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_configuration.py @@ -28,8 +28,8 @@ class ManagedIdentityClientConfiguration: # pylint: disable=too-many-instance-a :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :param endpoint: Service host. Default value is "https://management.azure.com". - :type endpoint: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -40,7 +40,7 @@ def __init__( self, credential: "TokenCredential", subscription_id: str, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: api_version: str = kwargs.pop("api_version", "2023-12-01-preview") @@ -52,7 +52,7 @@ def __init__( self.credential = credential self.subscription_id = subscription_id - self.endpoint = endpoint + self.base_url = base_url self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "resourcemanager-models-commontypes-managedidentity/{}".format(VERSION)) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py index 524f78ca832..6337d6e6c5e 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py @@ -34,8 +34,8 @@ class ManagedIdentityClient: # pylint: disable=client-accepts-api-version-keywo :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword endpoint: Service host. Default value is "https://management.azure.com". - :paramtype endpoint: str + :keyword base_url: Service host. Default value is "https://management.azure.com". + :paramtype base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -47,12 +47,12 @@ def __init__( credential: "AsyncTokenCredential", subscription_id: str, *, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: _endpoint = "{endpoint}" self._config = ManagedIdentityClientConfiguration( - credential=credential, subscription_id=subscription_id, endpoint=endpoint, **kwargs + credential=credential, subscription_id=subscription_id, base_url=base_url, **kwargs ) _policies = kwargs.pop("policies", None) if _policies is None: @@ -103,7 +103,7 @@ def send_request( request_copy = deepcopy(request) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_configuration.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_configuration.py index 45edd746ba3..91a41bb6b44 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_configuration.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_configuration.py @@ -28,8 +28,8 @@ class ManagedIdentityClientConfiguration: # pylint: disable=too-many-instance-a :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :param endpoint: Service host. Default value is "https://management.azure.com". - :type endpoint: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -40,7 +40,7 @@ def __init__( self, credential: "AsyncTokenCredential", subscription_id: str, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: api_version: str = kwargs.pop("api_version", "2023-12-01-preview") @@ -52,7 +52,7 @@ def __init__( self.credential = credential self.subscription_id = subscription_id - self.endpoint = endpoint + self.base_url = base_url self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "resourcemanager-models-commontypes-managedidentity/{}".format(VERSION)) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/operations/_operations.py index 12930d51e3e..7634f1b87a7 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/operations/_operations.py @@ -136,7 +136,7 @@ async def get( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -523,7 +523,7 @@ async def create_with_system_assigned( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -910,7 +910,7 @@ async def update_with_user_assigned_and_system_assigned( # pylint: disable=name params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/operations/_operations.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/operations/_operations.py index d75ef020694..fe8de25e751 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/operations/_operations.py @@ -231,7 +231,7 @@ def get( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -618,7 +618,7 @@ def create_with_system_assigned( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1005,7 +1005,7 @@ def update_with_user_assigned_and_system_assigned( # pylint: disable=name-too-l params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py index 452da9ca495..869d1d3b66d 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py @@ -37,8 +37,8 @@ class ResourcesClient: # pylint: disable=client-accepts-api-version-keyword :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword endpoint: Service host. Default value is "https://management.azure.com". - :paramtype endpoint: str + :keyword base_url: Service host. Default value is "https://management.azure.com". + :paramtype base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -52,12 +52,12 @@ def __init__( credential: "TokenCredential", subscription_id: str, *, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: _endpoint = "{endpoint}" self._config = ResourcesClientConfiguration( - credential=credential, subscription_id=subscription_id, endpoint=endpoint, **kwargs + credential=credential, subscription_id=subscription_id, base_url=base_url, **kwargs ) _policies = kwargs.pop("policies", None) if _policies is None: @@ -109,7 +109,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: request_copy = deepcopy(request) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_configuration.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_configuration.py index 0e6493bfc22..902cad19dd8 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_configuration.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_configuration.py @@ -28,8 +28,8 @@ class ResourcesClientConfiguration: # pylint: disable=too-many-instance-attribu :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :param endpoint: Service host. Default value is "https://management.azure.com". - :type endpoint: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -40,7 +40,7 @@ def __init__( self, credential: "TokenCredential", subscription_id: str, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: api_version: str = kwargs.pop("api_version", "2023-12-01-preview") @@ -52,7 +52,7 @@ def __init__( self.credential = credential self.subscription_id = subscription_id - self.endpoint = endpoint + self.base_url = base_url self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "resourcemanager-models-resources/{}".format(VERSION)) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py index 013f1384601..2e04d3ae528 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py @@ -37,8 +37,8 @@ class ResourcesClient: # pylint: disable=client-accepts-api-version-keyword :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword endpoint: Service host. Default value is "https://management.azure.com". - :paramtype endpoint: str + :keyword base_url: Service host. Default value is "https://management.azure.com". + :paramtype base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -52,12 +52,12 @@ def __init__( credential: "AsyncTokenCredential", subscription_id: str, *, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: _endpoint = "{endpoint}" self._config = ResourcesClientConfiguration( - credential=credential, subscription_id=subscription_id, endpoint=endpoint, **kwargs + credential=credential, subscription_id=subscription_id, base_url=base_url, **kwargs ) _policies = kwargs.pop("policies", None) if _policies is None: @@ -111,7 +111,7 @@ def send_request( request_copy = deepcopy(request) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_configuration.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_configuration.py index 7208a1794ea..cb7fb0a6566 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_configuration.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_configuration.py @@ -28,8 +28,8 @@ class ResourcesClientConfiguration: # pylint: disable=too-many-instance-attribu :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :param endpoint: Service host. Default value is "https://management.azure.com". - :type endpoint: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -40,7 +40,7 @@ def __init__( self, credential: "AsyncTokenCredential", subscription_id: str, - endpoint: str = "https://management.azure.com", + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: api_version: str = kwargs.pop("api_version", "2023-12-01-preview") @@ -52,7 +52,7 @@ def __init__( self.credential = credential self.subscription_id = subscription_id - self.endpoint = endpoint + self.base_url = base_url self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "resourcemanager-models-resources/{}".format(VERSION)) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/operations/_operations.py index 96802927902..20846fcc643 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/operations/_operations.py @@ -151,7 +151,7 @@ async def get( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -221,7 +221,7 @@ async def _create_or_replace_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -547,7 +547,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -608,7 +608,7 @@ async def _update_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -932,7 +932,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -979,7 +979,7 @@ async def _delete_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1050,7 +1050,7 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- return cls(pipeline_response, None, {}) # type: ignore path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -1135,7 +1135,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1155,7 +1155,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1246,7 +1246,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1266,7 +1266,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1382,7 +1382,7 @@ async def get( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1454,7 +1454,7 @@ async def _create_or_replace_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1769,7 +1769,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -1832,7 +1832,7 @@ async def _update_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2145,7 +2145,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -2197,7 +2197,7 @@ async def _delete_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2275,7 +2275,7 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- return cls(pipeline_response, None, {}) # type: ignore path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -2359,7 +2359,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2379,7 +2379,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/operations/_operations.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/operations/_operations.py index 1b764d3bd47..d308ec4a29c 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/operations/_operations.py @@ -482,7 +482,7 @@ def get( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -552,7 +552,7 @@ def _create_or_replace_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -878,7 +878,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -939,7 +939,7 @@ def _update_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1263,7 +1263,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -1310,7 +1310,7 @@ def _delete_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1381,7 +1381,7 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- return cls(pipeline_response, None, {}) # type: ignore path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -1466,7 +1466,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1486,7 +1486,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1577,7 +1577,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1597,7 +1597,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1713,7 +1713,7 @@ def get( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -1785,7 +1785,7 @@ def _create_or_replace_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2100,7 +2100,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -2163,7 +2163,7 @@ def _update_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2476,7 +2476,7 @@ def get_long_running_output(pipeline_response): return deserialized path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -2528,7 +2528,7 @@ def _delete_initial( params=_params, ) path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2606,7 +2606,7 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent- return cls(pipeline_response, None, {}) # type: ignore path_format_arguments = { - "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), + "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True), } if polling is True: @@ -2690,7 +2690,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) @@ -2710,7 +2710,7 @@ def prepare_request(next_link=None): ) path_format_arguments = { "endpoint": self._serialize.url( - "self._config.endpoint", self._config.endpoint, "str", skip_quote=True + "self._config.base_url", self._config.base_url, "str", skip_quote=True ), } _request.url = self._client.format_url(_request.url, **path_format_arguments) From 4f6ba60081ab7d3b66f16da4f24746ee45a55dac Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:26:10 +0800 Subject: [PATCH 2/3] changelog --- .chronus/changes/HEAD-2024-7-9-10-25-50.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/HEAD-2024-7-9-10-25-50.md diff --git a/.chronus/changes/HEAD-2024-7-9-10-25-50.md b/.chronus/changes/HEAD-2024-7-9-10-25-50.md new file mode 100644 index 00000000000..55eb61b63f3 --- /dev/null +++ b/.chronus/changes/HEAD-2024-7-9-10-25-50.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-python" +--- + +Revert client signature `endpoint` to `base_url` to avoid breaking for Mgmt SDK \ No newline at end of file From 1f8951c93ba687965b9272de615fca748370a3d6 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:16:54 +0800 Subject: [PATCH 3/3] add test --- .../pygen/codegen/models/parameter.py | 6 +++- .../commontypes/managedidentity/_client.py | 5 ++- .../managedidentity/aio/_client.py | 5 ++- .../models/resources/_client.py | 5 ++- .../models/resources/aio/_client.py | 5 ++- .../test_azure_arm_models_resource_async.py | 32 +++++++++++++++++++ .../test/azure/mock_api_tests/conftest.py | 19 +++++++++++ .../test_azure_arm_models_resource.py | 30 +++++++++++++++++ 8 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_arm_models_resource_async.py create mode 100644 packages/typespec-python/test/azure/mock_api_tests/test_azure_arm_models_resource.py diff --git a/packages/typespec-python/generator/pygen/codegen/models/parameter.py b/packages/typespec-python/generator/pygen/codegen/models/parameter.py index 6e17463f368..8c3df862172 100644 --- a/packages/typespec-python/generator/pygen/codegen/models/parameter.py +++ b/packages/typespec-python/generator/pygen/codegen/models/parameter.py @@ -381,7 +381,11 @@ def method_location(self) -> ParameterMethodLocation: ): # this means i am the base url return ParameterMethodLocation.KEYWORD_ONLY - if self.client_default_value is not None and self.code_model.options["from_typespec"]: + if ( + self.client_default_value is not None + and self.code_model.options["from_typespec"] + and not self.code_model.options["azure_arm"] + ): return ParameterMethodLocation.KEYWORD_ONLY return ParameterMethodLocation.POSITIONAL diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py index d81d699bff3..4da103a03ff 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/_client.py @@ -34,8 +34,8 @@ class ManagedIdentityClient: # pylint: disable=client-accepts-api-version-keywo :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword base_url: Service host. Default value is "https://management.azure.com". - :paramtype base_url: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -46,7 +46,6 @@ def __init__( self, credential: "TokenCredential", subscription_id: str, - *, base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py index 6337d6e6c5e..da0a591def4 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-common-types-managed-identity/azure/resourcemanager/models/commontypes/managedidentity/aio/_client.py @@ -34,8 +34,8 @@ class ManagedIdentityClient: # pylint: disable=client-accepts-api-version-keywo :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword base_url: Service host. Default value is "https://management.azure.com". - :paramtype base_url: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -46,7 +46,6 @@ def __init__( self, credential: "AsyncTokenCredential", subscription_id: str, - *, base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py index 869d1d3b66d..0062d71a011 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/_client.py @@ -37,8 +37,8 @@ class ResourcesClient: # pylint: disable=client-accepts-api-version-keyword :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword base_url: Service host. Default value is "https://management.azure.com". - :paramtype base_url: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -51,7 +51,6 @@ def __init__( self, credential: "TokenCredential", subscription_id: str, - *, base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py index 2e04d3ae528..cffb32957b3 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-models-resources/azure/resourcemanager/models/resources/aio/_client.py @@ -37,8 +37,8 @@ class ResourcesClient: # pylint: disable=client-accepts-api-version-keyword :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. The value must be an UUID. Required. :type subscription_id: str - :keyword base_url: Service host. Default value is "https://management.azure.com". - :paramtype base_url: str + :param base_url: Service host. Default value is "https://management.azure.com". + :type base_url: str :keyword api_version: The API version to use for this operation. Default value is "2023-12-01-preview". Note that overriding this default value may result in unsupported behavior. @@ -51,7 +51,6 @@ def __init__( self, credential: "AsyncTokenCredential", subscription_id: str, - *, base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: diff --git a/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_arm_models_resource_async.py b/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_arm_models_resource_async.py new file mode 100644 index 00000000000..31124fde16a --- /dev/null +++ b/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_arm_models_resource_async.py @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import pytest +from azure.resourcemanager.models.resources.aio import ResourcesClient + +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" +RESOURCE_GROUP_NAME = "test-rg" + + +@pytest.mark.asyncio +async def test_client_signature(credential, authentication_policy): + # make sure signautre order is correct + client1 = ResourcesClient( + credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy + ) + # make sure signautre name is correct + client2 = ResourcesClient( + credential=credential, + subscription_id=SUBSCRIPTION_ID, + base_url="http://localhost:3000", + authentication_policy=authentication_policy, + ) + for client in [client1, client2]: + # make sure signautre order is correct + await client.top_level_tracked_resources.get(RESOURCE_GROUP_NAME, "top") + # make sure signautre name is correct + await client.top_level_tracked_resources.get( + resource_group_name=RESOURCE_GROUP_NAME, top_level_tracked_resource_name="top" + ) diff --git a/packages/typespec-python/test/azure/mock_api_tests/conftest.py b/packages/typespec-python/test/azure/mock_api_tests/conftest.py index c90503bcaba..0b897317d49 100644 --- a/packages/typespec-python/test/azure/mock_api_tests/conftest.py +++ b/packages/typespec-python/test/azure/mock_api_tests/conftest.py @@ -129,3 +129,22 @@ async def request_status(self, status_link: str): # ================== after azure-core fix, the up code can be removed (end) ================== + + +@pytest.fixture() +def credential(): + """I actually don't need anything, since the authentication policy + will bypass it. + """ + + class FakeCredential: + pass + + return FakeCredential() + + +@pytest.fixture() +def authentication_policy(): + from azure.core.pipeline.policies import SansIOHTTPPolicy + + return SansIOHTTPPolicy() diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_azure_arm_models_resource.py b/packages/typespec-python/test/azure/mock_api_tests/test_azure_arm_models_resource.py new file mode 100644 index 00000000000..c777afefd3f --- /dev/null +++ b/packages/typespec-python/test/azure/mock_api_tests/test_azure_arm_models_resource.py @@ -0,0 +1,30 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from azure.resourcemanager.models.resources import ResourcesClient + +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" +RESOURCE_GROUP_NAME = "test-rg" + + +def test_client_signature(credential, authentication_policy): + # make sure signautre order is correct + client1 = ResourcesClient( + credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy + ) + # make sure signautre name is correct + client2 = ResourcesClient( + credential=credential, + subscription_id=SUBSCRIPTION_ID, + base_url="http://localhost:3000", + authentication_policy=authentication_policy, + ) + for client in [client1, client2]: + # make sure signautre order is correct + client.top_level_tracked_resources.get(RESOURCE_GROUP_NAME, "top") + # make sure signautre name is correct + client.top_level_tracked_resources.get( + resource_group_name=RESOURCE_GROUP_NAME, top_level_tracked_resource_name="top" + )