feat: Supporto agli schemas dei moduli per la nuova API

This commit is contained in:
Maicol Battistini 2022-02-01 16:14:59 +01:00
parent b3db6fdc87
commit d60e3e7ead
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
2 changed files with 11 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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();
}
/**