Strip Ms suffix for duration properties#1339
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9d6ea12 to
4d0ed58
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the Python and C# code generators to produce more idiomatic SDK member names for duration-valued schema properties by removing trailing Ms from the generated member name (while preserving the original JSON/wire property names via serialization metadata). This aligns the public SDK surface with the fact that these fields already map to timedelta/TimeSpan-like types, without changing the wire contract.
Changes:
- Python codegen: detect duration-valued properties and strip a trailing
Msfrom the generated Python field name (snake_case), while keeping JSON keys unchanged. - C# codegen: apply the same
Ms-stripping rule for duration-valued properties, including nullable wrappers, while keeping[JsonPropertyName("...Ms")]intact. - Regenerate Python/.NET generated outputs and extend Node-based codegen tests to validate name stripping + JSON-name preservation.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/python.ts | Adds duration-property detection and Ms suffix stripping when computing Python field names. |
| scripts/codegen/csharp.ts | Adds duration-aware Ms suffix stripping for generated C# property names and improves nullable duration detection. |
| python/copilot/generated/session_events.py | Regenerated output reflecting renamed duration members (e.g., ttft_ms → ttft) while preserving JSON keys. |
| nodejs/test/python-codegen.test.ts | Adds a test covering Ms stripping behavior and JSON-name preservation (Python + C#). |
| dotnet/test/Unit/SessionEventSerializationTests.cs | Updates unit test to use the renamed .NET duration property. |
| dotnet/src/Generated/SessionEvents.cs | Regenerated session event types with Ms-less duration property names and unchanged [JsonPropertyName]. |
| dotnet/src/Generated/Rpc.cs | Regenerated RPC types with Ms-less duration property names and unchanged [JsonPropertyName]. |
Copilot's findings
- Files reviewed: 4/7 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR makes a well-scoped, intentional distinction across the SDK implementations:
The approach is consistent: only SDKs that map duration fields to a dedicated native duration type get the suffix stripped, because in those cases the type already conveys "this is a duration" and the Additional consistency checks:
No cross-SDK consistency issues found.
|
Duration-formatted schema fields already map to timespan-like SDK types in Python and C#, but generated member names still exposed millisecond-oriented wire suffixes like
durationMs. This keeps the wire contract unchanged while making the generated SDK surface more idiomatic for duration values.Summary
Msfrom duration property names in the Python and C# generators.Validation
npm --prefix .\nodejs test -- python-codegen.test.ts