Generate accessors for aliases
See https://issues.apache.org/jira/browse/AVRO-2320 (for the java compiler).
See https://avro.apache.org/docs/1.8.2/spec.html#Aliases (for the spec)
Aliased named schema (fixed, enum, record)
Aliased named schema could trigger generation of a child class.
Example:
{
"type": "record",
"name": "com.acme.Foo",
"aliases": ["Bar"],
"fields": [
{ "name": "plop", "type": "int" }
]
}
<?php
/**
* Autogenerated by jaumo/php-avro-class-generator
*
* DO NOT EDIT DIRECTLY
*/
declare (strict_types=1);
namespace Com\Acme;
final class Foo
{
/** @var null|\AvroSchema */
private static $schema;
/** @var int */
private $plop;
public function getSchema() : \AvroSchema
{
if (null === self::$schema) {
self::$schema = \AvroSchema::parse('{"type":"record","name":"Foo","namespace":"com.acme","aliases":["Bar"],"fields":[{"name":"plop","type":"int"}]}');
}
return self::$schema;
}
public function getPlop() : int
{
return $this->plop;
}
public function withPlop(int $plop) : self
{
$self = clone $this;
$self->plop = $plop;
return $self;
}
private function setPlop(int $plop) : void
{
$this->plop = $plop;
}
public function normalize() : array
{
return ['plop' => $this->plop];
}
public static function denormalize(array $record) : self
{
$self = new self();
$self->setPlop($record['plop'] ?? null);
return $self;
}
}
<?php
/**
* Autogenerated by jaumo/php-avro-class-generator
*
* DO NOT EDIT DIRECTLY
*/
declare (strict_types=1);
namespace Com\Acme;
final class Bar extends Foo
{
}
Aliased field
Aliased field could trigger generation of "duplicated" accessors with the same body (the fact that it is an alias field could be mentioned in the property comment, and in the accessor methods comment).
Example:
{
"type": "record",
"name": "com.acme.Foo",
"fields": [
{ "name": "plop", "type": "int", "aliases": ["plip"] }
]
}
<?php
/**
* Autogenerated by jaumo/php-avro-class-generator
*
* DO NOT EDIT DIRECTLY
*/
declare (strict_types=1);
namespace Com\Acme;
class Foo
{
/** @var null|\AvroSchema */
private static $schema;
/** @var int */
private $plop;
public function getSchema() : \AvroSchema
{
if (null === self::$schema) {
self::$schema = \AvroSchema::parse('{"type":"record","name":"Foo","namespace":"com.acme","fields":[{"name":"plop","type":"int","aliases":["plip"]}]}');
}
return self::$schema;
}
public function getPlop() : int
{
return $this->plop;
}
public function withPlop(int $plop) : self
{
$self = clone $this;
$self->plop = $plop;
return $self;
}
private function setPlop(int $plop) : void
{
$this->plop = $plop;
}
public function getPlip() : int
{
return $this->plop;
}
public function withPlip(int $plip) : self
{
$self = clone $this;
$self->plop = $plip;
return $self;
}
public function normalize() : array
{
return ['plop' => $this->plop];
}
public static function denormalize(array $record) : self
{
$self = new self();
$self->setPlop($record['plop'] ?? null);
return $self;
}
}
Edited by Gildas Quéméner