public function testCleanUnmergedProcessor() { $comment = <<<END @SWG\\Info( title="Info only has one contact field.", version="test", ) @SWG\\License( name="MIT", @SWG\\Contact( name="Batman" ) ) END; $analysis = new Analysis($this->parseComment($comment)); $this->assertCount(3, $analysis->annotations); $analysis->process(new MergeIntoSwagger()); $this->assertCount(4, $analysis->annotations); $before = $analysis->split(); $this->assertCount(2, $before->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info'); $this->assertCount(2, $before->unmerged->annotations, '@SWG\\License + @SWG\\Contact'); $this->assertCount(0, $analysis->swagger->_unmerged); $analysis->validate(); // Validation fails to detect the unmerged annotations. // CleanUnmerged should place the unmerged annotions into the swagger->_unmerged array. $analysis->process(new CleanUnmerged()); $between = $analysis->split(); $this->assertCount(2, $between->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info'); $this->assertCount(2, $between->unmerged->annotations, '@SWG\\License + @SWG\\Contact'); $this->assertCount(2, $analysis->swagger->_unmerged); // 1 would also be oke, Could a'Only the @SWG\License' $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\License(), expected to be inside @SWG\\Info in '); $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\Contact(), expected to be inside @SWG\\Info in '); $analysis->validate(); // When a processor places a previously unmerged annotation into the swagger obect. $license = $analysis->getAnnotationsOfType('Swagger\\Annotations\\License')[0]; $contact = $analysis->getAnnotationsOfType('Swagger\\Annotations\\Contact')[0]; $analysis->swagger->info->contact = $contact; $this->assertCount(1, $license->_unmerged); $analysis->process(new CleanUnmerged()); $this->assertCount(0, $license->_unmerged); $after = $analysis->split(); $this->assertCount(3, $after->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info + @SWG\\Contact'); $this->assertCount(1, $after->unmerged->annotations, '@SWG\\License'); $this->assertCount(1, $analysis->swagger->_unmerged); $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\License(), expected to be inside @SWG\\Info in '); $analysis->validate(); }
/** * {@inheritDoc} */ public function getServiceConfig() { return array('aliases' => array('service.swagger' => 'Swagger\\Annotations\\Swagger'), 'factories' => array('SwaggerModule\\Options\\ModuleOptions' => function ($serviceManager) { $config = $serviceManager->get('Config'); $config = isset($config['swagger']) ? $config['swagger'] : null; if ($config === null) { throw new RuntimeException('Configuration for SwaggerModule was not found'); } return new SwaggerModuleOptions($config); }, 'Swagger\\Annotations\\Swagger' => function ($serviceManager) { /** @var $options \SwaggerModule\Options\ModuleOptions */ $options = $serviceManager->get('SwaggerModule\\Options\\ModuleOptions'); $analyser = new SwaggerStaticAnalyser(); $analysis = new SwaggerAnalysis(); $processors = SwaggerAnalysis::processors(); // Crawl directory and parse all files $paths = $options->getPaths(); foreach ($paths as $directory) { $finder = SwaggerUtil::finder($directory); foreach ($finder as $file) { $analysis->addAnalysis($analyser->fromFile($file->getPathname())); } } // Post processing $analysis->process($processors); // Validation (Generate notices & warnings) $analysis->validate(); // Pass options to analyzer $resourceOptions = $options->getResourceOptions(); if (!empty($resourceOptions['defaultBasePath'])) { $analysis->swagger->basePath = $resourceOptions['defaultBasePath']; } if (!empty($resourceOptions['defaultHost'])) { $analysis->swagger->host = $resourceOptions['defaultHost']; } if (!empty($resourceOptions['schemes'])) { $analysis->swagger->schemes = $resourceOptions['schemes']; } return $analysis->swagger; })); }