4

I was working on php version 7.2 but now upgrading to 7.4 gave an issue while generating l5-swagger. I read this stackoverflow qauestion which is not working for me.

php artisan l5-swagger:generate
Regenerating docs

   ErrorException  : Trying to access array offset on value of type bool

  at /home/smartmobe/Projects/defence-new/server/vendor/zircote/swagger-php/src/StaticAnalyser.php:37
    33|             if (empty($GLOBALS['swagger_opcache_warning'])) {
    34|                 $GLOBALS['swagger_opcache_warning'] = true;
    35|                 $status = opcache_get_status();
    36|                 $config = opcache_get_configuration();
  > 37|                 if ($status['opcache_enabled'] && $config['directives']['opcache.save_comments'] == false) {
    38|                     Logger::warning("php.ini \"opcache.save_comments = 0\" interferes with extracting annotations.\n[LINK] http://php.net/manual/en/opcache.configuration.php#ini.opcache.save-comments");
    39|                 }
    40|             }
    41|         }

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError()
      /home/smartmobe/Projects/defence-new/server/vendor/zircote/swagger-php/src/StaticAnalyser.php:37

  2   Swagger\StaticAnalyser::fromFile()
      /home/smartmobe/Projects/defence-new/server/vendor/zircote/swagger-php/src/functions.php:41

  Please use the argument -v to see more details.
Dharman
  • 30,962
  • 25
  • 85
  • 135
monica kauri
  • 49
  • 1
  • 3

2 Answers2

2

zircote/swagger-php (the package in which your exception occurs) was updated to support PHP 7.4 in version 3.0.3. If you're using Composer you can check the current version of the package in your project with composer info zircote/swagger-php and you can update it using composer update.

If composer update doesn't do the trick, you need to check that your composer.json allows for darkaonline/l5-swagger to have a version greater than 5.6.1 because it only started to support zircote/swagger-php:3.* from 5.6.2 upwards.

D Malan
  • 10,272
  • 3
  • 25
  • 50
  • I currently have: darkaonline/l5-swagger 6.0.3 Swagger integration to Laravel 5 – monica kauri Dec 03 '19 at 08:55
  • I updated the composer to set: "zircote/swagger-php": "3.0.3", – monica kauri Dec 03 '19 at 08:56
  • Did you run `composer update`? So you shouldn't get exception anymore now. – D Malan Dec 03 '19 at 09:00
  • 1
    composer update doesn't work and my current version for "darkaonline/l5-swagger" is "6.0.*". Following error is shown after updating: Symfony\Component\Debug\Exception\FatalThrowableError : Call to undefined function Swagger\scan() at /home/smartmobe/Projects/defence-new/server/vendor/darkaonline/l5-swagger/src/Generator.php:124 – monica kauri Dec 03 '19 at 09:02
0

For Laravel >= 8 and latest version of L5-Swagger you don't need to extend the route you need to add the web middleware in the l5-swagger.php config file (documentations/defaults/routes/middleware/api);

enter image description here

Luke Snowden
  • 4,056
  • 2
  • 37
  • 70