Skip to content
Open
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
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 @@ -731,7 +731,7 @@ export class ModelInfo {
for (const prop of model.properties.values()) props.push(prop);
if (model.baseModel) {
const additional = this.getAllProperties(program, model.baseModel);
if (additional !== undefined) props.concat(additional);
if (additional !== undefined) props.push(...additional);
}

return props;
Expand Down
32 changes: 32 additions & 0 deletions packages/http-server-csharp/test/generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

function assertFileContains(fileName: string, fileContents: string, searchString: string): void {
assert.strictEqual(

Check failure on line 32 in packages/http-server-csharp/test/generation.test.ts

View workflow job for this annotation

GitHub Actions / core / Build (ubuntu-latest, Node 22.x)

[@typespec/http-server-csharp] test/generation.test.ts > emit correct code for `@error` models > emits error models when they inherit the `@error` decorator and resolves all the inheritance correctly

AssertionError: "public Error() : base(500)" not found in /test/@typespec/http-server-csharp/generated/models/Error.cs, contents of file: // Generated by @typespec/http-server-csharp // <auto-generated /> using System;using System.Text.Json;using System.Text.Json.Serialization;using TypeSpec.Helpers.JsonConverters;using TypeSpec.Helpers; namespace Microsoft.Contoso { public partial class Error : ApiError { public Error(string code, string message) : base(500, value: new{code = code,message = message}) { Code = code; MessageProp = message; } } } false !== true - Expected + Received - true + false ❯ assertFileContains test/generation.test.ts:32:10 ❯ test/generation.test.ts:82:7 ❯ compileAndValidateMultiple test/generation.test.ts:81:21 ❯ test/generation.test.ts:3121:5

Check failure on line 32 in packages/http-server-csharp/test/generation.test.ts

View workflow job for this annotation

GitHub Actions / core / Build (windows-latest, Node 22.x)

[@typespec/http-server-csharp] test/generation.test.ts > emit correct code for `@error` models > emits error models when they inherit the `@error` decorator and resolves all the inheritance correctly

AssertionError: "public Error() : base(500)" not found in Z:/test/@typespec/http-server-csharp/generated/models/Error.cs, contents of file: // Generated by @typespec/http-server-csharp // <auto-generated /> using System;using System.Text.Json;using System.Text.Json.Serialization;using TypeSpec.Helpers.JsonConverters;using TypeSpec.Helpers; namespace Microsoft.Contoso { public partial class Error : ApiError { public Error(string code, string message) : base(500, value: new{code = code,message = message}) { Code = code; MessageProp = message; } } } false !== true - Expected + Received - true + false ❯ assertFileContains test/generation.test.ts:32:10 ❯ test/generation.test.ts:82:7 ❯ compileAndValidateMultiple test/generation.test.ts:81:21 ❯ test/generation.test.ts:3121:5

Check failure on line 32 in packages/http-server-csharp/test/generation.test.ts

View workflow job for this annotation

GitHub Actions / core / Build (windows-latest, Node 24.x)

[@typespec/http-server-csharp] test/generation.test.ts > emit correct code for `@error` models > emits error models when they inherit the `@error` decorator and resolves all the inheritance correctly

AssertionError: "public Error() : base(500)" not found in Z:/test/@typespec/http-server-csharp/generated/models/Error.cs, contents of file: // Generated by @typespec/http-server-csharp // <auto-generated /> using System;using System.Text.Json;using System.Text.Json.Serialization;using TypeSpec.Helpers.JsonConverters;using TypeSpec.Helpers; namespace Microsoft.Contoso { public partial class Error : ApiError { public Error(string code, string message) : base(500, value: new{code = code,message = message}) { Code = code; MessageProp = message; } } } false !== true - Expected + Received - true + false ❯ assertFileContains test/generation.test.ts:32:10 ❯ test/generation.test.ts:82:7 ❯ compileAndValidateMultiple test/generation.test.ts:81:21 ❯ test/generation.test.ts:3121:5

Check failure on line 32 in packages/http-server-csharp/test/generation.test.ts

View workflow job for this annotation

GitHub Actions / core / Build (ubuntu-latest, Node 24.x)

[@typespec/http-server-csharp] test/generation.test.ts > emit correct code for `@error` models > emits error models when they inherit the `@error` decorator and resolves all the inheritance correctly

AssertionError: "public Error() : base(500)" not found in /test/@typespec/http-server-csharp/generated/models/Error.cs, contents of file: // Generated by @typespec/http-server-csharp // <auto-generated /> using System;using System.Text.Json;using System.Text.Json.Serialization;using TypeSpec.Helpers.JsonConverters;using TypeSpec.Helpers; namespace Microsoft.Contoso { public partial class Error : ApiError { public Error(string code, string message) : base(500, value: new{code = code,message = message}) { Code = code; MessageProp = message; } } } false !== true - Expected + Received - true + false ❯ assertFileContains test/generation.test.ts:32:10 ❯ test/generation.test.ts:82:7 ❯ compileAndValidateMultiple test/generation.test.ts:81:21 ❯ test/generation.test.ts:3121:5
fileContents.includes(searchString),
true,
`"${searchString}" not found in ${fileName}, contents of file: ${fileContents}`,
Expand Down Expand Up @@ -3422,3 +3422,35 @@
],
);
});

it("includes optional properties from generic base model when using 'is'", async () => {
await compileAndValidateSingleModel(
tester,
`
model Message<TData> {
source: string;
msgType: string;
reference?: string;
timestamp?: offsetDateTime;
data: TData;
}

model Report {
value: string;
}

model ReportMessage is Message<Report>;

@route("/report") @get op getReport(): ReportMessage;
Comment on lines +3430 to +3444
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
model Message<TData> {
source: string;
msgType: string;
reference?: string;
timestamp?: offsetDateTime;
data: TData;
}
model Report {
value: string;
}
model ReportMessage is Message<Report>;
@route("/report") @get op getReport(): ReportMessage;
model Template<T> {
baseProp: T
}
model ReportMessage is Template<string>;
op getReport(): ReportMessage;

to keep the test as relevant as possible

`,
"ReportMessage.cs",
[
"public partial class ReportMessage",
"public string Source { get; set; }",
"public string MsgType { get; set; }",
"public string Reference { get; set; }",
"public DateTimeOffset? Timestamp { get; set; }",
"public Report Data { get; set; }",
],
);
});
Loading