Skip to content

Commit

Permalink
[python emitter] update tcgc and switch to use doc and summary (#4566)
Browse files Browse the repository at this point in the history
update to tcgc 0.46.2 and remove deprecated usage of doc
  • Loading branch information
tadelesh authored Sep 29, 2024
1 parent 3804d7a commit 84c9558
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/http-client-python/emitter/src/code-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function emitClient<TServiceOperation extends SdkServiceOperation>(
}
return {
name: client.name,
description: client.description ?? "",
description: (client.summary ? client.summary : client.doc) ?? "",
parameters,
operationGroups,
url,
Expand Down
20 changes: 10 additions & 10 deletions packages/http-client-python/emitter/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SdkBodyParameter,
SdkClientType,
SdkHeaderParameter,
SdkHttpErrorResponse,
SdkHttpOperation,
SdkHttpOperationExample,
SdkHttpResponse,
Expand All @@ -23,7 +24,6 @@ import {
emitParamBase,
getAddedOn,
getDelimiterAndExplode,
getDescriptionAndSummary,
getImplementation,
isAbstract,
isAzureCoreErrorResponse,
Expand Down Expand Up @@ -55,8 +55,8 @@ export function emitBasicHttpMethod(
abstract: isAbstract(method),
internal: method.access === "internal",
name: camelToSnakeCase(method.name),
description: getDescriptionAndSummary(method).description,
summary: getDescriptionAndSummary(method).summary,
description: method.doc ?? "",
summary: method.summary,
},
];
}
Expand All @@ -73,8 +73,8 @@ function emitInitialLroHttpMethod(
isLroInitialOperation: true,
wantTracing: false,
exposeStreamKeyword: false,
description: getDescriptionAndSummary(method).description,
summary: getDescriptionAndSummary(method).summary,
description: method.doc ?? "",
summary: method.summary,
};
}

Expand All @@ -90,8 +90,8 @@ function addLroInformation(
discriminator: "lro",
initialOperation: emitInitialLroHttpMethod(context, rootClient, method, operationGroupName),
exposeStreamKeyword: false,
description: getDescriptionAndSummary(method).description,
summary: getDescriptionAndSummary(method).summary,
description: method.doc ?? "",
summary: method.summary,
};
}

Expand Down Expand Up @@ -119,8 +119,8 @@ function addPagingInformation(
itemName: method.response.resultPath,
continuationTokenName: method.nextLinkPath,
itemType,
description: getDescriptionAndSummary(method).description,
summary: getDescriptionAndSummary(method).summary,
description: method.doc ?? "",
summary: method.summary,
};
}

Expand Down Expand Up @@ -338,7 +338,7 @@ function emitHttpBodyParameter(
function emitHttpResponse(
context: PythonSdkContext<SdkHttpOperation>,
statusCodes: HttpStatusCodeRange | number | "*",
response: SdkHttpResponse,
response: SdkHttpResponse | SdkHttpErrorResponse,
method?: SdkServiceMethod<SdkHttpOperation>,
isException = false,
): Record<string, any> | undefined {
Expand Down
10 changes: 5 additions & 5 deletions packages/http-client-python/emitter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function emitMultiPartFile<TServiceOperation extends SdkServiceOperation>(
}
return getSimpleTypeResult({
type: type.kind,
description: type.type.description,
description: type.type.summary ? type.type.summary : type.type.doc,
});
}

Expand Down Expand Up @@ -239,7 +239,7 @@ function emitProperty<TServiceOperation extends SdkServiceOperation>(
wireName: property.serializedName,
type: getType(context, sourceType),
optional: property.optional,
description: property.description,
description: property.summary ? property.summary : property.doc,
addedOn: getAddedOn(context, property),
visibility: visibilityMapping(property.visibility),
isDiscriminator: property.discriminator,
Expand Down Expand Up @@ -277,7 +277,7 @@ function emitModel<TServiceOperation extends SdkServiceOperation>(
const newValue = {
type: type.kind,
name: type.name,
description: type.description,
description: type.summary ? type.summary : type.doc,
parents: parents,
discriminatorValue: type.discriminatorValue,
discriminatedSubtypes: {} as Record<string, Record<string, any>>,
Expand Down Expand Up @@ -345,7 +345,7 @@ function emitEnum(type: SdkEnumType): Record<string, any> {
const newValue = {
name: name,
snakeCaseName: camelToSnakeCase(name),
description: type.description || `Type of ${name}`,
description: (type.summary ? type.summary : type.doc) ?? `Type of ${name}`,
internal: type.access === "internal",
type: type.kind,
valueType: emitBuiltInType(type.valueType),
Expand Down Expand Up @@ -374,7 +374,7 @@ function emitEnumMember(
return {
name: enumName(type.name),
value: type.value,
description: type.description,
description: type.summary ? type.summary : type.doc,
enumType,
type: type.kind,
valueType: enumType["valueType"],
Expand Down
16 changes: 1 addition & 15 deletions packages/http-client-python/emitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function emitParamBase<TServiceOperation extends SdkServiceOperation>(
}
return {
optional: parameter.optional,
description: parameter.description || "",
description: (parameter.summary ? parameter.summary : parameter.doc) ?? "",
addedOn: getAddedOn(context, parameter),
clientName: camelToSnakeCase(parameter.name),
inOverload: false,
Expand All @@ -196,20 +196,6 @@ export function isAzureCoreErrorResponse(t: SdkType | undefined): boolean {
);
}

export function getDescriptionAndSummary<TServiceOperation extends SdkServiceOperation>(
method: SdkMethod<TServiceOperation>,
): { description?: string; summary?: string } {
if (method.details) {
return {
description: method.details,
summary: method.description,
};
}
return {
description: method.description ?? "",
};
}

export function capitalize(name: string): string {
return name[0].toUpperCase() + name.slice(1);
}
10 changes: 5 additions & 5 deletions packages/http-client-python/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@azure-tools/typespec-azure-core": ">=0.46.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.46.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.46.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.46.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.46.2 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.46.0 <3.0.0",
"@typespec/compiler": ">=0.60.0 <1.0.0",
"@typespec/http": ">=0.60.0 <1.0.0",
Expand All @@ -80,7 +80,7 @@
"typescript": "~5.6.2",
"typescript-eslint": "^8.5.0",
"@azure-tools/typespec-azure-core": "~0.46.0",
"@azure-tools/typespec-client-generator-core": "0.46.1",
"@azure-tools/typespec-client-generator-core": "0.46.2",
"@typespec/compiler": "~0.60.0",
"@typespec/http": "~0.60.0",
"@typespec/rest": "~0.60.0",
Expand Down

0 comments on commit 84c9558

Please sign in to comment.