From 2d0b9fb01e7a5f9d5792c7449cdb91c8ff7b5fa9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 02:28:50 +0000 Subject: [PATCH 1/2] Initial plan From d993f90c6eb04c875690459bedc46fd5b021c5df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 02:41:25 +0000 Subject: [PATCH 2/2] fix: emit C# class for models extending another model with no additional properties Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/606be68b-2055-4873-8f57-07dc41156fd0 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com> --- ...-empty-derived-model-emission-2026-3-27.md | 7 +++++ packages/http-server-csharp/src/lib/utils.ts | 2 +- .../test/generation.test.ts | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .chronus/changes/fix-empty-derived-model-emission-2026-3-27.md diff --git a/.chronus/changes/fix-empty-derived-model-emission-2026-3-27.md b/.chronus/changes/fix-empty-derived-model-emission-2026-3-27.md new file mode 100644 index 00000000000..5853e64894b --- /dev/null +++ b/.chronus/changes/fix-empty-derived-model-emission-2026-3-27.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-server-csharp" +--- + +Emit C# class for models that extend another model with no additional properties diff --git a/packages/http-server-csharp/src/lib/utils.ts b/packages/http-server-csharp/src/lib/utils.ts index 2b64cb84fea..10955435bb7 100644 --- a/packages/http-server-csharp/src/lib/utils.ts +++ b/packages/http-server-csharp/src/lib/utils.ts @@ -1059,7 +1059,7 @@ export function getControllerReturnStatement( export function isEmptyResponseModel(program: Program, model: Type): boolean { if (model.kind !== "Model") return false; - if (model.properties.size === 0) return true; + if (model.properties.size === 0 && !model.baseModel) return true; return ( model.properties.size === 1 && diff --git a/packages/http-server-csharp/test/generation.test.ts b/packages/http-server-csharp/test/generation.test.ts index 311289ba764..5cb6dfacfca 100644 --- a/packages/http-server-csharp/test/generation.test.ts +++ b/packages/http-server-csharp/test/generation.test.ts @@ -3395,3 +3395,30 @@ describe("collection type: defined as emitter option", () => { ); }); }); + +it("emits class for model extending another model with no additional properties", async () => { + await compileAndValidateMultiple( + tester, + ` + model Foo { + id: int32; + name: string; + } + + model Baz extends Foo {} + + @route("/foo/{id}") @get op getFoo(id: int32): Foo; + `, + [ + [ + "Foo.cs", + [ + "public partial class Foo", + "public int Id { get; set; }", + "public string Name { get; set; }", + ], + ], + ["Baz.cs", ["public partial class Baz : Foo"]], + ], + ); +});