Add the possibility to specify request schema

[MAILPOET-4207]
This commit is contained in:
Jan Jakes
2022-04-12 13:21:24 +02:00
committed by Veljko V
parent a06a8af0d5
commit c5ff597267
2 changed files with 13 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ namespace MailPoet\Automation\Engine\API;
use MailPoet\Automation\Engine\Exceptions\Exception;
use MailPoet\Automation\Engine\Hooks;
use MailPoet\Automation\Engine\WordPress;
use MailPoet\Validator\Schema;
use Throwable;
use WP_REST_Request;
@@ -53,6 +54,10 @@ class API {
}
private function registerRoute(string $route, string $endpointClass, string $method): void {
$schema = array_map(function (Schema $field) {
return $field->toArray();
}, $endpointClass::getRequestSchema());
$this->wordPress->registerRestRoute(self::PREFIX, $route, [
'methods' => $method,
'callback' => function (WP_REST_Request $wpRequest) use ($endpointClass) {
@@ -68,6 +73,7 @@ class API {
$endpoint = $this->endpointFactory->createEndpoint($endpointClass);
return $endpoint->checkPermissions();
},
'args' => $schema,
]);
}