feat: Supporto agli schemas dei moduli per la nuova API
This commit is contained in:
parent
b3db6fdc87
commit
d60e3e7ead
|
@ -18,11 +18,11 @@ class Controller extends BaseController
|
|||
use DispatchesJobs;
|
||||
use ValidatesRequests;
|
||||
|
||||
public function getModules(Request $request, ?array $filter = null): JsonResponse|Collection
|
||||
public function getModules(?Request $request = null, ?array $filter = null): JsonResponse|Collection
|
||||
{
|
||||
$packages = collect(Json::decode(File::get(base_path('vendor/composer/installed.json')))->packages);
|
||||
|
||||
$modules = $packages->filter(fn ($package) => $package->type === 'openstamanager-module');
|
||||
$modules = $packages->filter(fn($package) => $package->type === 'openstamanager-module');
|
||||
|
||||
$modules->transform(function ($module) {
|
||||
$osm_modules = collect($module->extra->{'osm-modules'});
|
||||
|
@ -46,6 +46,6 @@ class Controller extends BaseController
|
|||
|
||||
$filtered = $modules->only($filter);
|
||||
|
||||
return $request->wantsJson() ? response()->json($filtered) : $filtered;
|
||||
return ($request && $request->wantsJson()) ? response()->json($filtered) : $filtered;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\JsonApi\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\JsonApi\V1\Users\UserSchema;
|
||||
use LaravelJsonApi\Core\Server\Server as BaseServer;
|
||||
|
||||
|
@ -25,9 +26,13 @@ class Server extends BaseServer
|
|||
*/
|
||||
protected function allSchemas(): array
|
||||
{
|
||||
return [
|
||||
UserSchema::class,
|
||||
];
|
||||
return app(Controller::class)
|
||||
->getModules()
|
||||
->pluck('config.api.schemas')
|
||||
->reject(null)
|
||||
->merge([
|
||||
UserSchema::class,
|
||||
])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue