diff --git a/gen/gen.go b/gen/gen.go index 5d8c081d..78454d90 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -319,6 +319,8 @@ func (g *Generator) resolveLogicalSchema(logicalType avro.LogicalType) string { typ = "*big.Rat" case "duration": typ = "avro.LogicalDuration" + case "uuid": + typ = "string" } if strings.Contains(typ, "time") { g.addImport("time") diff --git a/gen/testdata/golden.avsc b/gen/testdata/golden.avsc index 0a8876fc..5c2300e8 100644 --- a/gen/testdata/golden.avsc +++ b/gen/testdata/golden.avsc @@ -258,6 +258,13 @@ { "name": "ref", "type": "record2InNullableUnion" + }, + { + "name": "uuid", + "type": { + "type": "string", + "logicalType": "uuid" + } } ] } diff --git a/gen/testdata/golden.go b/gen/testdata/golden.go index b6f0c14e..66297736 100644 --- a/gen/testdata/golden.go +++ b/gen/testdata/golden.go @@ -78,4 +78,5 @@ type Test struct { NonNullableRecordUnion any `avro:"nonNullableRecordUnion"` NullableRecordUnionWith3Options any `avro:"nullableRecordUnionWith3Options"` Ref Record2InNullableUnion `avro:"ref"` + UUID string `avro:"uuid"` } diff --git a/gen/testdata/golden_encoders.go b/gen/testdata/golden_encoders.go index f5b5efe4..d3c0fbbb 100644 --- a/gen/testdata/golden_encoders.go +++ b/gen/testdata/golden_encoders.go @@ -214,9 +214,10 @@ type Test struct { NonNullableRecordUnion any `avro:"nonNullableRecordUnion"` NullableRecordUnionWith3Options any `avro:"nullableRecordUnionWith3Options"` Ref Record2InNullableUnion `avro:"ref"` + UUID string `avro:"uuid"` } -var schemaTest = avro.MustParse(`{"name":"a.b.test","type":"record","fields":[{"name":"aString","type":"string"},{"name":"aBoolean","type":"boolean"},{"name":"anInt","type":"int"},{"name":"aFloat","type":"float"},{"name":"aDouble","type":"double"},{"name":"aLong","type":"long"},{"name":"justBytes","type":"bytes"},{"name":"primitiveNullableArrayUnion","type":["null",{"type":"array","items":"string"}]},{"name":"innerRecord","type":{"name":"a.c.InnerRecord","type":"record","fields":[{"name":"innerJustBytes","type":"bytes"},{"name":"innerPrimitiveNullableArrayUnion","type":["null",{"type":"array","items":"string"}]}]}},{"name":"anEnum","type":{"name":"a.b.Cards","type":"enum","symbols":["SPADES","HEARTS","DIAMONDS","CLUBS"]}},{"name":"aFixed","type":{"name":"a.b.fixedField","type":"fixed","size":7}},{"name":"aLogicalFixed","type":{"name":"a.b.logicalDuration","type":"fixed","size":12,"logicalType":"duration"}},{"name":"anotherLogicalFixed","type":"a.b.logicalDuration"},{"name":"mapOfStrings","type":{"type":"map","values":"string"}},{"name":"mapOfRecords","type":{"type":"map","values":{"name":"a.b.RecordInMap","type":"record","fields":[{"name":"name","type":"string"}]}}},{"name":"aDate","type":{"type":"int","logicalType":"date"}},{"name":"aDuration","type":{"type":"int","logicalType":"time-millis"}},{"name":"aLongTimeMicros","type":{"type":"long","logicalType":"time-micros"}},{"name":"aLongTimestampMillis","type":{"type":"long","logicalType":"timestamp-millis"}},{"name":"aLongTimestampMicro","type":{"type":"long","logicalType":"timestamp-micros"}},{"name":"aBytesDecimal","type":{"type":"bytes","logicalType":"decimal","precision":4,"scale":2}},{"name":"aRecordArray","type":{"type":"array","items":{"name":"a.b.recordInArray","type":"record","fields":[{"name":"aString","type":"string"}]}}},{"name":"nullableRecordUnion","type":["null",{"name":"a.b.recordInNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]}]},{"name":"nonNullableRecordUnion","type":[{"name":"a.b.record1InNonNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]},{"name":"a.b.record2InNonNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]}]},{"name":"nullableRecordUnionWith3Options","type":["null",{"name":"a.b.record1InNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]},{"name":"a.b.record2InNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]}]},{"name":"ref","type":"a.b.record2InNullableUnion"}]}`) +var schemaTest = avro.MustParse(`{"name":"a.b.test","type":"record","fields":[{"name":"aString","type":"string"},{"name":"aBoolean","type":"boolean"},{"name":"anInt","type":"int"},{"name":"aFloat","type":"float"},{"name":"aDouble","type":"double"},{"name":"aLong","type":"long"},{"name":"justBytes","type":"bytes"},{"name":"primitiveNullableArrayUnion","type":["null",{"type":"array","items":"string"}]},{"name":"innerRecord","type":{"name":"a.c.InnerRecord","type":"record","fields":[{"name":"innerJustBytes","type":"bytes"},{"name":"innerPrimitiveNullableArrayUnion","type":["null",{"type":"array","items":"string"}]}]}},{"name":"anEnum","type":{"name":"a.b.Cards","type":"enum","symbols":["SPADES","HEARTS","DIAMONDS","CLUBS"]}},{"name":"aFixed","type":{"name":"a.b.fixedField","type":"fixed","size":7}},{"name":"aLogicalFixed","type":{"name":"a.b.logicalDuration","type":"fixed","size":12,"logicalType":"duration"}},{"name":"anotherLogicalFixed","type":"a.b.logicalDuration"},{"name":"mapOfStrings","type":{"type":"map","values":"string"}},{"name":"mapOfRecords","type":{"type":"map","values":{"name":"a.b.RecordInMap","type":"record","fields":[{"name":"name","type":"string"}]}}},{"name":"aDate","type":{"type":"int","logicalType":"date"}},{"name":"aDuration","type":{"type":"int","logicalType":"time-millis"}},{"name":"aLongTimeMicros","type":{"type":"long","logicalType":"time-micros"}},{"name":"aLongTimestampMillis","type":{"type":"long","logicalType":"timestamp-millis"}},{"name":"aLongTimestampMicro","type":{"type":"long","logicalType":"timestamp-micros"}},{"name":"aBytesDecimal","type":{"type":"bytes","logicalType":"decimal","precision":4,"scale":2}},{"name":"aRecordArray","type":{"type":"array","items":{"name":"a.b.recordInArray","type":"record","fields":[{"name":"aString","type":"string"}]}}},{"name":"nullableRecordUnion","type":["null",{"name":"a.b.recordInNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]}]},{"name":"nonNullableRecordUnion","type":[{"name":"a.b.record1InNonNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]},{"name":"a.b.record2InNonNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]}]},{"name":"nullableRecordUnionWith3Options","type":["null",{"name":"a.b.record1InNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]},{"name":"a.b.record2InNullableUnion","type":"record","fields":[{"name":"aString","type":"string"}]}]},{"name":"ref","type":"a.b.record2InNullableUnion"},{"name":"uuid","type":{"type":"string","logicalType":"uuid"}}]}`) // Schema returns the schema for Test. func (o *Test) Schema() avro.Schema { diff --git a/gen/testdata/golden_fullname.go b/gen/testdata/golden_fullname.go index e5724490..cf81a16a 100644 --- a/gen/testdata/golden_fullname.go +++ b/gen/testdata/golden_fullname.go @@ -78,4 +78,5 @@ type ABTest struct { NonNullableRecordUnion any `avro:"nonNullableRecordUnion"` NullableRecordUnionWith3Options any `avro:"nullableRecordUnionWith3Options"` Ref ABRecord2InNullableUnion `avro:"ref"` + UUID string `avro:"uuid"` }