code: private function formatTreeData(array $treeData)
      {
          return array_map(function($data){
              $formatted = [
                  'categories' => $this->getCategoryService()->getItemCategories(new \core_kernel_classes_Resource($data['uri']))
              ];
              if(isset($data['children'])){
                  $formatted['children'] = $this->formatTreeData($data['children']);
              }
              return array_merge($data, $formatted);
          }, $treeData);
      }
docs: Reformat the the tree : state and count
  Add the item's categories
  @param array $treeData
  @return array the formated data