Skip to content

Commit

Permalink
chore: 5.x update PropertyDescriberInterface::describe()
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Nov 12, 2024
1 parent 50ab5f7 commit f4b1cfe
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 266 deletions.
12 changes: 11 additions & 1 deletion UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ This parameter was deprecated since `4.25.2`

## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface`

## BC BREAK: Removed passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()`
## BC BREAK: Removed passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()`

## BC BREAK: Updated `PropertyDescriberInterface::describe()` signature
```diff
- public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */);
+ public function describe(array $types, Schema $property, array $context = []);
```

`$groups` are now passed in `$context` and can be accessed via `$context['groups']`.

`$schema` has been removed with no replacement.
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,6 @@ parameters:
count: 1
path: src/Describer/ExternalDocDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/ArrayPropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/CompoundPropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/DictionaryPropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/NullablePropertyDescriber.php

-
message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#"
count: 1
path: src/PropertyDescriber/PropertyDescriber.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$context$#"
count: 1
path: src/PropertyDescriber/PropertyDescriberInterface.php

-
message: "#^PHPDoc tag @param references unknown parameter\\: \\$schema$#"
count: 1
path: src/PropertyDescriber/PropertyDescriberInterface.php

-
message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#"
count: 2
Expand Down
6 changes: 3 additions & 3 deletions src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function describe(Model $model, OA\Schema $schema)
throw new \LogicException(sprintf('The PropertyInfo component was not able to guess the type of %s::$%s. You may need to add a `@var` annotation or use `#[OA\Property(type="")]` to make its type explicit.', $class, $propertyName));
}

$this->describeProperty($types, $model, $property, $propertyName, $schema);
$this->describeProperty($types, $model, $property, $propertyName);
}

$this->markRequiredProperties($schema);
Expand Down Expand Up @@ -178,13 +178,13 @@ private function camelize(string $string): string
/**
* @param Type[] $types
*/
private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName, OA\Schema $schema): void
private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName): void
{
if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) {
$this->propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($this->propertyDescriber->supports($types)) {
$this->propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext());
$this->propertyDescriber->describe($types, $property, $model->getSerializationContext());

return;
}
Expand Down
22 changes: 2 additions & 20 deletions src/PropertyDescriber/ArrayPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,8 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'array';
/** @var OA\Items $property */
$property = Util::getChild($property, OA\Items::class);
Expand All @@ -56,7 +38,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul
continue;
}

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

Expand Down
20 changes: 1 addition & 19 deletions src/PropertyDescriber/BooleanPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,8 @@ class BooleanPropertyDescriber implements PropertyDescriberInterface
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'boolean';
}

Expand Down
22 changes: 2 additions & 20 deletions src/PropertyDescriber/CompoundPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,14 @@ class CompoundPropertyDescriber implements PropertyDescriberInterface, ModelRegi
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->oneOf = Generator::UNDEFINED !== $property->oneOf ? $property->oneOf : [];

foreach ($types as $type) {
$property->oneOf[] = $schema = Util::createChild($property, OA\Schema::class, []);

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

Expand Down
20 changes: 1 addition & 19 deletions src/PropertyDescriber/DateTimePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,8 @@ class DateTimePropertyDescriber implements PropertyDescriberInterface
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'string';
$property->format = 'date-time';
}
Expand Down
22 changes: 2 additions & 20 deletions src/PropertyDescriber/DictionaryPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,13 @@ final class DictionaryPropertyDescriber implements PropertyDescriberInterface, M
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'object';
/** @var OA\AdditionalProperties $additionalProperties */
$additionalProperties = Util::getChild($property, OA\AdditionalProperties::class);

$this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $groups, $schema, $context);
$this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $context);
}

public function supports(array $types): bool
Expand Down
20 changes: 1 addition & 19 deletions src/PropertyDescriber/FloatPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,8 @@ class FloatPropertyDescriber implements PropertyDescriberInterface
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'number';
$property->format = 'float';
}
Expand Down
20 changes: 1 addition & 19 deletions src/PropertyDescriber/IntegerPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,8 @@ class IntegerPropertyDescriber implements PropertyDescriberInterface
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$property->type = 'integer';
}

Expand Down
22 changes: 2 additions & 20 deletions src/PropertyDescriber/NullablePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,13 @@ final class NullablePropertyDescriber implements PropertyDescriberInterface, Pro
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

if (Generator::UNDEFINED === $property->nullable) {
$property->nullable = true;
}

$this->propertyDescriber->describe($types, $property, $groups, $schema, $context);
$this->propertyDescriber->describe($types, $property, $context);
}

public function supports(array $types): bool
Expand Down
24 changes: 3 additions & 21 deletions src/PropertyDescriber/ObjectPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,8 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist
/**
* @param array<string, mixed> $context Context options for describing the property
*/
public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = [])
public function describe(array $types, OA\Schema $property, array $context = [])
{
if (null === $schema) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.15.0',
'"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated',
__METHOD__
);
}

if (null !== $groups) {
trigger_deprecation(
'nelmio/api-doc-bundle',
'4.17.0',
'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']',
__METHOD__
);
}

$type = new Type(
$types[0]->getBuiltinType(),
false,
Expand All @@ -56,13 +38,13 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul

if ($types[0]->isNullable()) {
$weakContext = Util::createWeakContext($property->_context);
$schemas = [new OA\Schema(['ref' => $this->modelRegistry->register(new Model($type, $groups, [], $context)), '_context' => $weakContext])];
$schemas = [new OA\Schema(['ref' => $this->modelRegistry->register(new Model($type, serializationContext: $context)), '_context' => $weakContext])];
$property->oneOf = $schemas;

return;
}

$property->ref = $this->modelRegistry->register(new Model($type, $groups, [], $context));
$property->ref = $this->modelRegistry->register(new Model($type, serializationContext: $context));
}

public function supports(array $types): bool
Expand Down
Loading

0 comments on commit f4b1cfe

Please sign in to comment.