Skip to content

Commit f8c8005

Browse files
fix: address PR review feedback for codegen
- Python: remove unnecessary pass in empty dataclasses with methods - C#: properly type string|null as string? instead of object - Go: omit optional fields when nil instead of sending null Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7292e7c commit f8c8005

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

dotnet/src/Generated/Rpc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public class SessionPlanReadResult
253253

254254
/// <summary>The content of plan.md, or null if it does not exist</summary>
255255
[JsonPropertyName("content")]
256-
public object Content { get; set; }
256+
public string? Content { get; set; }
257257
}
258258

259259
internal class ReadRequest

go/rpc/generated_rpc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ type FleetRpcApi struct {
457457
func (a *FleetRpcApi) Start(ctx context.Context, params *SessionFleetStartParams) (*SessionFleetStartResult, error) {
458458
req := map[string]interface{}{"sessionId": a.sessionID}
459459
if params != nil {
460-
req["prompt"] = params.Prompt
460+
if params.Prompt != nil {
461+
req["prompt"] = *params.Prompt
462+
}
461463
}
462464
raw, err := a.client.Request("session.fleet.start", req)
463465
if err != nil {

python/copilot/generated/rpc.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,6 @@ def to_dict(self) -> dict:
565565

566566
@dataclass
567567
class SessionPlanUpdateResult:
568-
pass
569-
570568
@staticmethod
571569
def from_dict(obj: Any) -> 'SessionPlanUpdateResult':
572570
assert isinstance(obj, dict)
@@ -596,8 +594,6 @@ def to_dict(self) -> dict:
596594

597595
@dataclass
598596
class SessionPlanDeleteResult:
599-
pass
600-
601597
@staticmethod
602598
def from_dict(obj: Any) -> 'SessionPlanDeleteResult':
603599
assert isinstance(obj, dict)
@@ -661,8 +657,6 @@ def to_dict(self) -> dict:
661657

662658
@dataclass
663659
class SessionWorkspaceCreateFileResult:
664-
pass
665-
666660
@staticmethod
667661
def from_dict(obj: Any) -> 'SessionWorkspaceCreateFileResult':
668662
assert isinstance(obj, dict)

scripts/codegen/csharp.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ function schemaTypeToCSharp(schema: JSONSchema7, required: boolean, knownTypes:
6767
if (schema.anyOf) {
6868
const nonNull = schema.anyOf.filter((s) => typeof s === "object" && s.type !== "null");
6969
if (nonNull.length === 1 && typeof nonNull[0] === "object") {
70-
return schemaTypeToCSharp(nonNull[0] as JSONSchema7, false, knownTypes) + "?";
70+
// Pass required=true to get the base type, then add "?" for nullable
71+
return schemaTypeToCSharp(nonNull[0] as JSONSchema7, true, knownTypes) + "?";
7172
}
7273
}
7374
if (schema.$ref) {
@@ -76,6 +77,15 @@ function schemaTypeToCSharp(schema: JSONSchema7, required: boolean, knownTypes:
7677
}
7778
const type = schema.type;
7879
const format = schema.format;
80+
// Handle type: ["string", "null"] patterns (nullable string)
81+
if (Array.isArray(type)) {
82+
const nonNullTypes = type.filter((t) => t !== "null");
83+
if (nonNullTypes.length === 1 && nonNullTypes[0] === "string") {
84+
if (format === "uuid") return "Guid?";
85+
if (format === "date-time") return "DateTimeOffset?";
86+
return "string?";
87+
}
88+
}
7989
if (type === "string") {
8090
if (format === "uuid") return required ? "Guid" : "Guid?";
8191
if (format === "date-time") return required ? "DateTimeOffset" : "DateTimeOffset?";

scripts/codegen/go.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ function emitMethod(lines: string[], receiver: string, name: string, method: Rpc
246246
const resultType = toPascalCase(method.rpcMethod) + "Result";
247247

248248
const paramProps = method.params?.properties || {};
249+
const requiredParams = new Set(method.params?.required || []);
249250
const nonSessionParams = Object.keys(paramProps).filter((k) => k !== "sessionId");
250251
const hasParams = isSession ? nonSessionParams.length > 0 : Object.keys(paramProps).length > 0;
251252
const paramsType = hasParams ? toPascalCase(method.rpcMethod) + "Params" : "";
@@ -261,7 +262,16 @@ function emitMethod(lines: string[], receiver: string, name: string, method: Rpc
261262
if (hasParams) {
262263
lines.push(` if params != nil {`);
263264
for (const pName of nonSessionParams) {
264-
lines.push(` req["${pName}"] = params.${toGoFieldName(pName)}`);
265+
const goField = toGoFieldName(pName);
266+
const isOptional = !requiredParams.has(pName);
267+
if (isOptional) {
268+
// Optional fields are pointers - only add when non-nil and dereference
269+
lines.push(` if params.${goField} != nil {`);
270+
lines.push(` req["${pName}"] = *params.${goField}`);
271+
lines.push(` }`);
272+
} else {
273+
lines.push(` req["${pName}"] = params.${goField}`);
274+
}
265275
}
266276
lines.push(` }`);
267277
}

scripts/codegen/python.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ async function generateRpc(schemaPath?: string): Promise<void> {
160160
typesCode = typesCode.replace(/: Any$/gm, ": Any = None");
161161
// Fix bare except: to use Exception (required by ruff/pylint)
162162
typesCode = typesCode.replace(/except:/g, "except Exception:");
163+
// Remove unnecessary pass when class has methods (quicktype generates pass for empty schemas)
164+
typesCode = typesCode.replace(/^(\s*)pass\n\n(\s*@staticmethod)/gm, "$2");
163165

164166
const lines: string[] = [];
165167
lines.push(`"""

0 commit comments

Comments
 (0)