L5-Swagger: Can't read swagger JSON

i follow your documentation and after i publish everything i go to the path http://localhost:8090/api/documentation and i have this error Can't read swagger JSON from http://localhost:8090/docs/api-docs.json what i suppose to do ?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Had this problem due to using PHP built-in web server and not artisan serve.

Glad you figured it out.

By the way, you can set L5_SWAGGER_GENERATE_ALWAYS=true in your config file, so that json file will be regenerated on every request. Just disable it in production environment πŸ˜‰

@ahmed-al-bermawy I missed the middleware part πŸ˜ƒ

Yes please I have the same error I see the php artisan l5-swagger:generate command generates json file in storage/api-docs/api-docs.json

But the swagger-ui is trying to access the file from the location public/docs/api-docs.json

Do I manually need to link storage/api-docs/api-docs.josn to public/docs/api-docs.json? or am i missing some config settings?

And I see the doc generation path is set as below by default in the config 'docs' => storage_path('api-docs')

And the UI is trying to access it from public location how this is going to work?

        /*
        |--------------------------------------------------------------------------
        | Route for accessing parsed swagger annotations.
        |--------------------------------------------------------------------------
        */

        'docs' => 'docs',

you don’t have to link it manually

you just need to set the routes API for me

'routes' => [
        /*
        |--------------------------------------------------------------------------
        | Route for accessing api documentation interface
        |--------------------------------------------------------------------------
        */

        'api' => 'backend/api/documentation',

so i access it from URL with this link

http://localhost:8000/backend/api/documentation

also, you need to check the middleware for me it is

        'middleware' => [
            'api' => ['web', 'auth'],
            'asset' => [],
            'docs' => ['web', 'auth'],
            'oauth2_callback' => [],
        ],

It looks like your stand alone php server is not generating .json file. Can you see your documentation .json file in desired directory when you start your php server ? Does L5_SWAGGER_GENERATE_ALWAYS is set to TRUE ?

Like you can see this problem is not associated with package it self because it is working on php artisan serve

Getting this error screen shot 2017-04-15 at 11 26 03 am

But when i open this link β€œhttp://127.0.0.1:8000/docs/api-docs.json” it works fine. & render JSON on browser

it is working now after i run php artisan l5-swagger:generate