必需@SWG \ Info()未找到

时间:2015-10-01 09:42:49

标签: php swagger laravel-5.1

我很擅长使用Swagger。由于我的项目是使用Laravel,我使用Swaggerevel来记录我的API。我尝试生成如下,

./vendor/bin/swagger app/ -o storage/docs/api-docs.json

它表明

[INFO] Required @SWG\Info() not found

    get /api/resource.json
-----------------------
1 operations documented
-----------------------
Written to /home/admin/api/gevme-api/storage/docs/api-docs.json

当我尝试访问时,localhost:8000/docs,它正确显示我生成的json api。但是当我尝试访问localhost:8000/api-docs时,会再次显示相同的错误消息。

ErrorException in Logger.php line 38:
Required @SWG\Info() not found
in Logger.php line 38
at HandleExceptions->handleError('1024', 'Required @SWG\Info() not found', '/home/admin/api/gevme-api/vendor/zircote/swagger-php/src/Logger.php', '38', array('entry' => 'Required @SWG\Info() not found', 'type' => '1024'))
at trigger_error('Required @SWG\Info() not found', '1024') in Logger.php line 38
at Logger->Swagger\{closure}('Required @SWG\Info() not found', '1024')
at call_user_func(object(Closure), 'Required @SWG\Info() not found', '1024') in Logger.php line 68
at Logger::notice('Required @SWG\Info() not found') in AbstractAnnotation.php line 365
at AbstractAnnotation->validate() in Analysis.php line 284
at Analysis->validate() in functions.php line 46
at Swagger\scan('/home/admin/api/gevme-api/modules/Api', array('exclude' => array('/home/admin/api/gevme-api/storage', '/home/admin/api/gevme-api/tests', '/home/admin/api/gevme-api/resources/views', '/home/admin/api/gevme-api/config', '/home/admin/api/gevme-api/vendor'))) in routes.php line 39
at SwaggervelServiceProvider->{closure}()
at call_user_func_array(object(Closure), array()) in Route.php line 155
at Route->runCallable(object(Request)) in Route.php line 130
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in OAuthExceptionHandlerMiddleware.php line 36
at OAuthExceptionHandlerMiddleware->handle(object(Request), object(Closure))
at call_user_func_array(array(object(OAuthExceptionHandlerMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
at require_once('/home/admin/api/gevme-api/public/index.php') in server.php line 21

3 个答案:

答案 0 :(得分:23)

问题是 - 你错过了formalpara块。 这是一个告诉swagger一些关于你的API的最常见信息。

我通常将它放在一个单独的控制器中,这个控制器呈现出骄傲的JSON。 这是一个例子:

@SWG\Info

答案 1 :(得分:0)

如果您遇到这种情况,并且您在控制器中有Swagger定义等但仍未查看注释,请确保您的opcache配置中没有以下设置:

opcache.save_comments=1
opcache.load_comments=1

上面的设置删除并卸载了swagger创建文档所需的docblox。

答案 2 :(得分:0)

对于Laravel 5.6,我启动了

composer require darkaonline/l5-swagger:5.6

并悄无声息地安装了5.6.0版本(已链接到zircote / swagger-php版本两个),我什至在控制器中遇到@OA\Info块的错误。

我跑步时

composer require darkaonline/l5-swagger:5.6.9

并将zircote / swagger-php版本增加到

composer require zircote/swagger-php:3.0.2

我的问题解决了