laravel-openapi icon indicating copy to clipboard operation
laravel-openapi copied to clipboard

Non serializable configuration when using global security

Open marezelej opened this issue 5 years ago • 9 comments

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.

marezelej avatar Apr 14 '20 12:04 marezelej

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

matthew-inamdar avatar Apr 14 '20 13:04 matthew-inamdar

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

vyuldashev avatar Apr 14 '20 18:04 vyuldashev

Method __get_state should be added too.

marezelej avatar Apr 14 '20 19:04 marezelej

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

marezelej avatar Apr 14 '20 19:04 marezelej

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

andrewminion-luminfire avatar Jul 10 '20 17:07 andrewminion-luminfire

@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.

marezelej avatar Jul 11 '20 16:07 marezelej

Thanks @marezelej!

andrewminion-luminfire avatar Jul 11 '20 18:07 andrewminion-luminfire

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

macbookandrew avatar Sep 23 '22 16:09 macbookandrew

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

  1. install symplify/vendor-patches

  2. update config/openapi.php

'security' => [
    [
        'BearerToken' => []
    ],
],
  1. 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;
}
  1. run vendor/bin/vendor-patches generate
  2. run composer update
  3. check php artisan optimize

abordage avatar Feb 02 '24 12:02 abordage