Skip to content

Commit

Permalink
chore: 5.x update PropertyDescriberInterface::supports()
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Nov 12, 2024
1 parent c431718 commit 5f11f3a
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private function describeProperty(array $types, Model $model, OA\Schema $propert
if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
$propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($propertyDescriber->supports($types)) {
if ($propertyDescriber->supports($types, $model->getSerializationContext())) {
$propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext());

return;
Expand Down
4 changes: 2 additions & 2 deletions src/PropertyDescriber/ArrayPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
foreach ($types[0]->getCollectionValueTypes() as $type) {
// Handle list pseudo type
// https://symfony.com/doc/current/components/property_info.html#type-getcollectionkeytypes-type-getcollectionvaluetypes
if ($this->supports([$type]) && [] === $type->getCollectionValueTypes()) {
if ($this->supports([$type], $context) && [] === $type->getCollectionValueTypes()) {
continue;
}

$this->propertyDescriber->describe([$type], $property, $groups, $schema, $context);
}
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
if (1 !== count($types) || !$types[0]->isCollection()) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/BooleanPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->type = 'boolean';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_BOOL === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/CompoundPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
}
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return count($types) >= 2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/DateTimePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->format = 'date-time';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType()
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/DictionaryPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $groups, $schema, $context);
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& $types[0]->isCollection()
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/FloatPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->format = 'float';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_FLOAT === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/IntegerPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->type = 'integer';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_INT === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/NullablePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$this->propertyDescriber->describe($types, $property, $groups, $schema, $context);
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
foreach ($types as $type) {
if ($type->isNullable()) {
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/ObjectPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->ref = $this->modelRegistry->register(new Model($type, $groups, [], $context));
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType();
Expand Down
13 changes: 7 additions & 6 deletions src/PropertyDescriber/PropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
);
}

if (null === $propertyDescriber = $this->getPropertyDescriber($types)) {
if (null === $propertyDescriber = $this->getPropertyDescriber($types, $context)) {
return;
}

Expand All @@ -69,9 +69,9 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$this->called = []; // Reset recursion helper
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return null !== $this->getPropertyDescriber($types);
return null !== $this->getPropertyDescriber($types, $context);
}

/**
Expand All @@ -83,9 +83,10 @@ private function getHash(array $types): string
}

/**
* @param Type[] $types
* @param Type[] $types
* @param array<string, mixed> $context
*/
private function getPropertyDescriber(array $types): ?PropertyDescriberInterface
private function getPropertyDescriber(array $types, array $context): ?PropertyDescriberInterface
{
foreach ($this->propertyDescribers as $propertyDescriber) {
/* BC layer for Symfony < 6.3 @see https://symfony.com/doc/6.3/service_container/tags.html#reference-tagged-services */
Expand All @@ -108,7 +109,7 @@ private function getPropertyDescriber(array $types): ?PropertyDescriberInterface
$propertyDescriber->setPropertyDescriber($this);
}

if ($propertyDescriber->supports($types)) {
if ($propertyDescriber->supports($types, $context)) {
return $propertyDescriber;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/PropertyDescriber/PropertyDescriberInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ interface PropertyDescriberInterface
public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */);

/**
* @param Type[] $types
* @param Type[] $types
* @param array<string, mixed> $context Context options for describing the property
*/
public function supports(array $types): bool;
public function supports(array $types, array $context = []): bool;
}
2 changes: 1 addition & 1 deletion src/PropertyDescriber/StringPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->type = 'string';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types) && Type::BUILTIN_TYPE_STRING === $types[0]->getBuiltinType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyDescriber/UuidPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
$property->format = 'uuid';
}

public function supports(array $types): bool
public function supports(array $types, array $context = []): bool
{
return 1 === count($types)
&& Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType()
Expand Down

0 comments on commit 5f11f3a

Please sign in to comment.