Skip to content

Commit a4cd225

Browse files
authored
Merge pull request #85 from addisonj/guid_type_support
Add support for Guid type
2 parents df260a8 + 98da3b1 commit a4cd225

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

AvroSchemaGenerator.Tests/FullSchemaTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ public void TestRecTypeRequired()
275275
_output.WriteLine(actual);
276276
Assert.Equal(expected, actual);
277277
}
278+
279+
class WithGuidType
280+
{
281+
[Required]
282+
public Guid Id { get; set; }
283+
}
284+
[Fact]
285+
public void TestGuidType()
286+
{
287+
var expected = "{\"namespace\":\"AvroSchemaGenerator.Tests\",\"name\":\"WithGuidType\",\"type\":\"record\",\"fields\":[{\"name\":\"Id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}}]}";
288+
var actual = typeof(WithGuidType).GetSchema();
289+
_output.WriteLine(actual);
290+
Assert.Equal(expected, actual);
291+
292+
}
278293
private sbyte[] Write<T>(T message, ReflectWriter<T> writer)
279294
{
280295
var ms = new MemoryStream();

SchemaGenerator/GenerateSchema.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,12 @@ private static object ToAvroDataType(string type, LogicalTypeKind? kind)
15931593
{
15941594
{"type", "bytes"}, {"logicalType", "decimal"}, {"precision", 4}, {"scale", 2}
15951595
};
1596+
case "Guid":
1597+
return new Dictionary<string, object>
1598+
{
1599+
{"type", "string"}, {"logicalType", "uuid"}
1600+
};
1601+
15961602
default:
15971603
throw new ArgumentException($"{type} not supported");
15981604
}

0 commit comments

Comments
 (0)