public function testThirdPartyAnnotations() { $backup = Analyser::$whitelist; Analyser::$whitelist = ['Swagger\\Annotations\\']; $analyser = new StaticAnalyser(); $analysis = $analyser->fromFile(__DIR__ . '/Fixtures/ThirdPartyAnnotations.php'); $this->assertCount(3, $analysis->annotations, 'Only read the @SWG annotations, skip the others.'); // Allow Swagger to parse 3rd party annotations // might contain useful info that could be extracted with a custom processor Analyser::$whitelist[] = 'Zend\\Form\\Annotation'; $swagger = \Swagger\scan(__DIR__ . '/Fixtures/ThirdPartyAnnotations.php'); $this->assertSame('api/3rd-party', $swagger->paths[0]->path); $this->assertCount(10, $swagger->_unmerged); Analyser::$whitelist = $backup; }
public function testThirdPartyAnnotations() { $backup = Analyser::$whitelist; Analyser::$whitelist = ['Swagger\\Annotations\\']; $analyser = new StaticAnalyser(); $defaultAnalysis = $analyser->fromFile(__DIR__ . '/Fixtures/ThirdPartyAnnotations.php'); $this->assertCount(3, $defaultAnalysis->annotations, 'Only read the @SWG annotations, skip the others.'); // Allow Swagger to parse 3rd party annotations // might contain useful info that could be extracted with a custom processor Analyser::$whitelist[] = 'Zend\\Form\\Annotation'; $swagger = \Swagger\scan(__DIR__ . '/Fixtures/ThirdPartyAnnotations.php'); $this->assertSame('api/3rd-party', $swagger->paths[0]->path); $this->assertCount(10, $swagger->_unmerged); Analyser::$whitelist = $backup; $analysis = $swagger->_analysis; $annotations = $analysis->getAnnotationsOfType('Zend\\Form\\Annotation\\Name'); $this->assertCount(1, $annotations); $context = $analysis->getContext($annotations[0]); $this->assertInstanceOf('Swagger\\Context', $context); $this->assertSame('ThirdPartyAnnotations', $context->class); $this->assertSame('\\SwaggerFixtures\\ThirdPartyAnnotations', $context->fullyQualifiedName($context->class)); $this->assertCount(2, $context->annotations); }
/** * * @param string $comment Contents of a comment block * @return AbstractAnnotation[] */ protected function parseComment($comment) { $analyser = new Analyser(); $context = Context::detect(1); $context->line -= 1; // correct generated lines: "<?php\n" and "/**\n" return $analyser->fromComment("<?php\n/**\n * " . implode("\n * ", explode("\n", $comment)) . "\n*/", $context); }