public function buildOutput(ApiDoc $annotation, $data = null)
    {
        $annotationReflection = new \ReflectionClass('Nelmio\ApiDocBundle\Annotation\ApiDoc');
        $outputReflection = $annotationReflection->getProperty('output');
        $outputReflection->setAccessible(true);
        if (!(isset($data['output']) || $data['output'] === null) || empty($data['output'])) {
            if ($annotation->toArray()['method'] === 'POST' || $annotation->toArray()['method'] === 'PUT') {
                $actionName = $annotation->getRoute()->getDefault('_controller');
                $reflectionMethod = new \ReflectionMethod($actionName);
                $phpdoc = $reflectionMethod->getDocComment();
                $return = substr($phpdoc, strpos($phpdoc, '@return'));
                $returnType = str_replace(['@return \\', '*', '[]', 'array<\\', '>'], '', $return);
                $returnType = substr($returnType, 0, strpos($returnType, strstr($returnType, "\n")));
                $returnType = preg_replace("/\r\n|\r|\n|\\/\\s+/", '', $returnType);

                if (class_exists($returnType) || interface_exists($returnType)) {
                    $outputReflection->setValue($annotation, $returnType);
                }
            }
        } else {
            $outputReflection->setValue($annotation, $data['output']);
        }

        return $annotation;
    }