From b4ceb67b6e7f1f84cd5c2ac10fc8e3f7fdf94879 Mon Sep 17 00:00:00 2001 From: Mattia Basone Date: Mon, 12 Aug 2024 17:43:22 +0200 Subject: [PATCH] add logical types for attributes/annotations (#4) --- src/Objects/Schema/Generation/TypeMapper.php | 7 +++++++ .../Schema/Generation/Fixture/SimpleRecord.php | 12 ++++++++++++ .../Schema/Generation/SchemaGeneratorTest.php | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/Objects/Schema/Generation/TypeMapper.php b/src/Objects/Schema/Generation/TypeMapper.php index 2ee8f69..8d8cda0 100644 --- a/src/Objects/Schema/Generation/TypeMapper.php +++ b/src/Objects/Schema/Generation/TypeMapper.php @@ -31,6 +31,13 @@ public function __construct(SchemaGenerator $generator) TypeName::MAP => $this->simpleType(Schema::map()), TypeName::ENUM => $this->simpleType(Schema::enum()), TypeName::FIXED => $this->simpleType(Schema::fixed()), + TypeName::UUID => $this->simpleType(Schema::uuid()), + TypeName::TIME_MICROS => $this->simpleType(Schema::timeMicros()), + TypeName::TIME_MILLIS => $this->simpleType(Schema::timeMillis()), + TypeName::TIMESTAMP_MICROS => $this->simpleType(Schema::timestampMicros()), + TypeName::TIMESTAMP_MILLIS => $this->simpleType(Schema::timestampMillis()), + TypeName::LOCAL_TIMESTAMP_MICROS => $this->simpleType(Schema::localTimestampMicros()), + TypeName::LOCAL_TIMESTAMP_MILLIS => $this->simpleType(Schema::localTimestampMillis()), ]; } diff --git a/test/Objects/Schema/Generation/Fixture/SimpleRecord.php b/test/Objects/Schema/Generation/Fixture/SimpleRecord.php index ae0f8bc..74dc9d5 100644 --- a/test/Objects/Schema/Generation/Fixture/SimpleRecord.php +++ b/test/Objects/Schema/Generation/Fixture/SimpleRecord.php @@ -30,4 +30,16 @@ class SimpleRecord #[AvroType("int")] #[AvroDefault(42)] private $intType; + + /** + * @SerDe\AvroType("uuid") + */ + #[AvroType("uuid")] + private $uuidType; + + /** + * @SerDe\AvroType("timestamp-millis") + */ + #[AvroType("timestamp-millis")] + private $timestampMillisType; } diff --git a/test/Objects/Schema/Generation/SchemaGeneratorTest.php b/test/Objects/Schema/Generation/SchemaGeneratorTest.php index ae9cf32..08a02ad 100644 --- a/test/Objects/Schema/Generation/SchemaGeneratorTest.php +++ b/test/Objects/Schema/Generation/SchemaGeneratorTest.php @@ -168,6 +168,14 @@ public function it_should_generate_records_containing_records(): void 'intType', Schema::int(), Schema\Record\FieldOption::default(42) + ) + ->field( + 'uuidType', + Schema::uuid() + ) + ->field( + 'timestampMillisType', + Schema::timestampMillis() ), ) ->field( @@ -198,6 +206,13 @@ public function it_should_generate_records_containing_records_using_attributes() 'intType', Schema::int(), FieldOption::default(42) + )->field( + 'uuidType', + Schema::uuid() + ) + ->field( + 'timestampMillisType', + Schema::timestampMillis() ), ) ->field(