你能否解释为什么Swagger在与ZendFramework2集成时不适合我。我按照here给出的说明进行了操作。
composer.json :
{
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.3.5",
"outeredge/swagger-module": "dev-master"
},
}
配置/ application.config.php :
<?php
return array(
'modules' => array(
'MyApp',
'SwaggerModule',
),
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
),
);
?>
/config/autoload/swagger.global.php :
return array(
'swagger' => array(
'paths' => array(
__DIR__ . '/../../module/Morpho/src/Morpho/Controller',
),
'resource_options' => array(
'output' => 'array',
'json_pretty_print' => true, // for outputtype 'json'
'defaultBasePath' => null,
'defaultApiVersion' => null,
'defaultSwaggerVersion' => '1.2',
),
)
);
在Apache下部署应用程序后,当调用http://myapp/public/api/docs时,我得到:
{"errors":[{"message":"An error occurred during execution;
please try again later.","error":"error-exception","exception":
"class":"Zend\ServiceManager\Exception\ServiceNotCreatedException",
"file":"\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php",
"line":930,
"message":"An exception was raised while creating "Swagger\Swagger";
no instance returned"
堆栈跟踪:
0 \vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(1057): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Object(Closure), 'swaggerswagger', 'Swagger\Swagger')
1 \vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(633): Zend\ServiceManager\ServiceManager->createFromFactory('swaggerswagger', 'Swagger\Swagger')
2 \vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(593): Zend\ServiceManager\ServiceManager->doCreate('Swagger\Swagger', 'swaggerswagger')
3 \vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(525): Zend\ServiceManager\ServiceManager->create(Array)
4 \vendor\outeredge\swagger-module\src\SwaggerModule\Controller\DocumentationController.php(39): Zend\ServiceManager\ServiceManager->get('Swagger\Swagger')
5 \vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): SwaggerModule\Controller\DocumentationController->displayAction()
6 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
7 \vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
8 \vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
9 \vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(116): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
10 \vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(113): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
11 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
12 \vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
13 \vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
14 \vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
15 \public\index.php(10): Zend\Mvc\Application->run()
16 {main}"}}]}
答案 0 :(得分:0)
swagger-module
似乎不活跃。请改为尝试https://github.com/zircote/swagger-php。
答案 1 :(得分:0)
1)在 \ config \ autoload 中创建 swagger.local.php 文件 (在开发系统中swagger.development.php )
2) swagger.local.php 有以下内容。
return array(
'swagger' => array(
'paths' => array(
__DIR__ . '/../../module/Api/src/Api/Controller',
),
'resource_options' => array(
'output' => 'array',
'json_pretty_print' => true,
'defaultBasePath' => '/',
'defaultApiVersion' => null,
'defaultSwaggerVersion' => '1.2',
),
)
);
由于