@@ -184,17 +184,21 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
184
184
$ relatedDefinitions = [];
185
185
foreach ($ properties as $ propertyName => $ property ) {
186
186
if ($ relation = $ this ->getRelationship ($ className , $ propertyName , $ serializerContext )) {
187
- [$ isOne , $ hasOperations , $ relatedClassName ] = $ relation ;
188
- if (false === $ hasOperations ) {
189
- continue ;
190
- }
187
+ [$ isOne , $ relatedClasses ] = $ relation ;
188
+ $ refs = [];
189
+ foreach ($ relatedClasses as $ relatedClassName => $ hasOperations ) {
190
+ if (false === $ hasOperations ) {
191
+ continue ;
192
+ }
191
193
192
- $ operation = $ this ->findOperation ($ relatedClassName , $ type , $ operation , $ serializerContext );
193
- $ inputOrOutputClass = $ this ->findOutputClass ($ relatedClassName , $ type , $ operation , $ serializerContext );
194
- $ serializerContext ??= $ this ->getSerializerContext ($ operation , $ type );
195
- $ definitionName = $ this ->definitionNameFactory ->create ($ relatedClassName , $ format , $ inputOrOutputClass , $ operation , $ serializerContext );
196
- $ ref = Schema::VERSION_OPENAPI === $ schema ->getVersion () ? '#/components/schemas/ ' .$ definitionName : '#/definitions/ ' .$ definitionName ;
197
- $ relatedDefinitions [$ propertyName ] = ['$ref ' => $ ref ];
194
+ $ operation = $ this ->findOperation ($ relatedClassName , $ type , $ operation , $ serializerContext );
195
+ $ inputOrOutputClass = $ this ->findOutputClass ($ relatedClassName , $ type , $ operation , $ serializerContext );
196
+ $ serializerContext ??= $ this ->getSerializerContext ($ operation , $ type );
197
+ $ definitionName = $ this ->definitionNameFactory ->create ($ relatedClassName , $ format , $ inputOrOutputClass , $ operation , $ serializerContext );
198
+ $ ref = Schema::VERSION_OPENAPI === $ schema ->getVersion () ? '#/components/schemas/ ' .$ definitionName : '#/definitions/ ' .$ definitionName ;
199
+ $ refs [$ ref ] = '$ref ' ;
200
+ }
201
+ $ relatedDefinitions [$ propertyName ] = array_flip ($ refs );
198
202
if ($ isOne ) {
199
203
$ relationships [$ propertyName ]['properties ' ]['data ' ] = self ::RELATION_PROPS ;
200
204
continue ;
@@ -203,7 +207,6 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
203
207
'type ' => 'array ' ,
204
208
'items ' => self ::RELATION_PROPS ,
205
209
];
206
- continue ;
207
210
}
208
211
if ('id ' === $ propertyName ) {
209
212
$ attributes ['_id ' ] = $ property ;
@@ -264,7 +267,7 @@ private function getRelationship(string $resourceClass, string $property, ?array
264
267
$ types = $ propertyMetadata ->getBuiltinTypes () ?? [];
265
268
$ isRelationship = false ;
266
269
$ isOne = $ isMany = false ;
267
- $ className = $ hasOperations = null ;
270
+ $ relatedClasses = [] ;
268
271
269
272
foreach ($ types as $ type ) {
270
273
if ($ type ->isCollection ()) {
@@ -281,9 +284,9 @@ private function getRelationship(string $resourceClass, string $property, ?array
281
284
$ operation = $ resourceMetadata ->getOperation ();
282
285
// @see https://github.com/api-platform/core/issues/5501
283
286
// @see https://github.com/api-platform/core/pull/5722
284
- $ hasOperations ?? = $ operation ->canRead ();
287
+ $ relatedClasses [ $ className ] = $ operation ->canRead ();
285
288
}
286
289
287
- return $ isRelationship ? [$ isOne , $ hasOperations , $ className ] : null ;
290
+ return $ isRelationship ? [$ isOne , $ relatedClasses ] : null ;
288
291
}
289
292
}
0 commit comments