Skip to content

EspoCRM – Open Source CRM Application

api spec specific module

Yuri Kuznetsov627cdaf58d8b
diff --git a/application/Espo/Tools/OpenApi/Api/GetSpec.php b/application/Espo/Tools/OpenApi/Api/GetSpec.php
index 28edcbbcd1..2e72bfef86 100644
--- a/application/Espo/Tools/OpenApi/Api/GetSpec.php
+++ b/application/Espo/Tools/OpenApi/Api/GetSpec.php
@@ -57,8 +57,14 @@ class GetSpec implements Action
$provider = $this->providerFactory->create();
$skipCustom = $request->getQueryParam('skipCustom') === 'true';
+ $module = $request->getQueryParam('module');
- $spec = $provider->get(new Params(skipCustom: $skipCustom));
+ $params = new Params(
+ skipCustom: $skipCustom,
+ module: $module,
+ );
+
+ $spec = $provider->get($params);
return ResponseComposer::empty()
->writeBody($spec)
diff --git a/application/Espo/Tools/OpenApi/Provider.php b/application/Espo/Tools/OpenApi/Provider.php
index 5009ff75b1..e2653125ff 100644
--- a/application/Espo/Tools/OpenApi/Provider.php
+++ b/application/Espo/Tools/OpenApi/Provider.php
@@ -32,11 +32,13 @@ namespace Espo\Tools\OpenApi;
use Espo\Core\Acl\GlobalRestriction;
use Espo\Core\Acl\Table;
use Espo\Core\AclManager;
+use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Select\Where\Item\Type as WhereItemType;
use Espo\Core\Utils\DataCache;
use Espo\Core\Utils\FieldUtil;
use Espo\Core\Utils\Json;
use Espo\Core\Utils\Metadata;
+use Espo\Core\Utils\Module;
use Espo\Entities\Team;
use Espo\ORM\Defs;
use Espo\ORM\Defs\Params\FieldParam;
@@ -65,10 +67,17 @@ class Provider
private AclManager $aclManager,
private FieldUtil $fieldUtil,
private DataCache $dataCache,
+ private Module $module,
) {}
+ /**
+ * @throws BadRequest
+ */
public function get(Params $params): string
{
+ $this->validateParams($params);
+ $params = $this->sanitizeParams($params);
+
$data = $this->getData($params);
return Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
@@ -139,8 +148,14 @@ class Provider
{
$key = self::CACHE_KEY;
+ if ($params->module !== null) {
+ $key .= '_' . $params->module;
+
+ return $key;
+ }
+
if ($params->skipCustom) {
- $key .= 'SkipCustom';
+ $key .= '_skipCustom';
}
return $key;
@@ -198,6 +213,10 @@ class Provider
$disabled = $it['disabled'] ?? false;
$module = $it['module'] ?? false;
+ if ($params->module !== null && $params->module !== $module) {
+ continue;
+ }
+
if ($params->skipCustom && $module === 'Custom') {
continue;
}
@@ -1114,4 +1133,26 @@ class Provider
return $createOperation;
}
+
+ /**
+ * @throws BadRequest
+ */
+ private function validateParams(Params $params): void
+ {
+ if (
+ $params->module !== null &&
+ !in_array($params->module, $this->module->getList())
+ ) {
+ throw new BadRequest("Module does not exist.");
+ }
+ }
+
+ private function sanitizeParams(Params $params): Params
+ {
+ if ($params->module !== null) {
+ $params = $params->withSkipCustom(true);
+ }
+
+ return $params;
+ }
}
diff --git a/application/Espo/Tools/OpenApi/Provider/Params.php b/application/Espo/Tools/OpenApi/Provider/Params.php
index c8bb84d7f6..f5ac570413 100644
--- a/application/Espo/Tools/OpenApi/Provider/Params.php
+++ b/application/Espo/Tools/OpenApi/Provider/Params.php
@@ -6,5 +6,14 @@ readonly class Params
{
public function __construct(
public bool $skipCustom = false,
+ public ?string $module = null,
) {}
+
+ public function withSkipCustom(bool $skipCustom): self
+ {
+ return new self(
+ skipCustom: $skipCustom,
+ module: $this->module,
+ );
+ }
}