Skip to content

Commit

Permalink
add logical types for attributes/annotations (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiabasone committed Jan 29, 2025
1 parent f7883b0 commit b4ceb67
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Objects/Schema/Generation/TypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
}

Expand Down
12 changes: 12 additions & 0 deletions test/Objects/Schema/Generation/Fixture/SimpleRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 15 additions & 0 deletions test/Objects/Schema/Generation/SchemaGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b4ceb67

Please sign in to comment.