Custom route => re-generate api.json live on local, use cached on production #897
-
|
Hello 👋 , We use a custom route for scramble (see code below) that checks de difference between local en production. On local we still want it to live generate, but i can not find a way how to do that. My code: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hey @mcorten! Cool, you're almost there! The only thing left is to inject a generator instance into the route's handler, and invoke it with the configuration (the generator instance is invokable). The result of the invocation is the OpenAPI document you're looking for. use Dedoc\Scramble\Generator;
Route::get('/api/****/***', function (Generator $generator) {
if (App::isLocal()) {
return view('scramble::docs', [
'config' => $config = Scramble::getGeneratorConfig('default'),
'spec' => $generator($config),
]);
}
/* return a cached version of the api.json for staging and production */
if (App::isProduction()) {
return view('scramble::docs', [
'spec' => file_get_contents(base_path('api.json')),
'config' => Scramble::getGeneratorConfig('default'),
]);
}
}); |
Beta Was this translation helpful? Give feedback.
Hey @mcorten! Cool, you're almost there! The only thing left is to inject a generator instance into the route's handler, and invoke it with the configuration (the generator instance is invokable). The result of the invocation is the OpenAPI document you're looking for.