1717use function is_string ;
1818use function str_replace ;
1919
20- final readonly class SchemaFactoryDecorator implements SchemaFactoryInterface
20+ final class SchemaFactoryDecorator implements SchemaFactoryInterface
2121{
2222 use SchemaUriPrefixTrait;
2323
@@ -47,13 +47,13 @@ public function buildSchema(string $className, string $format = 'json', string $
4747 && $ type === Schema::TYPE_INPUT
4848 && in_array ($ operation ::class, [Put::class, Post::class, Patch::class], true )
4949 ) {
50- $ this ->addJsonldUpdatePropertyToObjectSchemaDefinitions ($ currentReference , $ schemaPrefix , $ schema ->getDefinitions ());
50+ $ this ->ensureJsonldInputPropertyForInputSchemas ($ currentReference , $ schemaPrefix , $ schema ->getDefinitions ());
5151 }
5252
5353 return $ schema ;
5454 }
5555
56- private function addJsonldUpdatePropertyToObjectSchemaDefinitions (string $ reference , string $ schemaPrefix , ArrayObject $ definitions ): void
56+ private function ensureJsonldInputPropertyForInputSchemas (string $ reference , string $ schemaPrefix , ArrayObject $ definitions ): void
5757 {
5858 $ definitionName = str_replace ($ schemaPrefix , '' , $ reference );
5959
@@ -62,8 +62,12 @@ private function addJsonldUpdatePropertyToObjectSchemaDefinitions(string $refere
6262 continue ;
6363 }
6464
65- if (isset ($ property ['$ref ' ]) && !isset ($ definitions [str_replace ($ schemaPrefix , '' , $ property ['$ref ' ])]['properties ' ][self ::JSONLD_INPUT_OBJECT_PROPERTY_NAME ])) {
66- $ definitions [str_replace ($ schemaPrefix , '' , $ property ['$ref ' ])]['properties ' ][self ::JSONLD_INPUT_OBJECT_PROPERTY_NAME ] = self ::JSONLD_INPUT_OBJECT_PROPERTY ;
65+ if (isset ($ property ['$ref ' ])) {
66+ $ this ->addJsonldInputProperty (
67+ $ definitions ,
68+ $ schemaPrefix ,
69+ $ property ['$ref ' ],
70+ );
6771
6872 break ;
6973 }
@@ -78,9 +82,24 @@ private function addJsonldUpdatePropertyToObjectSchemaDefinitions(string $refere
7882 continue ;
7983 }
8084
81- $ definitions [str_replace ($ schemaPrefix , '' , $ subschema ['$ref ' ])]['properties ' ][self ::JSONLD_INPUT_OBJECT_PROPERTY_NAME ] = self ::JSONLD_INPUT_OBJECT_PROPERTY ;
85+ $ this ->addJsonldInputProperty (
86+ $ definitions ,
87+ $ schemaPrefix ,
88+ $ subschema ['$ref ' ],
89+ );
8290 }
8391 }
8492 }
8593 }
94+
95+ private function addJsonldInputProperty (
96+ ArrayObject $ definitions ,
97+ string $ schemaPrefix ,
98+ string $ ref ,
99+ ): void {
100+ $ definitionKey = str_replace ($ schemaPrefix , '' , $ ref );
101+
102+ $ definitions [$ definitionKey ]['properties ' ][self ::JSONLD_INPUT_OBJECT_PROPERTY_NAME ]
103+ ??= self ::JSONLD_INPUT_OBJECT_PROPERTY ;
104+ }
86105}
0 commit comments