Skip to content

Commit

Permalink
Merge branch 'main' into ReleaseHttpSpecsAlpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
sarangan12 authored Dec 9, 2024
2 parents a38a7d9 + 55f313e commit d1f3dae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
7 changes: 7 additions & 0 deletions packages/http-client-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log - @typespec/http-client-python

## 0.4.2

### Bug Fixes

- Ignore models/enum only used as LRO envelope results
- Refine exception handling logic to keep compatibility for legacy SDK

## 0.4.1

### Bug Fixes
Expand Down
27 changes: 14 additions & 13 deletions packages/http-client-python/emitter/src/code-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ function emitClient<TServiceOperation extends SdkServiceOperation>(
};
}

function onlyUsedByPolling(usage: UsageFlags): boolean {
return (
((usage & UsageFlags.LroInitial) > 0 ||
(usage & UsageFlags.LroFinalEnvelope) > 0 ||
(usage & UsageFlags.LroPolling) > 0) &&
(usage & UsageFlags.Input) === 0 &&
(usage & UsageFlags.Output) === 0
);
}

export function emitCodeModel<TServiceOperation extends SdkServiceOperation>(
sdkContext: PythonSdkContext<TServiceOperation>,
) {
Expand All @@ -269,9 +279,6 @@ export function emitCodeModel<TServiceOperation extends SdkServiceOperation>(
}
// loop through models and enums since there may be some orphaned models needs to be generated
for (const model of sdkPackage.models) {
if (isAzureCoreModel(model)) {
continue;
}
// filter out spread models
if (
model.name === "" ||
Expand All @@ -282,13 +289,7 @@ export function emitCodeModel<TServiceOperation extends SdkServiceOperation>(
continue;
}
// filter out models only used for polling and or envelope result
if (
((model.usage & UsageFlags.LroInitial) > 0 ||
(model.usage & UsageFlags.LroFinalEnvelope) > 0 ||
(model.usage & UsageFlags.LroPolling) > 0) &&
(model.usage & UsageFlags.Input) === 0 &&
(model.usage & UsageFlags.Output) === 0
) {
if (onlyUsedByPolling(model.usage)) {
continue;
}
// filter out specific models not used in python, e.g., pageable models
Expand All @@ -302,13 +303,13 @@ export function emitCodeModel<TServiceOperation extends SdkServiceOperation>(
getType(sdkContext, model);
}
for (const sdkEnum of sdkPackage.enums) {
if (isAzureCoreModel(sdkEnum)) {
continue;
}
// filter out api version enum since python do not generate it
if (sdkEnum.usage === UsageFlags.ApiVersionEnum) {
continue;
}
if (onlyUsedByPolling(sdkEnum.usage)) {
continue;
}
// filter out core enums
if (isAzureCoreModel(sdkEnum)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def default_error_deserialization(self) -> Optional[str]:
exception_schema = default_exceptions[0].type
if isinstance(exception_schema, ModelType):
return exception_schema.type_annotation(skip_quote=True)
return None
return None if self.code_model.options["models_mode"] == "dpg" else "'object'"

@property
def non_default_errors(self) -> List[Response]:
Expand Down
4 changes: 2 additions & 2 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.

2 changes: 1 addition & 1 deletion packages/http-client-python/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typespec/http-client-python",
"version": "0.4.1",
"version": "0.4.2",
"author": "Microsoft Corporation",
"description": "TypeSpec emitter for Python SDKs",
"homepage": "https://typespec.io",
Expand Down

0 comments on commit d1f3dae

Please sign in to comment.