Skip to content

Commit 04c2bd8

Browse files
stephentoubCopilot
andcommitted
Address review: Range(Type,string,string) for long, add SDK using to Rpc
Use Range(typeof(long), ...) overload since RangeAttribute has no long constructor. Add 'using GitHub.Copilot.SDK' to Rpc.cs header so MillisecondsTimeSpanConverter resolves when duration fields exist. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 56ba3cf commit 04c2bd8

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

dotnet/src/Generated/Rpc.cs

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

scripts/codegen/csharp.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,24 @@ function emitDataAnnotations(schema: JSONSchema7, indent: string): string[] {
220220
attrs.push(`${indent}[Base64String]`);
221221
}
222222

223-
// [Range]for minimum/maximum
223+
// [Range] for minimum/maximum
224224
const hasMin = typeof schema.minimum === "number";
225225
const hasMax = typeof schema.maximum === "number";
226226
if (hasMin || hasMax) {
227-
const min = hasMin ? String(schema.minimum) : (schema.type === "integer" ? "long.MinValue" : "double.MinValue");
228-
const max = hasMax ? String(schema.maximum) : (schema.type === "integer" ? "long.MaxValue" : "double.MaxValue");
229227
const namedArgs: string[] = [];
230228
if (schema.exclusiveMinimum === true) namedArgs.push("MinimumIsExclusive = true");
231229
if (schema.exclusiveMaximum === true) namedArgs.push("MaximumIsExclusive = true");
232230
const namedSuffix = namedArgs.length > 0 ? `, ${namedArgs.join(", ")}` : "";
233-
attrs.push(`${indent}[Range(${min}, ${max}${namedSuffix})]`);
231+
if (schema.type === "integer") {
232+
// Use Range(Type, string, string) overload since RangeAttribute has no long constructor
233+
const min = hasMin ? String(schema.minimum) : "long.MinValue";
234+
const max = hasMax ? String(schema.maximum) : "long.MaxValue";
235+
attrs.push(`${indent}[Range(typeof(long), "${min}", "${max}"${namedSuffix})]`);
236+
} else {
237+
const min = hasMin ? String(schema.minimum) : "double.MinValue";
238+
const max = hasMax ? String(schema.maximum) : "double.MaxValue";
239+
attrs.push(`${indent}[Range(${min}, ${max}${namedSuffix})]`);
240+
}
234241
}
235242

236243
// [RegularExpression] for pattern
@@ -1190,6 +1197,7 @@ using System.ComponentModel.DataAnnotations;
11901197
using System.Diagnostics.CodeAnalysis;
11911198
using System.Text.Json;
11921199
using System.Text.Json.Serialization;
1200+
using GitHub.Copilot.SDK;
11931201
using StreamJsonRpc;
11941202
11951203
namespace GitHub.Copilot.SDK.Rpc;

0 commit comments

Comments
 (0)