@@ -58,52 +58,79 @@ public function buildSchema(string $className, string $format = 'json', string $
5858 /** @param ArrayObject<string, mixed> $definitions */
5959 private function ensureJsonldInputPropertyForInputSchemas (string $ reference , string $ schemaPrefix , ArrayObject $ definitions ): void
6060 {
61- $ definitionName = str_replace ($ schemaPrefix , '' , $ reference );
61+ foreach (
62+ $ this ->collectReferences (
63+ $ definitions [
64+ $ this ->stripSchemaPrefix ($ schemaPrefix , $ reference )
65+ ]['properties ' ] ?? [],
66+ $ schemaPrefix ,
67+ ) as $ definitionKey ) {
68+ $ this ->addJsonldInputProperty ($ definitionKey , $ definitions );
69+ }
70+ }
6271
63- foreach ($ definitions [$ definitionName ]['properties ' ] ?? [] as $ property ) {
64- if (isset ($ property ['type ' ])) {
72+ /**
73+ * @param array<string, ArrayObject<string, mixed>> $properties
74+ *
75+ * @return iterable<int, string>
76+ */
77+ private function collectReferences (array $ properties , string $ schemaPrefix ): iterable
78+ {
79+ foreach ($ properties as $ property ) {
80+ if (
81+ isset ($ property ['type ' ])
82+ && !isset ($ property ['items ' ])
83+ ) {
6584 continue ;
6685 }
6786
6887 if (isset ($ property ['$ref ' ])) {
69- $ this ->addJsonldInputProperty (
70- $ definitions ,
71- $ schemaPrefix ,
72- $ property ['$ref ' ],
73- );
88+ yield $ this ->stripSchemaPrefix ($ schemaPrefix , $ property ['$ref ' ]);
89+
90+ continue ;
91+ }
7492
75- break ;
93+ if (isset ($ property ['items ' ]['$ref ' ])) {
94+ yield $ this ->stripSchemaPrefix ($ schemaPrefix , $ property ['items ' ]['$ref ' ]);
95+
96+ continue ;
7697 }
7798
7899 foreach (self ::SCHEMA_LOGICAL_OPERATORS as $ operator ) {
79- if (!isset ($ property [$ operator ])) {
80- continue ;
81- }
100+ if (isset ($ property [$ operator ])) {
101+ foreach ($ property [$ operator ] as $ subschema ) {
102+ if (!isset ($ subschema ['$ref ' ])) {
103+ continue ;
104+ }
82105
83- foreach ($ property [$ operator ] as $ subschema ) {
84- if (!isset ($ subschema ['$ref ' ])) {
85- continue ;
106+ yield $ this ->stripSchemaPrefix ($ schemaPrefix , $ subschema ['$ref ' ]);
86107 }
108+ }
87109
88- $ this ->addJsonldInputProperty (
89- $ definitions ,
90- $ schemaPrefix ,
91- $ subschema ['$ref ' ],
92- );
110+ if (isset ($ property ['items ' ][$ operator ])) {
111+ foreach ($ property ['items ' ][$ operator ] as $ subschema ) {
112+ if (!isset ($ subschema ['$ref ' ])) {
113+ continue ;
114+ }
115+
116+ yield $ this ->stripSchemaPrefix ($ schemaPrefix , $ subschema ['$ref ' ]);
117+ }
93118 }
94119 }
95120 }
96121 }
97122
98123 /** @param ArrayObject<string, mixed> $definitions */
99124 private function addJsonldInputProperty (
125+ string $ definitionKey ,
100126 ArrayObject $ definitions ,
101- string $ schemaPrefix ,
102- string $ ref ,
103127 ): void {
104- $ definitionKey = str_replace ($ schemaPrefix , '' , $ ref );
105-
106128 $ definitions [$ definitionKey ]['properties ' ][self ::JSONLD_INPUT_OBJECT_PROPERTY_NAME ]
107129 ??= self ::JSONLD_INPUT_OBJECT_PROPERTY ;
108130 }
131+
132+ private function stripSchemaPrefix (string $ schemaPrefix , string $ reference ): string
133+ {
134+ return str_replace ($ schemaPrefix , '' , $ reference );
135+ }
109136}
0 commit comments