Skip to content

Commit

Permalink
WIP: Very first draft for ignoring properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicLuidold committed Jan 7, 2025
1 parent 8e56941 commit aa8b81e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Annotation/Ignore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nelmio\ApiDocBundle\Annotation;

trigger_deprecation('nelmio/api-doc-bundle', 'todo', 'The "%s" class is deprecated and will be removed in 5.0. Use the "\Nelmio\ApiDocBundle\Attribute\Ignore" attribute instead.', Ignore::class);

/**
* @Annotation
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY)]

Check failure on line 21 in src/Annotation/Ignore.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class Nelmio\ApiDocBundle\Annotation\Ignore extends @Final class Nelmio\ApiDocBundle\Attribute\Ignore.
final class Ignore extends \Nelmio\ApiDocBundle\Attribute\Ignore
{
}
22 changes: 22 additions & 0 deletions src/Attribute/Ignore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nelmio\ApiDocBundle\Attribute;

/**
* @final
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY)]
class Ignore
{
}
16 changes: 15 additions & 1 deletion src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Nelmio\ApiDocBundle\ModelDescriber;

use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\Attribute\Ignore;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Nelmio\ApiDocBundle\Model\Model;
Expand Down Expand Up @@ -130,11 +131,24 @@ public function describe(Model $model, OA\Schema $schema)

$reflections = $this->getReflections($reflClass, $propertyName);

// Check if a custom name is set
$ignoredProperty = false;
foreach ($reflections as $reflection) {
if (\PHP_VERSION_ID >= 80000) {
if (0 !== \count($reflection->getAttributes(Ignore::class))) {
$ignoredProperty = true;

continue;
}
}

// Check if a custom name is set
$serializedName = $annotationsReader->getPropertyName($reflection, $serializedName);
}

if ($ignoredProperty) {
continue;
}

$property = Util::getProperty($schema, $serializedName);

// Interpret additional options
Expand Down

0 comments on commit aa8b81e

Please sign in to comment.