Skip to content

Commit 391ae18

Browse files
stephentoubCopilot
andcommitted
Fix generated C# leading underscore names
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent f8a81b6 commit 391ae18

5 files changed

Lines changed: 50 additions & 18 deletions

File tree

dotnet/src/Generated/Rpc.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/src/Generated/SessionEvents.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/test/session-event-codegen.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,38 @@ describe("session event codegen", () => {
209209
);
210210
});
211211

212+
it("drops leading underscores from C# member names while preserving JSON names", () => {
213+
const schema: JSONSchema7 = {
214+
definitions: {
215+
SessionEvent: {
216+
anyOf: [
217+
{
218+
type: "object",
219+
required: ["type", "data"],
220+
properties: {
221+
type: { const: "session.synthetic" },
222+
data: {
223+
type: "object",
224+
required: ["_meta"],
225+
properties: {
226+
_meta: { type: "string" },
227+
},
228+
},
229+
},
230+
},
231+
],
232+
},
233+
},
234+
};
235+
236+
const csharpCode = generateCSharpSessionEventsCode(schema);
237+
238+
expect(csharpCode).toContain(
239+
'[JsonPropertyName("_meta")]\n public required string Meta { get; set; }'
240+
);
241+
expect(csharpCode).not.toContain("public required string _meta");
242+
});
243+
212244
it("collapses redundant callable wrapper lambdas", () => {
213245
const schema: JSONSchema7 = {
214246
definitions: {

rust/tests/e2e/rpc_mcp_and_skills.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ use std::path::Path;
33

44
use github_copilot_sdk::rpc::{
55
ExtensionsDisableRequest, ExtensionsEnableRequest, McpAppsCallToolRequest,
6-
McpAppsDiagnoseRequest, McpAppsListToolsRequest, McpAppsReadResourceRequest,
7-
McpAppsSetHostContextDetails, McpAppsSetHostContextDetailsAvailableDisplayMode,
8-
McpAppsSetHostContextDetailsDisplayMode, McpAppsSetHostContextDetailsPlatform,
9-
McpAppsSetHostContextDetailsTheme, McpAppsSetHostContextRequest,
10-
McpCancelSamplingExecutionParams, McpDisableRequest, McpEnableRequest,
11-
McpExecuteSamplingParams, McpExecuteSamplingRequest, McpOauthLoginRequest,
12-
McpSamplingExecutionAction, McpSetEnvValueModeDetails, McpSetEnvValueModeParams,
13-
SkillsDisableRequest, SkillsEnableRequest,
6+
McpAppsDiagnoseRequest, McpAppsListToolsRequest, McpAppsSetHostContextDetails,
7+
McpAppsSetHostContextDetailsAvailableDisplayMode, McpAppsSetHostContextDetailsDisplayMode,
8+
McpAppsSetHostContextDetailsPlatform, McpAppsSetHostContextDetailsTheme,
9+
McpAppsSetHostContextRequest, McpCancelSamplingExecutionParams, McpDisableRequest,
10+
McpEnableRequest, McpExecuteSamplingParams, McpExecuteSamplingRequest, McpOauthLoginRequest,
11+
McpResourcesReadRequest, McpSamplingExecutionAction, McpSetEnvValueModeDetails,
12+
McpSetEnvValueModeParams, SkillsDisableRequest, SkillsEnableRequest,
1413
};
1514
use github_copilot_sdk::{IndexMap, McpServerConfig, McpStdioServerConfig};
1615

@@ -510,8 +509,8 @@ async fn should_report_error_when_mcp_app_resource_is_not_available() {
510509
let err = session
511510
.rpc()
512511
.mcp()
513-
.apps()
514-
.read_resource(McpAppsReadResourceRequest {
512+
.resources()
513+
.read(McpResourcesReadRequest {
515514
server_name: "missing-app-server".to_string(),
516515
uri: "ui://missing/resource.html".to_string(),
517516
})

scripts/codegen/csharp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ function stripDurationMillisecondsSuffix(name: string): string {
230230
}
231231

232232
function toCSharpPropertyName(propName: string, schema: JSONSchema7): string {
233-
return toPascalCase(isDurationProperty(schema) ? stripDurationMillisecondsSuffix(propName) : propName);
233+
const normalizedName = propName.replace(/^_+/, "") || propName;
234+
return toPascalCase(isDurationProperty(schema) ? stripDurationMillisecondsSuffix(normalizedName) : normalizedName);
234235
}
235236

236237
function isSecondsDurationPropertyName(propName: string | undefined): boolean {

0 commit comments

Comments
 (0)