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"]], + ], + ); +});