diff --git a/.chronus/changes/python-pagingModelUsage-2025-10-13-15-25-59.md b/.chronus/changes/python-pagingModelUsage-2025-10-13-15-25-59.md new file mode 100644 index 00000000000..b5da968ccf1 --- /dev/null +++ b/.chronus/changes/python-pagingModelUsage-2025-10-13-15-25-59.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Emit paging models marked with `@usage` overrides \ No newline at end of file diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 44ac08c6788..581e6043837 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -335,9 +335,12 @@ export function emitCodeModel(sdkContext: PythonSdkContext) { } getType(sdkContext, sdkEnum); } - // clear usage when a model is only used by paging for (const type of typesMap.values()) { + const usageOverride = (type["usageOverride"] as UsageFlags | undefined) || 0; + if ((usageOverride & UsageFlags.Input) > 0 || (usageOverride & UsageFlags.Output) > 0) { + continue; // Don't clear usage for types used as Input or Output + } if ( type["type"] === "model" && type["referredByOperationType"] === ReferredByOperationTypes.PagingOnly diff --git a/packages/http-client-python/emitter/src/types.ts b/packages/http-client-python/emitter/src/types.ts index 26bee78d935..4150f4f8f12 100644 --- a/packages/http-client-python/emitter/src/types.ts +++ b/packages/http-client-python/emitter/src/types.ts @@ -1,4 +1,5 @@ import { + getUsageOverride, isHttpMetadata, SdkArrayType, SdkBuiltInType, @@ -16,7 +17,7 @@ import { SdkUnionType, UsageFlags, } from "@azure-tools/typespec-client-generator-core"; -import { Type } from "@typespec/compiler"; +import { Model, Type } from "@typespec/compiler"; import { HttpAuth, Visibility } from "@typespec/http"; import { dump } from "js-yaml"; import { PythonSdkContext } from "./lib.js"; @@ -284,6 +285,7 @@ function emitModel(context: PythonSdkContext, type: SdkModelType): Record