12

I'm pretty new to using Swagger. Since my project is with Laravel, I use Swaggerevel to document my API. During I tried to generate as follows,

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

It shows that

[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

When I tried to access, It localhost:8000/docs, It properly show json api which I generated. But when I tried to access localhost:8000/api-docs, the same error message show again.

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 Answers 3

31

The problem is - you're missing the @SWG\Info block. It's a block which tells swagger some most common information about your API.

I usually put this in a separate controller which is rendering swagger JSON. Here's an example:

/**
 * @SWG\Swagger(
 *     schemes={"http","https"},
 *     host="api.host.com",
 *     basePath="/",
 *     @SWG\Info(
 *         version="1.0.0",
 *         title="This is my website cool API",
 *         description="Api description...",
 *         termsOfService="",
 *         @SWG\Contact(
 *             email="[email protected]"
 *         ),
 *         @SWG\License(
 *             name="Private License",
 *             url="URL to the license"
 *         )
 *     ),
 *     @SWG\ExternalDocumentation(
 *         description="Find out more about my website",
 *         url="http..."
 *     )
 * )
 */

class SwaggerController extends...
4
  • 5
    i have got the same error but with Lumen framework using DarkaOnLine/SwaggerLume. where can i find this file to edit it ?
    – Niahm
    Commented Apr 12, 2016 at 10:00
  • Wherever you place your Swagger documentation. You usually need to create it manually. I don't know about Lumen.
    – Mathew
    Commented Aug 8, 2016 at 11:51
  • @AhmedZelfani did you find how did you fix this ?
    – user269867
    Commented Apr 17, 2017 at 21:18
  • @AhmedZelfani @user269867 You can create a simple controller like Mathew does above in your app/Http/Controllers directory. Commented Sep 7, 2017 at 19:02
0

If this happens to you, and you have the Swagger definition in the controller etc but still aren't seeing the comments make sure you don't have the following settings in your opcache configuration:

opcache.save_comments=1
opcache.load_comments=1

The settings above remove and not-load the docblox needed for swagger to create the documentation.

1
  • what? are you sure?
    – user4332766
    Commented Oct 19, 2017 at 17:08
0

For Laravel 5.6 I launched

composer require darkaonline/l5-swagger:5.6

and quietly installed version 5.6.0 (which was linked to zircote/swagger-php version TWO), and I got subj error having @OA\Info block in Controller even.

When I runned

composer require darkaonline/l5-swagger:5.6.9

and increased version of zircote/swagger-php to

composer require zircote/swagger-php:3.0.2

my problem was solved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.