@@ -163,14 +163,17 @@ private function generateJson($parameters, $actionId)
163163 }
164164 }
165165
166+ // assign additionalData from docBlock in paramStruct
166167 foreach ($ additionalData as $ name => $ value ) {
167168 // if value looks like json object or array, get struct from json string
168- if ((substr ($ value , 0 , 1 ) === '[ ' && substr ($ value , -1 ) !== '] ' ) || (substr ($ value , 0 , 2 ) === '{" ' && substr ($ value , -1 , 2 ) === '"} ' ) ) {
169+ $ value = trim ($ value );
170+ if ( preg_match ('#^(\{.+\})|(\[.+\])$# ' , $ value )) {
169171 $ value = json_decode ($ value );
170172 }
171173 $ paramStruct ->$ name = $ value ;
172174 }
173175
176+ // set enum options
174177 if (\is_array ($ enumData )) {
175178 // if we want string, cast keys to string, otherwise we would get IDs as int
176179 if ($ paramStruct ->type === 'string ' ) {
@@ -181,15 +184,15 @@ private function generateJson($parameters, $actionId)
181184
182185 // ensure options is set...
183186 if (!isset ($ paramStruct ->options )) {
184- $ paramStruct ->options = [] ;
187+ $ paramStruct ->options = new \ stdClass () ;
185188 }
186189 // ... and add enum_titles, ensure strings
187- $ paramStruct ->options [ ' enum_titles ' ] = array_map ('strval ' , array_values ($ enumData ));
190+ $ paramStruct ->options -> enum_titles = array_map ('strval ' , array_values ($ enumData ));
188191 }
189192
190193 }
191194
192- // add to required if param is not optional
195+ // add to required list if param is not optional
193196 if (!$ parameter ->isOptional ()) {
194197 $ requiredFields [] = $ parameterName ;
195198 // TODO: how to check other types?
0 commit comments