Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .chronus/changes/bump_tcgc-2024-4-6-17-11-30.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: dependencies
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

bump tcgc dependencies to `0.41.9`
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"cwd": "${workspaceFolder}/packages/typespec-python",
"args": [
"compile",
"${workspaceFolder}/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs/http/server/versions/not-versioned",
"${workspaceFolder}/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs/http/versioning/added",
"--emit",
"${workspaceFolder}/packages/typespec-python/dist/src/index.js",
"--option=@azure-tools/typespec-python.debug=true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _imports_shared(self, async_mode: bool, **_: Any) -> FileImport:
file_import = FileImport(self.code_model)
if self.optional and self.client_default_value is None:
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
if self.added_on and self.implementation != "Client":
if self.added_on:
file_import.add_submodule_import(
f"{'.' if async_mode else ''}.._validation",
"api_version_validation",
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.8 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.9 <1.0.0",
"@typespec/compiler": ">=0.55.0 <1.0.0",
"@typespec/http": ">=0.55.0 <1.0.0",
"@typespec/rest": ">=0.55.0 <1.0.0",
Expand Down Expand Up @@ -78,7 +78,7 @@
"rimraf": "~5.0.0",
"typescript": "~5.1.3",
"@azure-tools/typespec-azure-core": "~0.41.0",
"@azure-tools/typespec-client-generator-core": "~0.41.8",
"@azure-tools/typespec-client-generator-core": "~0.41.9",
"@typespec/compiler": "~0.55.0",
"@typespec/http": "~0.55.0",
"@typespec/rest": "~0.55.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/typespec-python/src/code-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ function emitLroPagingMethod<TServiceOperation extends SdkServiceOperation>(

function emitMethodParameter<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
client: SdkClientType<TServiceOperation>,
parameter: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter,
): Record<string, any>[] {
if (parameter.kind === "endpoint") {
if (parameter.type.serverUrl && parameter.type.templateArguments.length > 0) {
const params: Record<string, any>[] = [];
for (const param of parameter.type.templateArguments) {
params.push({
...emitParamBase(context, param),
...emitParamBase(context, param, false, client),
wireName: param.name,
location: "endpointPath",
implementation: getImplementation(context, param),
Expand Down Expand Up @@ -205,7 +206,7 @@ function emitClient<TServiceOperation extends SdkServiceOperation>(
context.__endpointPathParameters = [];
}
const parameters =
client.initialization?.properties.map((x) => emitMethodParameter(context, x)).reduce((a, b) => [...a, ...b]) ??
client.initialization?.properties.map((x) => emitMethodParameter(context, client, x)).reduce((a, b) => [...a, ...b]) ??
[];

const endpointParameter = client.initialization?.properties.find((x) => x.kind === "endpoint") as
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-python/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function emitHttpOperation(
responses,
exceptions,
groupName: operationGroupName,
addedOn: method ? getAddedOn(context, method) : "",
addedOn: method ? getAddedOn(context, method, rootClient) : "",
discriminator: "basic",
isOverload: false,
overloads: [],
Expand Down
8 changes: 6 additions & 2 deletions packages/typespec-python/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SdkServiceMethod,
SdkServiceOperation,
SdkType,
SdkClientType,
} from "@azure-tools/typespec-client-generator-core";
import { getSimpleTypeResult, getType } from "./types.js";
import { getNamespaceFullName } from "@typespec/compiler";
Expand Down Expand Up @@ -76,16 +77,19 @@ type ParamBase = {
export function getAddedOn<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
type: SdkModelPropertyType | SdkMethod<TServiceOperation>,
client?: SdkClientType<TServiceOperation>,
): string | undefined {
// We only want added on if it's not the same as the client's added on
if (type.apiVersions[0] === context.experimental_sdkPackage.clients[0].apiVersions[0]) return undefined;
const clientToCheck = client || context.experimental_sdkPackage.clients[0];
if (type.apiVersions[0] <= clientToCheck.apiVersions[0]) return undefined;
return type.apiVersions[0];
}

export function emitParamBase<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
parameter: SdkParameter | SdkHttpParameter,
fromBody: boolean = false,
client?: SdkClientType<TServiceOperation>,
): ParamBase {
let type = getType(context, parameter.type, fromBody);
if (parameter.isApiVersionParam) {
Expand All @@ -96,7 +100,7 @@ export function emitParamBase<TServiceOperation extends SdkServiceOperation>(
return {
optional: parameter.optional,
description: parameter.description || "",
addedOn: getAddedOn(context, parameter),
addedOn: getAddedOn(context, parameter, client),
clientName: camelToSnakeCase(parameter.name),
inOverload: false,
isApiVersion: parameter.isApiVersionParam,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ async def _create_or_update_initial(
resource_group_name=resource_group_name,
catalog_name=catalog_name,
subscription_id=self._config.subscription_id,
content_type=content_type,
api_version=self._config.api_version,
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
Expand Down Expand Up @@ -1091,8 +1091,8 @@ async def update(
resource_group_name=resource_group_name,
catalog_name=catalog_name,
subscription_id=self._config.subscription_id,
content_type=content_type,
api_version=self._config.api_version,
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
Expand Down Expand Up @@ -2642,11 +2642,11 @@ def prepare_request(next_link=None):
resource_group_name=resource_group_name,
catalog_name=catalog_name,
subscription_id=self._config.subscription_id,
api_version=self._config.api_version,
filter=filter,
top=top,
skip=skip,
maxpagesize=maxpagesize,
api_version=self._config.api_version,
headers=_headers,
params=_params,
)
Expand Down Expand Up @@ -2730,8 +2730,8 @@ async def _create_or_update_initial(
catalog_name=catalog_name,
image_name=image_name,
subscription_id=self._config.subscription_id,
content_type=content_type,
api_version=self._config.api_version,
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
Expand Down Expand Up @@ -5240,11 +5240,11 @@ def prepare_request(next_link=None):
resource_group_name=resource_group_name,
catalog_name=catalog_name,
subscription_id=self._config.subscription_id,
api_version=self._config.api_version,
filter=filter,
top=top,
skip=skip,
maxpagesize=maxpagesize,
api_version=self._config.api_version,
headers=_headers,
params=_params,
)
Expand Down
Loading