Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-server-csharp"
---

Emit C# class for models that extend another model with no additional properties
2 changes: 1 addition & 1 deletion packages/http-server-csharp/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
27 changes: 27 additions & 0 deletions packages/http-server-csharp/test/generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]],
],
);
});