@@ -35,6 +35,10 @@ public function __construct(private readonly PropertyMetadataFactoryInterface $p
35
35
36
36
/**
37
37
* {@inheritdoc}
38
+ *
39
+ * To handle the composite identifiers type correctly, use an `uri_variables_map` that maps uriVariables to their uriVariablesDefinition.
40
+ * Indeed, a composite identifier will already be parsed, and their corresponding properties will be the parameterName and not the defined
41
+ * identifiers.
38
42
*/
39
43
public function convert (array $ uriVariables , string $ class , array $ context = []): array
40
44
{
@@ -43,10 +47,15 @@ public function convert(array $uriVariables, string $class, array $context = [])
43
47
$ uriVariablesDefinitions = $ operation ->getUriVariables () ?? [];
44
48
45
49
foreach ($ uriVariables as $ parameterName => $ value ) {
46
- $ uriVariableDefinition = $ uriVariablesDefinitions [$ parameterName ] ?? $ uriVariablesDefinitions ['id ' ] ?? new Link ();
50
+ $ uriVariableDefinition = $ context [ ' uri_variables_map ' ][ $ parameterName ] ?? $ uriVariablesDefinitions [$ parameterName ] ?? $ uriVariablesDefinitions ['id ' ] ?? new Link ();
47
51
48
- $ identifierTypes = $ this ->getIdentifierTypes ($ uriVariableDefinition ->getFromClass () ?? $ class , $ uriVariableDefinition ->getIdentifiers () ?? [$ parameterName ]);
49
- if (!($ types = $ identifierTypes [$ parameterName ] ?? false )) {
52
+ // When a composite identifier is used, we assume that the parameterName is the property to find our type
53
+ $ properties = $ uriVariableDefinition ->getIdentifiers () ?? [$ parameterName ];
54
+ if ($ uriVariableDefinition ->getCompositeIdentifier ()) {
55
+ $ properties = [$ parameterName ];
56
+ }
57
+
58
+ if (!$ types = $ this ->getIdentifierTypes ($ uriVariableDefinition ->getFromClass () ?? $ class , $ properties )) {
50
59
continue ;
51
60
}
52
61
@@ -73,7 +82,7 @@ private function getIdentifierTypes(string $resourceClass, array $properties): a
73
82
foreach ($ properties as $ property ) {
74
83
$ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ resourceClass , $ property );
75
84
foreach ($ propertyMetadata ->getBuiltinTypes () as $ type ) {
76
- $ types [$ property ][ ] = Type::BUILTIN_TYPE_OBJECT === ($ builtinType = $ type ->getBuiltinType ()) ? $ type ->getClassName () : $ builtinType ;
85
+ $ types [] = Type::BUILTIN_TYPE_OBJECT === ($ builtinType = $ type ->getBuiltinType ()) ? $ type ->getClassName () : $ builtinType ;
77
86
}
78
87
}
79
88
0 commit comments