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/HEAD-2024-7-9-10-25-50.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-python"
---

Revert client signature `endpoint` to `base_url` to avoid breaking for Mgmt SDK
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions packages/typespec-python/scripts/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ 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";
}
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}`;
});
Expand All @@ -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}`;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emitter-options shall be posix path style otherwise cause warning: microsoft/typespec#4023

console.log(command);
return executeCommand(command);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/typespec-python/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,10 @@ export function emitEndpointType<TServiceOperation extends SdkServiceOperation>(
): Record<string, any>[] {
const params: Record<string, any>[] = [];
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
: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.
Expand All @@ -46,13 +46,12 @@ def __init__(
self,
credential: "TokenCredential",
subscription_id: str,
*,
endpoint: str = "https://management.azure.com",
base_url: str = "https://management.azure.com",
Copy link
Copy Markdown
Member Author

@msyyc msyyc Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**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:
Expand Down Expand Up @@ -101,7 +100,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
: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.
Expand All @@ -46,13 +46,12 @@ def __init__(
self,
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:
Expand Down Expand Up @@ -103,7 +102,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
: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.
Expand All @@ -51,13 +51,12 @@ def __init__(
self,
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:
Expand Down Expand Up @@ -109,7 +108,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
: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.
Expand All @@ -51,13 +51,12 @@ def __init__(
self,
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:
Expand Down Expand Up @@ -111,7 +110,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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))
Expand Down
Loading