Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jul 13, 2018
1 parent a10bb34 commit e14aa17
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/SchemaGenerator/ObjectSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public function generate(\ReflectionClass $reflectionClass, array $context = [])
}
if (($mapping['targetEntity'] ?? null) === $reflectionClass->name) {
// todo Is there a better way to handle this case?
$schema['properties'][$property] = $this->typeGenerator->generate($property, $mapping, ['serializer_groups' => []] + $context);
$schema['properties'][$property] = $this->typeGenerator->generate($mapping, ['serializer_groups' => []] + $context);
} else {
$schema['properties'][$property] = $this->typeGenerator->generate($property, $mapping, $context);
$schema['properties'][$property] = $this->typeGenerator->generate($mapping, $context);
}
unset($this->path[$context['depth']]);
if (false === ($mapping['nullable'] ?? true)) {
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/ArrayTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/
final class ArrayTypeGenerator implements TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], [Type::TARRAY, Type::SIMPLE_ARRAY, Type::JSON_ARRAY], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
$type = ['type' => ['array', 'object']];
if ($mapping['nullable'] ?? false) {
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/CollectionTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public function __construct(ContainerInterface $container = null)
$this->container = $container;
}

public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
return [
'type' => 'array',
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/DateTimeTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
final class DateTimeTypeGenerator implements TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['datetime', 'date', 'time'], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
$type = [
'type' => ['string'],
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/DefaultTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
final class DefaultTypeGenerator implements TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return true;
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
if (!in_array($mapping['type'], ['integer', 'number', 'boolean', 'object', 'array', 'string', 'null', 'any'], true)) {
$mapping['type'] = 'any';
Expand Down
10 changes: 6 additions & 4 deletions src/SchemaGenerator/TypeGenerator/EmailTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ final class EmailTypeGenerator implements TypeGeneratorInterface, TypeGeneratorA
{
use TypeGeneratorAwareTrait;

public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return 'email' === $property;
return 'email' === $mapping['fieldName'];
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
return ['pattern' => '^[\\w\\.-]+@[\\w\\.-]+\\.[A-z]+$'] + $this->typeGenerator->generate('', $mapping, $context);
unset($mapping['fieldName']);

return ['pattern' => '^[\\w\\.-]+@[\\w\\.-]+\\.[A-z]+$'] + $this->typeGenerator->generate($mapping, $context);
}
}
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/EntityTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public function setAnnotationReader(Reader $reader)
$this->reader = $reader;
}

public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
$reflectionClass = new \ReflectionClass($mapping['targetEntity']);
if (0 < count($this->propertyInfo->getProperties($mapping['targetEntity'], $context))) {
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/IntegerTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
final class IntegerTypeGenerator implements TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['integer', 'smallint', 'bigint'], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
$type = ['type' => ['integer']];
if ($mapping['nullable'] ?? false) {
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/NumberTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
final class NumberTypeGenerator implements TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['int', 'float', 'decimal'], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
$type = ['type' => ['number']];
if ($mapping['nullable'] ?? false) {
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/StringTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
final class StringTypeGenerator implements TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['string', 'text'], true);
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
$type = ['type' => ['string']];
if ($mapping['nullable'] ?? false) {
Expand Down
8 changes: 4 additions & 4 deletions src/SchemaGenerator/TypeGenerator/TypeGeneratorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public function __construct(array $generators)
$this->generators = $generators;
}

public function supports(string $property, array $mapping, array $context = []): bool
public function supports(array $mapping, array $context = []): bool
{
return true;
}

public function generate(string $property, array $mapping, array $context = []): array
public function generate(array $mapping, array $context = []): array
{
foreach ($this->generators as $generator) {
if ($generator->supports($property, $mapping, $context)) {
return $generator->generate($property, $mapping, $context);
if ($generator->supports($mapping, $context)) {
return $generator->generate($mapping, $context);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/TypeGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
interface TypeGeneratorInterface
{
public function supports(string $property, array $mapping, array $context = []): bool;
public function supports(array $mapping, array $context = []): bool;

public function generate(string $property, array $mapping, array $context = []): array;
public function generate(array $mapping, array $context = []): array;
}

0 comments on commit e14aa17

Please sign in to comment.