File tree Expand file tree Collapse file tree 1 file changed +48
-1
lines changed
Expand file tree Collapse file tree 1 file changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -435,14 +435,61 @@ public function getParamExample(array $param): string
435435 $ output .= "\"{$ example }\"" ;
436436 break ;
437437 case self ::TYPE_OBJECT :
438- $ output .= '[:] ' ;
438+ $ decoded = json_decode ($ example , true );
439+ if ($ decoded && is_array ($ decoded )) {
440+ $ output .= $ this ->jsonToSwiftDict ($ decoded );
441+ } else {
442+ $ output .= '[:] ' ;
443+ }
439444 break ;
440445 }
441446 }
442447
443448 return $ output ;
444449 }
445450
451+ /**
452+ * Converts JSON Object To Swift Native Dictionary
453+ *
454+ * @param array $data
455+ * @param int $indent
456+ * @return string
457+ */
458+ protected function jsonToSwiftDict (array $ data , int $ indent = 0 ): string
459+ {
460+ if (empty ($ data )) {
461+ return '[:] ' ;
462+ }
463+
464+ $ baseIndent = str_repeat (' ' , $ indent );
465+ $ itemIndent = str_repeat (' ' , $ indent + 1 );
466+ $ output = "[ \n" ;
467+
468+ $ keys = array_keys ($ data );
469+ foreach ($ keys as $ index => $ key ) {
470+ $ node = $ data [$ key ];
471+
472+ if (is_array ($ node )) {
473+ $ value = $ this ->jsonToSwiftDict ($ node , $ indent + 1 );
474+ } elseif (is_string ($ node )) {
475+ $ value = '" ' . $ node . '" ' ;
476+ } elseif (is_bool ($ node )) {
477+ $ value = $ node ? 'true ' : 'false ' ;
478+ } elseif (is_null ($ node )) {
479+ $ value = 'nil ' ;
480+ } else {
481+ $ value = $ node ;
482+ }
483+
484+ $ comma = ($ index < count ($ keys ) - 1 ) ? ', ' : '' ;
485+ $ output .= ' ' . $ itemIndent . '" ' . $ key . '": ' . $ value . $ comma . "\n" ;
486+ }
487+
488+ $ output .= ' ' . $ baseIndent . '] ' ;
489+
490+ return $ output ;
491+ }
492+
446493 public function getFilters (): array
447494 {
448495 return [
You can’t perform that action at this time.
0 commit comments