Skip to content

Commit

Permalink
Merge pull request #85 from addisonj/guid_type_support
Browse files Browse the repository at this point in the history
Add support for Guid type
  • Loading branch information
eaba committed Feb 3, 2023
2 parents df260a8 + 98da3b1 commit a4cd225
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions AvroSchemaGenerator.Tests/FullSchemaTest.cs
Expand Up @@ -275,6 +275,21 @@ public void TestRecTypeRequired()
_output.WriteLine(actual);
Assert.Equal(expected, actual);
}

class WithGuidType
{
[Required]
public Guid Id { get; set; }
}
[Fact]
public void TestGuidType()
{
var expected = "{\"namespace\":\"AvroSchemaGenerator.Tests\",\"name\":\"WithGuidType\",\"type\":\"record\",\"fields\":[{\"name\":\"Id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}}]}";
var actual = typeof(WithGuidType).GetSchema();
_output.WriteLine(actual);
Assert.Equal(expected, actual);

}
private sbyte[] Write<T>(T message, ReflectWriter<T> writer)
{
var ms = new MemoryStream();
Expand Down
6 changes: 6 additions & 0 deletions SchemaGenerator/GenerateSchema.cs
Expand Up @@ -1593,6 +1593,12 @@ private static object ToAvroDataType(string type, LogicalTypeKind? kind)
{
{"type", "bytes"}, {"logicalType", "decimal"}, {"precision", 4}, {"scale", 2}
};
case "Guid":
return new Dictionary<string, object>
{
{"type", "string"}, {"logicalType", "uuid"}
};

default:
throw new ArgumentException($"{type} not supported");
}
Expand Down

0 comments on commit a4cd225

Please sign in to comment.