Skip to content

Commit 56d8eae

Browse files
authored
Merge pull request #17 from xl32/master
Swagger / OpenAPI 3.0 support, migration to Laminas
2 parents 5d27e32 + cfbbf86 commit 56d8eae

File tree

6 files changed

+48
-42
lines changed

6 files changed

+48
-42
lines changed

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"name": "outeredge/swagger-module",
3-
"description": "Zend Framework Module for Swagger resource file generation",
3+
"description": "Laminas Framework Module for Swagger resource file generation",
44
"type": "library",
55
"license": "Apache-2.0",
66
"homepage": "https://github.com/outeredge/SwaggerModule",
77
"keywords": [
88
"api",
99
"rest",
10-
"zf2",
11-
"zf3",
12-
"swagger"
10+
"laminas",
11+
"swagger",
12+
"openapi"
1313
],
1414
"require": {
15-
"php": "^5.6 || ^7.0",
16-
"zendframework/zend-servicemanager": "^2.7.6 || ^3.1",
17-
"zircote/swagger-php": "~2.0"
15+
"php": "^7.0",
16+
"laminas/laminas-servicemanager": "^3.1",
17+
"zircote/swagger-php": "~3.0"
1818
},
1919
"autoload": {
2020
"psr-0": {

config/swagger.global.php.dist

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ return array(
1313
'output' => 'array',
1414
'json_pretty_print' => true, // for outputtype 'json'
1515
'defaultApiVersion' => null,
16-
'defaultBasePath' => null, // e.g. /api
17-
'defaultHost' => null, // example.com
18-
'schemes' => null, // e.g. ['http', 'https'],
16+
'servers' => [
17+
[
18+
'url' => 'https://example.com/api/v1', // servers replaces the host, basePath and schemes keywords used in OpenAPI 2.0.
19+
'description' => null, // e.g. "Production server (uses live data)"
20+
],
21+
],
1922
),
2023
)
2124
);

src/SwaggerModule/Controller/DocumentationController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020

2121
namespace SwaggerModule\Controller;
2222

23-
use Swagger\Annotations\Swagger;
24-
use Zend\Mvc\Controller\AbstractActionController;
25-
use Zend\View\Model\JsonModel;
23+
use OpenApi\Annotations\OpenApi;
24+
use Laminas\Mvc\Controller\AbstractActionController;
25+
use Laminas\View\Model\JsonModel;
2626

2727
/**
2828
* DocumentationController. It is used to display a documentation in HTML
2929
*/
3030
class DocumentationController extends AbstractActionController
3131
{
32-
protected $swagger;
32+
protected $openApi;
3333

34-
public function setSwagger(Swagger $swagger) {
35-
$this->swagger = $swagger;
34+
public function setOpenApi(OpenApi $openApi) {
35+
$this->swagger = $openApi;
3636
}
3737

3838
/**

src/SwaggerModule/Controller/DocumentationControllerFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
namespace SwaggerModule\Controller;
2222

2323
use Interop\Container\ContainerInterface;
24-
use Swagger\Annotations\Swagger;
25-
use Zend\ServiceManager\AbstractFactoryInterface;
26-
use Zend\ServiceManager\AbstractPluginManager;
27-
use Zend\ServiceManager\ServiceLocatorInterface;
24+
use OpenApi\Annotations\OpenApi;
25+
use Laminas\ServiceManager\AbstractFactoryInterface;
26+
use Laminas\ServiceManager\AbstractPluginManager;
27+
use Laminas\ServiceManager\ServiceLocatorInterface;
2828

2929
class DocumentationControllerFactory implements AbstractFactoryInterface
3030
{
@@ -41,9 +41,9 @@ public function canCreateServiceWithName(ServiceLocatorInterface $services, $nam
4141
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
4242
{
4343
$controller = new DocumentationController();
44-
/** @var Swagger $swagger */
45-
$swagger = $container->get('Swagger\Annotations\Swagger');
46-
$controller->setSwagger($swagger);
44+
/** @var OpenApi $openApi */
45+
$openApi = $container->get('OpenApi\Annotations\OpenApi');
46+
$controller->setOpenApi($openApi);
4747
return $controller;
4848
}
4949

src/SwaggerModule/Module.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
use RuntimeException;
2424
use SwaggerModule\Options\ModuleOptions as SwaggerModuleOptions;
25-
use Swagger\StaticAnalyser as SwaggerStaticAnalyser;
26-
use Swagger\Analysis as SwaggerAnalysis;
27-
use Swagger\Util as SwaggerUtil;
28-
use Zend\Console\Adapter\AdapterInterface;
29-
use Zend\ModuleManager\Feature\ConfigProviderInterface;
30-
use Zend\ModuleManager\Feature\ServiceProviderInterface;
25+
use OpenApi\StaticAnalyser as OpenApiStaticAnalyser;
26+
use OpenApi\Analysis as OpenApiAnalysis;
27+
use OpenApi\Util as OpenApiUtil;
28+
use Laminas\Console\Adapter\AdapterInterface;
29+
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
30+
use Laminas\ModuleManager\Feature\ServiceProviderInterface;
3131

3232
/**
3333
* SwaggerModule
@@ -64,17 +64,17 @@ public function getServiceConfig()
6464
return new SwaggerModuleOptions($config);
6565
},
6666

67-
'Swagger\Annotations\Swagger' => function($serviceManager) {
67+
'OpenApi\Annotations\OpenApi' => function($serviceManager) {
6868
/** @var $options \SwaggerModule\Options\ModuleOptions */
6969
$options = $serviceManager->get('SwaggerModule\Options\ModuleOptions');
70-
$analyser = new SwaggerStaticAnalyser();
71-
$analysis = new SwaggerAnalysis();
72-
$processors = SwaggerAnalysis::processors();
70+
$analyser = new OpenApiStaticAnalyser();
71+
$analysis = new OpenApiAnalysis();
72+
$processors = OpenApiAnalysis::processors();
7373

7474
// Crawl directory and parse all files
7575
$paths = $options->getPaths();
7676
foreach($paths as $directory) {
77-
$finder = SwaggerUtil::finder($directory);
77+
$finder = OpenApiUtil::finder($directory);
7878
foreach ($finder as $file) {
7979
$analysis->addAnalysis($analyser->fromFile($file->getPathname()));
8080
}
@@ -86,17 +86,20 @@ public function getServiceConfig()
8686

8787
// Pass options to analyzer
8888
$resourceOptions = $options->getResourceOptions();
89-
if(!empty($resourceOptions['defaultBasePath'])) {
90-
$analysis->swagger->basePath = $resourceOptions['defaultBasePath'];
89+
if(! empty($resourceOptions['servers'])) {
90+
$analysis->openapi->servers = $resourceOptions['servers'];
9191
}
92-
if(!empty($resourceOptions['defaultHost'])) {
93-
$analysis->swagger->host = $resourceOptions['defaultHost'];
92+
if(! empty($resourceOptions['defaultBasePath'])) {
93+
$analysis->openapi->servers['basePath'] = $resourceOptions['defaultBasePath'];
9494
}
95-
if(!empty($resourceOptions['schemes'])) {
96-
$analysis->swagger->schemes = $resourceOptions['schemes'];
95+
if(! empty($resourceOptions['defaultHost'])) {
96+
$analysis->openapi->servers['host'] = $resourceOptions['defaultHost'];
97+
}
98+
if(! empty($resourceOptions['schemes'])) {
99+
$analysis->openapi->servers['schemes'] = $resourceOptions['schemes'];
97100
}
98101

99-
return $analysis->swagger;
102+
return $analysis->openapi;
100103
},
101104
)
102105
);

src/SwaggerModule/Options/ModuleOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace SwaggerModule\Options;
2222

2323
use DirectoryIterator;
24-
use Zend\Stdlib\AbstractOptions;
24+
use Laminas\Stdlib\AbstractOptions;
2525

2626
/**
2727
* ModuleOptions

0 commit comments

Comments
 (0)