Skip to content

Commit e44febc

Browse files
committed
Address no-client warning review feedback
1 parent e58dbf5 commit e44febc

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
2-
import type { EmitContext, Namespace, Program } from "@typespec/compiler";
2+
import type { DiagnosticTarget, EmitContext, Program } from "@typespec/compiler";
33
import { emitFile, joinPaths, listServices, NoTarget } from "@typespec/compiler";
44
import pkgJson from "../../package.json" with { type: "json" };
55
import { emitCodeModel } from "./code-model.js";
@@ -128,8 +128,8 @@ async function runPyodideGeneration(
128128
await pyodide.runPythonAsync(pyodideGenerationCode, { globals });
129129
}
130130

131-
export function getNoSdkClientsDiagnosticTarget(program: Program): Namespace {
132-
return listServices(program)[0].type;
131+
export function getNoSdkClientsDiagnosticTarget(program: Program): DiagnosticTarget {
132+
return listServices(program)[0]?.type ?? NoTarget;
133133
}
134134

135135
async function copyPyodideOutputToHost(
@@ -191,7 +191,6 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
191191
code: "no-sdk-clients",
192192
target: getNoSdkClientsDiagnosticTarget(program),
193193
});
194-
// return;
195194
}
196195

197196
const resolvedOptions = sdkContext.emitContext.options;

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolvePath } from "@typespec/compiler";
1+
import { NoTarget, resolvePath } from "@typespec/compiler";
22
import { createTester, t } from "@typespec/compiler/testing";
33
import { strictEqual } from "assert";
44
import { it } from "vitest";
@@ -22,3 +22,16 @@ it("targets the service namespace when no SDK clients are found", async () => {
2222
false,
2323
);
2424
});
25+
26+
it("uses no target when no service exists", async () => {
27+
const { program } = await Tester.compile(`model Widget {}`);
28+
29+
const target = getNoSdkClientsDiagnosticTarget(program);
30+
strictEqual(target, NoTarget);
31+
32+
reportDiagnostic(program, { code: "no-sdk-clients", target });
33+
strictEqual(
34+
program.diagnostics.some((x) => x.code.endsWith("/no-sdk-clients")),
35+
true,
36+
);
37+
});

0 commit comments

Comments
 (0)