Closed kichetof closed 4 months ago
Some additional informations:
./frankenphp php-cli artisan scramble:export
docker run -p 80:80 -p 443:443 -p 443:443/udp -v $PWD:/app dunglas/frankenphp
Need more investigations with Octane
As a workaround, the time to find the cause, this code works fine after having exporting doc from command line.
Route::get('docs/api.json', function (Dedoc\Scramble\Generator $generator) {
return File::exists($doc = base_path(config('scramble.export_path')))
? File::json($doc)
: $generator();
})->name('scramble.docs.index');
@romalytvynenko After many hours of digging debug, I finally found that the properties was not resolved from \Dedoc\Scramble\Infer\Scope\Index::class
\Dedoc\Scramble\Support\TypeToSchemaExtensions\JsonResourceTypeToSchema::toSchema \Dedoc\Scramble\Support\Type\ObjectType::getMethodDefinition \Dedoc\Scramble\Infer\Definition\ClassDefinition::getMethodDefinition \Dedoc\Scramble\Infer\Scope\Scope::__construct
As Index::class
is resolved only one time, it could be our issue! I resolved it by binding in shared mode and it works!
class ScrambleServiceProvider extends PackageServiceProvider
{
// $this->app->singleton(Index::class);
$this->app->bind(Index::class, shared: true);
//...
}
Without shared mode, I encounter same error from #307 as $this->index->classesDefinitions is an empty array.
[2024-04-04 18:51:22] local.ERROR: Error when analyzing route 'GET api/users' (App\Http\Controllers\UsersController@__invoke): Undefined property: Dedoc\Scramble\Support\Type\Generic::$typeToSchemaExtensions – /Users/tof/Herd/scramble-frankenphp/vendor/dedoc/scramble/src/Support/Generator/TypeTransformer.php on line 270
[2024-04-04 18:51:22] local.ERROR: Undefined property: Dedoc\Scramble\Support\Type\Generic::$typeToSchemaExtensions {"exception":"[object] (ErrorException(code: 0): Undefined property: Dedoc\\Scramble\\Support\\Type\\Generic::$typeToSchemaExtensions at /Users/tof/Herd/scramble-frankenphp/vendor/dedoc/scramble/src/Support/Generator/TypeTransformer.php:270)
I tried both php serve and octane:start and both works :)
Need further investigation to not breaking anything!
@kichetof should be fixed in v0.10.7
Hi guy!
I deployed a site with Laravel Octane powered by FrankenPHP and everything works fine and fast!
Today, I looked my API doc, and saw an error with
JsonResource
Schema.I was able to reproduce the bug with Laravel 11 and without Docker (my project is on L10 with Docker, I can exclude this), please find my repo https://github.com/kichetof/scramble-frankenphp
Example
UserResource
toArray:When serving app by:
php artisan serve
Works fine!
When serving app with Octane/FrankenPHP:
php artisan octane:frankenphp
Don't display my resource schema as expected.
I try to debug but they are no error nor no logs!
As my project is on Docker, I tried with FrankenPHP binary and Docker image (binary isn't compiled in the same way) and same behavior.
http://127.0.0.1:8000/docs/api.json : schemas "empty"; no trace of name/email
Maybe you've an idea why this happen with FrankenPHP? Thanks a lot for your help! Cheers Christophe