vyuldashev / laravel-openapi

Generate OpenAPI specification for Laravel Applications
MIT License
413 stars 96 forks source link

Non serializable configuration when using global security #10

Open marezelej opened 4 years ago

marezelej commented 4 years ago

When configuring global security it is not posible to use config:cache command as it breaks with the "Your configuration files are not serializable." exception. At config/openapi.php: 'security' => [ GoldSpecDigital\ObjectOrientedOAS\Objects\SecurityRequirement::create()->securityScheme('oauth2'), ], Exception: image

I solved the issue using an array for the security specification, but had to override the GoldSpecDigital\ObjectOrientedOAS\OpenApi class.

matthew-inamdar commented 4 years ago

@vyuldashev could this be solved by providing custom __unserialize() and __wakeup() methods for each object?

vyuldashev commented 4 years ago

@matthew-inamdar I guess so. Probably in BaseObject would be enough.

marezelej commented 4 years ago

Method __get_state should be added too.

marezelej commented 4 years ago

I added by extending SecurityRequirement class and got same problem with GoldSpecDigital\ObjectOrientedOAS\Utilities\Extensions class.

andrewminion-luminfire commented 4 years ago

@marezelej Did you get this working? I’m running into the same problems.

marezelej commented 4 years ago

@andrewminion-luminfire yes... I ovewritten OpenApi class using composer. There, changed security method signature to allow passing an array as security configuration. Composer.json override: image OpenApi.php override: image openapi.php security configuration: image

It is not the best solution but worked for me.

andrewminion-luminfire commented 4 years ago

Thanks @marezelej!

macbookandrew commented 2 years ago

https://github.com/goldspecdigital/oooas/pull/56 should fix this

abordage commented 9 months ago

Solution based on https://github.com/symplify/vendor-patches:

  1. install symplify/vendor-patches

  2. update config/openapi.php

    'security' => [
    [
        'BearerToken' => []
    ],
    ],
  3. copy vendor/goldspecdigital/oooas/src/OpenApi.php to vendor/goldspecdigital/oooas/src/OpenApi.php.old and update security method in vendor/goldspecdigital/oooas/src/OpenApi.php

    * @param array $security
    * @return static
    */
    public function security($security): self
    {
    $instance = clone $this;
    
    $instance->security = [$security] ?: null;
    
    return $instance;
    }
  4. run vendor/bin/vendor-patches generate

  5. run composer update

  6. check php artisan optimize