@@ -81,11 +81,6 @@ final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareI
8181 'required ' => ['@type ' ],
8282 ];
8383
84- /**
85- * @var array<string, true>
86- */
87- private array $ transformed = [];
88-
8984 /**
9085 * @param array<string, mixed> $defaultContext
9186 */
@@ -284,7 +279,7 @@ public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void
284279
285280 private function decorateItemDefinition (string $ definitionName , \ArrayObject $ definitions , string $ prefix , string $ type , ?array $ serializerContext ): void
286281 {
287- if (!isset ($ definitions [$ definitionName ]) || ( $ this -> transformed [ $ definitionName ] ?? false ) ) {
282+ if (!isset ($ definitions [$ definitionName ])) {
288283 return ;
289284 }
290285
@@ -294,6 +289,12 @@ private function decorateItemDefinition(string $definitionName, \ArrayObject $de
294289 $ baseName = self ::ITEM_WITHOUT_ID_BASE_SCHEMA_NAME ;
295290 }
296291
292+ // Check if the definition is already decorated to prevent double wrapping (recursion or cache)
293+ $ currentDef = $ definitions [$ definitionName ];
294+ if (($ currentDef ['allOf ' ][0 ]['$ref ' ] ?? null ) === $ prefix .$ baseName ) {
295+ return ;
296+ }
297+
297298 if (!isset ($ definitions [$ baseName ])) {
298299 $ definitions [$ baseName ] = $ hasNoId ? self ::ITEM_BASE_SCHEMA_WITHOUT_ID : self ::ITEM_BASE_SCHEMA_WITH_ID ;
299300 }
@@ -309,7 +310,5 @@ private function decorateItemDefinition(string $definitionName, \ArrayObject $de
309310
310311 $ definitions [$ definitionName ] = $ allOf ;
311312 unset($ definitions [$ definitionName ]['allOf ' ][1 ]['description ' ]);
312-
313- $ this ->transformed [$ definitionName ] = true ;
314313 }
315314}
0 commit comments