Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
"league/openapi-psr7-validator": "^0.22.0",
"nelmio/api-doc-bundle": "^5.8",
"nyholm/psr7": "^1.8",
"symfony/dependency-injection": "^7.3",
"symfony/framework-bundle": "^7.3",
"symfony/messenger": "^7.3",
"symfony/psr-http-message-bridge": "^7.3",
"symfony/serializer": "^7.3",
"symfony/validator": "^7.3"
"symfony/dependency-injection": "^7.3 || ^8.0",
"symfony/framework-bundle": "^7.3 || ^8.0",
"symfony/messenger": "^7.3 || ^8.0",
"symfony/property-access": "^7.3 || ^8.0",
"symfony/psr-http-message-bridge": "^7.3 || ^8.0",
"symfony/serializer": "^7.3 || ^8.0",
"symfony/validator": "^7.3 || ^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.91",
"nyholm/symfony-bundle-test": "^3.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
Expand All @@ -52,6 +54,8 @@
},
"scripts": {
"test": "./vendor/bin/simple-phpunit",
"test:unit": "./vendor/bin/simple-phpunit --filter Unit",
"test:functional": "./vendor/bin/simple-phpunit --filter Functional",
"check": [
"@cs-fixer",
"@phpstan"
Expand Down
1,346 changes: 711 additions & 635 deletions composer.lock

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions config/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@

use Stixx\OpenApiCommandBundle\Controller\ArgumentResolver\CommandValueResolver;
use Stixx\OpenApiCommandBundle\Controller\CommandController;
use Stixx\OpenApiCommandBundle\Responder\ResponderInterface;
use Stixx\OpenApiCommandBundle\Response\StatusResolverInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
->set(CommandController::class)
->public()
->tag('controller.service_arguments')
->arg('$commandBus', service(MessageBusInterface::class))
->arg('$validator', service(ValidatorInterface::class))
->arg('$statusResolver', service(StatusResolverInterface::class))
->arg('$responder', service(ResponderInterface::class))
->arg('$validationEnabled', param('stixx_openapi_command.validation.enabled'))
->arg('$validationGroups', param('stixx_openapi_command.validation.groups'));

$services
->set(CommandValueResolver::class)
->arg('$serializer', service('serializer'))
->tag('controller.argument_value_resolver');
};
3 changes: 1 addition & 2 deletions config/openapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
->set(CommandRouteDescriber::class)
->arg('$argumentMetadataFactory', service('argument_metadata_factory'))
->arg('$inlineParameterDescribers', tagged_iterator('nelmio_api_doc.route_argument_describer'))
->arg('$attributesCache', [])
->tag('nelmio_api_doc.route_describer', ['priority' => -260]);
};
18 changes: 8 additions & 10 deletions config/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@
use Stixx\OpenApiCommandBundle\Response\ResponseStatusResolver;
use Stixx\OpenApiCommandBundle\Response\StatusResolverInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
->set(ResponderChain::class)
->arg('$responders', tagged_iterator(ResponderInterface::TAG_NAME));
$services->alias(ResponderInterface::class, ResponderChain::class);

$services
->instanceof(ResponderInterface::class)
->tag(ResponderInterface::TAG_NAME);

$services->set(ResponseStatusResolver::class);
$services->alias(StatusResolverInterface::class, ResponseStatusResolver::class);

$services->set(JsonResponder::class);
$services->set(JsonSerializedResponder::class);
$services->set(NullableResponder::class);
$services->set(JsonResponder::class)
->tag(ResponderInterface::TAG_NAME);
$services->set(JsonSerializedResponder::class)
->arg('$serializer', service('serializer'))
->tag(ResponderInterface::TAG_NAME);
$services->set(NullableResponder::class)
->tag(ResponderInterface::TAG_NAME);
};
6 changes: 3 additions & 3 deletions config/routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
Expand All @@ -22,7 +20,9 @@

$services
->set(CommandRouteClassLoader::class)
->arg('$controllerClasses', param('stixx_openapi_command.controller_classes'));
->arg('$env', param('kernel.environment'))
->arg('$controllerClasses', param('stixx_openapi_command.controller_classes'))
->tag('routing.loader');

$services
->set(AttributeDirectoryLoaderDecorator::class)
Expand Down
5 changes: 2 additions & 3 deletions config/serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
use Stixx\OpenApiCommandBundle\Serializer\Normalizer\ConstraintViolationNormalizer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

use Symfony\Component\Serializer\Serializer;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
->set(ApiProblemNormalizer::class)
->arg('$debug', '%kernel.debug%')
->arg('$debug', param('kernel.debug'))
->tag('serializer.normalizer');
$services
->set(ConstraintViolationNormalizer::class)
Expand Down
10 changes: 7 additions & 3 deletions config/subscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use Stixx\OpenApiCommandBundle\EventSubscriber\RequestValidatorSubscriber;
use Stixx\OpenApiCommandBundle\Exception\DefaultExceptionToApiProblemTransformer;
use Stixx\OpenApiCommandBundle\Exception\ExceptionToApiProblemTransformerInterface;
use Stixx\OpenApiCommandBundle\Routing\NelmioAreaRoutesChecker;
use Stixx\OpenApiCommandBundle\Validator\RequestValidatorChain;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
Expand All @@ -24,9 +24,13 @@

$services
->set(ApiExceptionSubscriber::class)
->arg('$serializer', service('stixx_openapi_command.problem_serializer'))
->arg('$nelmioAreaRoutesChecker', service(NelmioAreaRoutesChecker::class))
->arg('$normalizer', service('stixx_openapi_command.problem_serializer'))
->arg('$exceptionTransformer', service(ExceptionToApiProblemTransformerInterface::class))
->tag('kernel.event_subscriber');
$services
->set(RequestValidatorSubscriber::class)
->arg('$requestValidatorChain', service(RequestValidatorChain::class))
->arg('$nelmioAreaRoutes', service(NelmioAreaRoutesChecker::class))
->tag('kernel.event_subscriber');
};
9 changes: 2 additions & 7 deletions config/validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@
return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure(false)
->private();

$services
->set(RequestValidatorChain::class)
->arg('$validators', tagged_iterator(StixxValidatorInterface::TAG_NAME));
$services->alias(StixxValidatorInterface::class, RequestValidatorChain::class);

$services
->instanceof(StixxValidatorInterface::class)
->tag(StixxValidatorInterface::TAG_NAME);

$services
->set(RequestValidator::class)
->arg('$apiDocGenerator', service('nelmio_api_doc.generator.default'));
->arg('$apiDocGenerator', service('nelmio_api_doc.generator.default'))
->tag(StixxValidatorInterface::TAG_NAME);
};
5 changes: 3 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
>
<php>
<env name="SYMFONY_PHPUNIT_VERSION" value="12.4" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=0" />
</php>

<testsuites>
Expand All @@ -21,9 +22,9 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory>./src/</directory>
</include>
</coverage>
</source>
</phpunit>
3 changes: 1 addition & 2 deletions src/Controller/ArgumentResolver/CommandValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ private function extractScalarsFromRouteAndQuery(Request $request): array
$routeData = array_filter(
$attributes,
static function ($value, $key): bool {
return is_string($key)
&& $key !== ''
return $key !== ''
&& $key[0] !== '_'
&& (is_scalar($value) || $value === null);
},
Expand Down
6 changes: 4 additions & 2 deletions src/DependencyInjection/StixxOpenApiCommandExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function load(array $configs, ContainerBuilder $container): void
->addTag(ValidatorInterface::TAG_NAME);

$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$this->registerCommonConfiguration($loader);
$this->registerCommonConfiguration($loader, $container);
}

public function getAlias(): string
{
return Configuration::BUNDLE_ALIAS;
}

private function registerCommonConfiguration(PhpFileLoader $loader): void
private function registerCommonConfiguration(PhpFileLoader $loader, ContainerBuilder $container): void
{
$loader->load('controller.php');
$loader->load('response.php');
Expand All @@ -59,5 +59,7 @@ private function registerCommonConfiguration(PhpFileLoader $loader): void
$loader->load('validators.php');
$loader->load('openapi.php');
$loader->load('serializer.php');

$container->setParameter('stixx_openapi_command.controller_classes', []);
}
}
2 changes: 1 addition & 1 deletion src/EventSubscriber/ApiExceptionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => ['onKernelException', 0],
KernelEvents::EXCEPTION => ['onKernelException', 256],
];
}

Expand Down
3 changes: 3 additions & 0 deletions src/Response/ResponseStatusResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ private function findOperationAttributeForMethod(object $command, string $method
private function first2xxFromOperation(Operation $operation): ?int
{
$responses = $operation->responses;
if (!is_iterable($responses)) {
return null;
}

foreach ($responses as $response) {
$code = $response->response;
Expand Down
Empty file removed tests/Functional/.gitignore
Empty file.
45 changes: 45 additions & 0 deletions tests/Functional/AbstractKernelTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* This file is part of the StixxOpenApiCommandBundle package.
*
* (c) Stixx
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Stixx\OpenApiCommandBundle\Tests\Functional;

use Stixx\OpenApiCommandBundle\Tests\Functional\App\Kernel;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class AbstractKernelTestCase extends KernelTestCase
{
protected function tearDown(): void
{
parent::tearDown();

for ($i = 0; $i < 5; ++$i) {
restore_error_handler();
restore_exception_handler();
}
}

protected static function getKernelClass(): string
{
return Kernel::class;
}

protected function createKernelWithConfig(callable $config): Kernel
{
$kernel = new Kernel('test', true);

$config($kernel);
$kernel->boot();

return $kernel;
}
}
38 changes: 38 additions & 0 deletions tests/Functional/App/Command/CreateBookCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/*
* This file is part of the StixxOpenApiCommandBundle package.
*
* (c) Stixx
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Stixx\OpenApiCommandBundle\Tests\Functional\App\Command;

use Nelmio\ApiDocBundle\Attribute\Model;
use OpenApi\Attributes as OA;
use Stixx\OpenApiCommandBundle\Tests\Functional\App\Model\BookRequest;
use Stixx\OpenApiCommandBundle\Tests\Functional\App\Model\BookResource;

#[OA\Post(
path: '/api/books',
summary: 'Create a book',
requestBody: new OA\RequestBody(
required: true,
content: new OA\JsonContent(ref: new Model(type: BookRequest::class))
),
responses: [
new OA\Response(
response: 201,
description: 'Book created',
content: new OA\JsonContent(ref: new Model(type: BookResource::class))
),
]
)]
final class CreateBookCommand extends BookRequest
{
}
Loading