From f0dba6f8b2779047957066ff67fa24080248a67a Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 14 Feb 2024 15:54:54 +0100 Subject: [PATCH] Updates on the openapi spec --- src/ApiResource/Gateway.php | 6 +++--- src/Entity/Account.php | 4 ++++ src/OpenApi/OpenApiFactory.php | 18 +++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/ApiResource/Gateway.php b/src/ApiResource/Gateway.php index 80d8c4e..0a9c26c 100644 --- a/src/ApiResource/Gateway.php +++ b/src/ApiResource/Gateway.php @@ -7,10 +7,10 @@ use App\Library\Economy\Payment\GatewayInterface; use App\State\GatewayStateProvider; /** - * Gateways represent payment services used to perform Transactions from Users into Accountings of the platform.\ + * Gateways represent payment services used to perform the necessary payments for Transactions between Accounts.\ * \ - * For each Gateway there is an internal implementation that handles the creation and validation of Transactions between Accountings. - * These implementations make use of external or internal payment services to gather the funds that are inside a Transaction, + * For each Gateway there is an internal implementation that handles the creation and validation of Transactions between Accounts. + * These implementations make use of external or internal services to gather the funds that are inside a Transaction, * perform corroboration of funds and store the Transactions into the system. */ #[API\GetCollection(provider: GatewayStateProvider::class)] diff --git a/src/Entity/Account.php b/src/Entity/Account.php index b2eff99..1578b28 100644 --- a/src/Entity/Account.php +++ b/src/Entity/Account.php @@ -6,8 +6,12 @@ use ApiPlatform\Metadata as API; use App\Repository\AccountRepository; use Doctrine\ORM\Mapping as ORM; +/** + * Accounts are the senders and receivers of Transactions. + */ #[ORM\Entity(repositoryClass: AccountRepository::class)] #[API\ApiResource] +#[API\Get()] class Account { #[ORM\Id] diff --git a/src/OpenApi/OpenApiFactory.php b/src/OpenApi/OpenApiFactory.php index 21b74f1..c70c961 100644 --- a/src/OpenApi/OpenApiFactory.php +++ b/src/OpenApi/OpenApiFactory.php @@ -22,15 +22,19 @@ class OpenApiFactory implements OpenApiFactoryInterface $idResource = $operation->getTags()[0]; $idOperation = array_slice($idParts, -1)[0]; + $operationDescription = $operation->getDescription(); + switch ($idOperation) { case 'collection': $operationId = sprintf('List all %ss', $idResource); break; case 'post': $operationId = sprintf('Create one %s', $idResource); + $operationDescription = sprintf('Creates a new %s resource.', $idResource); break; case 'get': $operationId = sprintf('Retrieve one %s', $idResource); + $operationDescription = sprintf('Retrieves one %s resource.', $idResource); break; case 'put': $operationId = sprintf('Update one %s', $idResource); @@ -46,8 +50,9 @@ class OpenApiFactory implements OpenApiFactoryInterface } return $operation + ->withSummary($operationId) ->withOperationId($operationId) - ->withSummary($operationId); + ->withDescription($operationDescription); } private function updatePathItemOperations(PathItem $pathItem): PathItem @@ -89,6 +94,10 @@ class OpenApiFactory implements OpenApiFactoryInterface { $openApi = $this->decorated->__invoke($context); + $openApi = $openApi->withServers([ + new Model\Server(sprintf('%s://%s', $_SERVER['REQUEST_SCHEME'], $_SERVER['HTTP_HOST'])) + ]); + $openApi = $openApi->withInfo( $openApi ->getInfo() @@ -104,8 +113,7 @@ class OpenApiFactory implements OpenApiFactoryInterface $tags = []; foreach ($openApi->getComponents()->getSchemas() as $name => $schema) { - if (\preg_match('/.*\.json/', $name)) continue; - if (empty($schema['description'])) continue; + if (\preg_match('/.*\.jsonld/', $name)) continue; $tags[] = [ 'name' => $name, @@ -124,10 +132,6 @@ class OpenApiFactory implements OpenApiFactoryInterface $openApi = $openApi->withPaths($paths); - $openApi = $openApi->withServers([ - new Model\Server(sprintf('%s://%s', $_SERVER['REQUEST_SCHEME'], $_SERVER['HTTP_HOST'])) - ]); - return $openApi; } }