Skip to content

Commit 80e05f0

Browse files
author
iscai-msft
committed
fix(python): target first SDK model for no-sdk-clients diagnostic
Point the no-sdk-clients diagnostic at the first SDK model's raw type when there is no service, so it stays suppressable for model-only packages whose models live under an explicit namespace (the global namespace has no suppressable node). Also delete the code-model YAML temp file the emit-yaml-only test helper produces. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9baae876-cdbf-4556-952a-e95b26298ca9
1 parent f49c7fc commit 80e05f0

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/http-client-python/emitter/src/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
197197
code: "no-sdk-clients",
198198
target:
199199
listServices(program)[0]?.type ??
200-
program.getGlobalNamespaceType().models.values().next().value ??
200+
sdkContext.sdkPackage.models[0]?.__raw ??
201201
program.getGlobalNamespaceType(),
202202
});
203203
}

packages/http-client-python/emitter/test/test-host.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export async function emitCodeModel(
5050
code: string,
5151
): Promise<{ codeModel: CodeModel; diagnostics: readonly Diagnostic[] }> {
5252
const outputDir = await mkdtemp(join(tmpdir(), "typespec-python-"));
53+
let yamlPath: string | undefined;
5354
try {
5455
const [, diagnostics] = await EmitterTester.compileAndDiagnose(code, {
5556
compilerOptions: {
@@ -70,14 +71,17 @@ export async function emitCodeModel(
7071
if (!pointerName) {
7172
throw new Error("Emitter did not produce a code model.");
7273
}
73-
const { yamlPath } = JSON.parse(
74+
({ yamlPath } = JSON.parse(
7475
await readFile(join(outputDir, pointerName), "utf-8"),
75-
);
76+
));
7677
const codeModel = jsyaml.load(
77-
await readFile(yamlPath, "utf-8"),
78+
await readFile(yamlPath!, "utf-8"),
7879
) as CodeModel;
7980
return { codeModel, diagnostics };
8081
} finally {
8182
await rm(outputDir, { recursive: true, force: true });
83+
if (yamlPath) {
84+
await rm(yamlPath, { force: true });
85+
}
8286
}
8387
}

0 commit comments

Comments
 (0)