Skip to content

Commit 4b9be83

Browse files
haiyuazhangCopilot
andcommitted
fix(http-client-csharp): support int64 enum/union base types
Extend InputEnumTypeValueConverter to handle InputPrimitiveTypeKind.Int64 by reading values via GetInt64() and widening InputEnumTypeIntegerValue's IntegerValue from int to long. Also include the offending kind, enum, and value names in the default-arm JsonException message so unsupported kinds are diagnosable from build output. Fixes Azure/azure-sdk-for-net#59168. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7ff22d0 commit 4b9be83

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputEnumTypeIntegerValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace Microsoft.TypeSpec.Generator.Input
55
{
66
internal class InputEnumTypeIntegerValue : InputEnumTypeValue
77
{
8-
public InputEnumTypeIntegerValue(string name, int integerValue, InputPrimitiveType valueType, string? summary, string? doc, InputEnumType? enumType = default)
8+
public InputEnumTypeIntegerValue(string name, long integerValue, InputPrimitiveType valueType, string? summary, string? doc, InputEnumType? enumType = default)
99
: base(name, integerValue, valueType, summary, doc, enumType)
1010
{
1111
IntegerValue = integerValue;
1212
}
1313

14-
public int IntegerValue { get; }
14+
public long IntegerValue { get; }
1515
}
1616
}

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputEnumTypeValueConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ internal static InputEnumTypeValue CreateEnumTypeValue(ref Utf8JsonReader reader
6060
{
6161
InputPrimitiveTypeKind.String => new InputEnumTypeStringValue(name, rawValue.Value.GetString() ?? throw new JsonException(), valueType, summary, doc, enumType) { Decorators = decorators ?? [] },
6262
InputPrimitiveTypeKind.Int32 => new InputEnumTypeIntegerValue(name, rawValue.Value.GetInt32(), valueType, summary, doc, enumType) { Decorators = decorators ?? [] },
63+
InputPrimitiveTypeKind.Int64 => new InputEnumTypeIntegerValue(name, rawValue.Value.GetInt64(), valueType, summary, doc, enumType) { Decorators = decorators ?? [] },
6364
InputPrimitiveTypeKind.Float32 => new InputEnumTypeFloatValue(name, rawValue.Value.GetSingle(), valueType, summary, doc, enumType) { Decorators = decorators ?? [] },
64-
_ => throw new JsonException()
65+
_ => throw new JsonException($"Unsupported enum valueType kind '{valueType.Kind}' for enum '{enumType.Name}' value '{name}'.")
6566
};
6667
if (id != null)
6768
{

0 commit comments

Comments
 (0)