unmerged() public method

Analysis with only the annotations that not merged.
public unmerged ( ) : Analysis
return Analysis
 public function __invoke(Analysis $analysis)
 {
     $definitions = $analysis->getAnnotationsOfType('\\Swagger\\Annotations\\Definition');
     // Use the class names for @SWG\Definition()
     foreach ($definitions as $definition) {
         if ($definition->definition === null) {
             if ($definition->_context->is('class')) {
                 $definition->definition = $definition->_context->class;
             } elseif ($definition->_context->is('trait')) {
                 $definition->definition = $definition->_context->trait;
             }
             // if ($definition->type === null) {
             //     $definition->type = 'object';
             // }
         }
     }
     // Merge unmerged @SWG\Property annotations into the @SWG\Definition of the class
     $unmergedProperties = $analysis->unmerged()->getAnnotationsOfType('\\Swagger\\Annotations\\Property');
     foreach ($unmergedProperties as $property) {
         $definitonContext = $property->_context->with('class') ?: $property->_context->with('trait');
         if ($definitonContext->annotations) {
             $definition = false;
             foreach ($definitonContext->annotations as $annotation) {
                 if ($annotation instanceof Definition) {
                     $definition = $annotation;
                 }
             }
             if ($definition) {
                 $definition->merge([$property], true);
             }
         }
     }
 }
Esempio n. 2
0
 public function __invoke(Analysis $analysis)
 {
     $paths = [];
     // Merge @SWG\Paths with the same path.
     foreach ($analysis->swagger->paths as $annotation) {
         if (empty($annotation->path)) {
             Logger::notice($annotation->identity() . ' is missing required property "path" in ' . $annotation->_context);
         } elseif (isset($paths[$annotation->path])) {
             $paths[$annotation->path]->mergeProperties($annotation);
             $analysis->annotations->detach($annotation);
         } else {
             $paths[$annotation->path] = $annotation;
         }
     }
     // Merge @SWG\Operations into existing @SWG\Paths or create a new one.
     $operations = $analysis->unmerged()->getAnnotationsOfType('\\Swagger\\Annotations\\Operation');
     foreach ($operations as $operation) {
         if ($operation->path) {
             if (empty($paths[$operation->path])) {
                 $paths[$operation->path] = new Path(['path' => $operation->path, '_context' => new Context(['generated' => true], $operation->_context)]);
                 $analysis->annotations->attach($paths[$operation->path]);
             }
             if ($paths[$operation->path]->merge([$operation])) {
                 Logger::notice('Unable to merge ' . $operation->identity() . ' in ' . $operation->_context);
             }
         }
     }
     $analysis->swagger->paths = array_values($paths);
 }
 public function testProcessor()
 {
     $swagger = new Swagger([]);
     $info = new Info([]);
     $analysis = new Analysis([$swagger, $info]);
     $this->assertNull($analysis->swagger);
     $this->assertNull($swagger->info);
     $analysis->process(new MergeIntoSwagger());
     $this->assertInstanceOf('Swagger\\Annotations\\Swagger', $analysis->swagger);
     $this->assertSame($info, $swagger->info);
     $this->assertCount(0, $analysis->unmerged()->annotations);
 }