Skip to content

Commit 39efdff

Browse files
committed
fix: allowed composite identifiers with differents types
1 parent bf4b0e4 commit 39efdff

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

features/main/composite.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ Feature: Retrieve data with Composite identifiers
132132
Then the response status code should be 200
133133
And the response should be in JSON
134134
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
135+
136+
Scenario: Get identifiers with different type
137+
Given there are Composite identifier objects
138+
When I send a "GET" request to "/composite_key_with_different_types/id=82133;verificationKey=7d75af772e637e45c36d041696e1128d"
139+
Then the response status code should be 200

src/Api/UriVariablesConverter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function convert(array $uriVariables, string $class, array $context = [])
4444

4545
foreach ($uriVariables as $parameterName => $value) {
4646
$uriVariableDefinition = $uriVariablesDefinitions[$parameterName] ?? $uriVariablesDefinitions['id'] ?? new Link();
47-
if ([] === $types = $this->getIdentifierTypes($uriVariableDefinition->getFromClass() ?? $class, $uriVariableDefinition->getIdentifiers() ?? [$parameterName])) {
47+
48+
$identifierTypes = $this->getIdentifierTypes($uriVariableDefinition->getFromClass() ?? $class, $uriVariableDefinition->getIdentifiers() ?? [$parameterName]);
49+
if (!($types = $identifierTypes[$parameterName] ?? false)) {
4850
continue;
4951
}
5052

@@ -61,7 +63,6 @@ public function convert(array $uriVariables, string $class, array $context = [])
6163
}
6264
}
6365
}
64-
6566
return $uriVariables;
6667
}
6768

@@ -71,7 +72,7 @@ private function getIdentifierTypes(string $resourceClass, array $properties): a
7172
foreach ($properties as $property) {
7273
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $property);
7374
foreach ($propertyMetadata->getBuiltinTypes() as $type) {
74-
$types[] = Type::BUILTIN_TYPE_OBJECT === ($builtinType = $type->getBuiltinType()) ? $type->getClassName() : $builtinType;
75+
$types[$property][] = Type::BUILTIN_TYPE_OBJECT === ($builtinType = $type->getBuiltinType()) ? $type->getClassName() : $builtinType;
7576
}
7677
}
7778

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5396;
6+
7+
use ApiPlatform\Metadata\ApiProperty;
8+
use ApiPlatform\Metadata\ApiResource;
9+
use ApiPlatform\Metadata\Operation;
10+
11+
#[ApiResource(provider: [self::class, 'provide'])]
12+
class CompositeKeyWithDifferentType {
13+
14+
#[ApiProperty(identifier: true)]
15+
private ?int $id;
16+
17+
#[ApiProperty(identifier: true)]
18+
private ?string $verificationKey;
19+
20+
public static function provide(Operation $operation, array $uriVariables = [], array $context = []) {
21+
return $context;
22+
}
23+
}

0 commit comments

Comments
 (0)