Skip to content

Commit

Permalink
fix(metadata): name convert parameter property
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 30, 2024
1 parent 736ca04 commit 59adca2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
use ApiPlatform\Serializer\Filter\FilterInterface as SerializerFilterInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Count;
use Symfony\Component\Validator\Constraints\DivisibleBy;
Expand All @@ -47,7 +48,7 @@
*/
final class ParameterResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
{
public function __construct(private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null, private readonly ?ContainerInterface $filterLocator = null)
public function __construct(private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null, private readonly ?ContainerInterface $filterLocator = null, private readonly ?NameConverterInterface $nameConverter = null)
{
}

Expand Down Expand Up @@ -136,6 +137,10 @@ private function setDefaults(string $key, Parameter $parameter, string $resource
$parameter = $this->addSchemaValidation($parameter, $schema, $parameter->getRequired() ?? $description['required'] ?? false, $parameter->getOpenApi() ?: null);
}

if ($this->nameConverter && $property = $parameter->getProperty()) {
$parameter = $parameter->withProperty($this->nameConverter->normalize($property));
}

return $parameter;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/Resources/config/metadata/resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@

<service id="api_platform.metadata.resource.metadata_collection_factory.parameter" class="ApiPlatform\Metadata\Resource\Factory\ParameterResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" public="false" decoration-priority="1000">
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.parameter.inner" />
<argument type="service" id="api_platform.filter_locator" />
<argument type="service" id="api_platform.filter_locator" on-invalid="ignore" />
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
</service>

<service id="api_platform.metadata.resource.metadata_collection_factory.cached" class="ApiPlatform\Metadata\Resource\Factory\CachedResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="-10" public="false">
Expand Down

0 comments on commit 59adca2

Please sign in to comment.