Skip to content

Commit

Permalink
Merge pull request #9 from xl32/swagger-php-2.0
Browse files Browse the repository at this point in the history
Support for Swagger 2.0
  • Loading branch information
davidwindell committed Feb 12, 2016
2 parents 23c63cd + 11238bf commit c785686
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.3.3",
"zircote/swagger-php": "~0.9.0"
"zircote/swagger-php": "~2.0"
},
"autoload": {
"psr-0": {
Expand Down
10 changes: 5 additions & 5 deletions src/SwaggerModule/Controller/DocumentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class DocumentationController extends AbstractActionController
*/
public function displayAction()
{
/** @var $swagger \Swagger\Swagger */
$swagger = $this->serviceLocator->get('Swagger\Swagger');
$jsonModel = new JsonModel();
return $jsonModel->setVariables($swagger->getResourceList());
/** @var $swagger \Swagger\Annotations\Swagger */
$swagger = $this->serviceLocator->get('Swagger\Annotations\Swagger');
$jsonModel = new JsonModel((array)$swagger->jsonSerialize());
return $jsonModel;
}

/**
Expand All @@ -49,7 +49,7 @@ public function displayAction()
public function detailsAction()
{
/** @var $swagger \Swagger\Swagger */
$swagger = $this->serviceLocator->get('Swagger\Swagger');
$swagger = $this->serviceLocator->get('Swagger\Annotations\Swagger');

/** @var $options \SwaggerModule\Options\ModuleOptions */
$options = $this->serviceLocator->get('SwaggerModule\Options\ModuleOptions');
Expand Down
26 changes: 22 additions & 4 deletions src/SwaggerModule/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
namespace SwaggerModule;

use RuntimeException;
use Swagger\Swagger as SwaggerLibrary;
use SwaggerModule\Options\ModuleOptions as SwaggerModuleOptions;
use Swagger\StaticAnalyser as SwaggerStaticAnalyser;
use Swagger\Analysis as SwaggerAnalysis;
use Swagger\Util as SwaggerUtil;
use Zend\Console\Adapter\AdapterInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
Expand All @@ -47,7 +49,7 @@ public function getServiceConfig()
{
return array(
'aliases' => array(
'service.swagger' => 'Swagger\Swagger',
'service.swagger' => 'Swagger\Annotations\Swagger',
),

'factories' => array(
Expand All @@ -62,10 +64,26 @@ public function getServiceConfig()
return new SwaggerModuleOptions($config);
},

'Swagger\Swagger' => function($serviceManager) {
'Swagger\Annotations\Swagger' => function($serviceManager) {
/** @var $options \SwaggerModule\Options\ModuleOptions */
$options = $serviceManager->get('SwaggerModule\Options\ModuleOptions');
return new SwaggerLibrary($options->getPaths());
$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();
return $analysis->swagger;
},
)
);
Expand Down

0 comments on commit c785686

Please sign in to comment.