DarkaOnLine / L5-Swagger

OpenApi or Swagger integration to Laravel

Home Page:https://github.com/DarkaOnLine/L5-Swagger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version is only available reliably for validation and serialization

andrey-helldar opened this issue · comments

  • L5-Swagger Version: 8.6.0
  • Laravel Version: 11.0.8
  • PHP Version: 8.3.4
  • OS: Windows 11 Pro

Description:

After upgrading the zircote/swagger-php component from version 4.8.6 to version 4.8.7, an error started appearing when trying to generate documentation:

$ php artisan l5-swagger:generate --all
Regenerating docs private

   RuntimeException 

  Version is only available reliably for validation and serialization

  at vendor\zircote\swagger-php\src\Context.php:124
    120▕      */
    121▕     public function isVersion($versions): bool
    122▕     {
    123▕         if (!$this->version) {
  ➜ 124▕             throw new \RuntimeException('Version is only available reliably for validation and serialization');
    125▕         }
    126▕
    127▕         $versions = (array) $versions;
    128▕         $currentVersion = $this->version ?: OA\OpenApi::DEFAULT_VERSION;

  1   vendor\zircote\swagger-php\src\Annotations\AbstractAnnotation.php:175
      OpenApi\Context::isVersion("3.0.0")

  2   vendor\zircote\swagger-php\src\Annotations\AbstractAnnotation.php:394
      OpenApi\Annotations\AbstractAnnotation::isOpenApiVersion("3.0.0")

There is speculation that because of these changes: zircote/swagger-php#1561, zircote/swagger-php@4.8.6...4.8.7

Steps To Reproduce:

composer update

Update the dependency. We see an error when trying to generate.

commented
  • L5-Swagger Version: 8.6.0
  • Laravel Version: 9.52.16
  • PHP Version: 8.2.15
  • OS: Ubuntu 22.04.4

I'm getting the same error (Version is only available reliably for validation and serialization) as @andrey-helldar , after the update.

RuntimeException 

Version is only available reliably for validation and serialization

at vendor/zircote/swagger-php/src/Context.php:124
  120▕      */
  121▕     public function isVersion($versions): bool
  122▕     {
  123▕         if (!$this->version) {
➜ 124▕             throw new \RuntimeException('Version is only available reliably for validation and serialization');
  125▕         }
  126▕ 
  127▕         $versions = (array) $versions;
  128▕         $currentVersion = $this->version ?: OA\OpenApi::DEFAULT_VERSION;

1   vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php:175
    OpenApi\Context::isVersion()

2   vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php:394
    OpenApi\Annotations\AbstractAnnotation::isOpenApiVersion()

3   [internal]:0
    OpenApi\Annotations\AbstractAnnotation::jsonSerialize()

4   vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php:282
    json_encode()

5   vendor/zircote/swagger-php/src/Annotations/OpenApi.php:182
    OpenApi\Annotations\AbstractAnnotation::toJson()

6   vendor/darkaonline/l5-swagger/src/Generator.php:299
    OpenApi\Annotations\OpenApi::saveAs()

7   vendor/darkaonline/l5-swagger/src/Generator.php:134
    L5Swagger\Generator::saveJson()

8   vendor/darkaonline/l5-swagger/src/Console/GenerateDocsCommand.php:72
    L5Swagger\Generator::generateDocs()

9   vendor/darkaonline/l5-swagger/src/Console/GenerateDocsCommand.php:58
    L5Swagger\Console\GenerateDocsCommand::generateDocumentation()

10  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
    L5Swagger\Console\GenerateDocsCommand::handle()

11  vendor/laravel/framework/src/Illuminate/Container/Util.php:41
    Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()

12  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
    Illuminate\Container\Util::unwrapIfClosure()

13  vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35
    Illuminate\Container\BoundMethod::callBoundMethod()

14  vendor/laravel/framework/src/Illuminate/Container/Container.php:661
    Illuminate\Container\BoundMethod::call()

15  vendor/laravel/framework/src/Illuminate/Console/Command.php:183
    Illuminate\Container\Container::call()

16  vendor/symfony/console/Command/Command.php:326
    Illuminate\Console\Command::execute()

17  vendor/laravel/framework/src/Illuminate/Console/Command.php:152
    Symfony\Component\Console\Command\Command::run()

18  vendor/symfony/console/Application.php:1078
    Illuminate\Console\Command::run()

19  vendor/symfony/console/Application.php:324
    Symfony\Component\Console\Application::doRunCommand()

20  vendor/symfony/console/Application.php:175
    Symfony\Component\Console\Application::doRun()

21  vendor/laravel/framework/src/Illuminate/Console/Application.php:102
    Symfony\Component\Console\Application::run()

22  vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:155
    Illuminate\Console\Application::run()

23  artisan:35
    Illuminate\Foundation\Console\Kernel::handle()

@AdAvAn, you can apply a hotfix by rolling back one of the dependencies.

To do this, run the command in the console:

composer require --dev zircote/swagger-php:4.8.6