Skip to content

Commit

Permalink
Merge pull request #91 from niels-nijens/remove-deprecated-exception-…
Browse files Browse the repository at this point in the history
…handling-and-validation

Remove deprecated exception handling and validation
  • Loading branch information
niels-nijens authored Apr 9, 2024
2 parents 17fd68a + 739dfb3 commit 5cdab01
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 1,514 deletions.
36 changes: 4 additions & 32 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,14 @@ private function addValidationSection(ArrayNodeDefinition $rootNode): void
->arrayNode('validation')
->treatTrueLike(['enabled' => true])
->treatFalseLike(['enabled' => false])
->treatNullLike(['enabled' => null])
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')
->info(
'Set to true to enable the new request validation component.'.PHP_EOL.
'Set to false to disable request validation provided by this bundle.'.PHP_EOL.
'Set to null to keep using the deprecated request validation.'
'Set to false to disable request validation provided by this bundle.'
)
->defaultNull()
->validate()
->ifNull()
->then(function ($value) {
trigger_deprecation(
self::BUNDLE_NAME,
'1.5',
'Setting the "nijens_openapi.validation.enabled" option to "null" is deprecated. It will default to "true" as of version 2.0.'
);

return $value;
})
->end()
->defaultTrue()
->end()
->booleanNode('parameter_validation')
->info('Enables the experimental query parameter request validation.')
Expand All @@ -111,28 +97,14 @@ private function addExceptionsSection(ArrayNodeDefinition $rootNode): void
->arrayNode('exception_handling')
->treatTrueLike(['enabled' => true])
->treatFalseLike(['enabled' => false])
->treatNullLike(['enabled' => null])
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')
->info(
'Set to true to enable the new serialization-based exception handling.'.PHP_EOL.
'Set to false to disable exception handling provided by this bundle.'.PHP_EOL.
'Set to null to keep using the deprecated exception JSON response builder.'
'Set to false to disable exception handling provided by this bundle.'
)
->defaultNull()
->validate()
->ifNull()
->then(function ($value) {
trigger_deprecation(
self::BUNDLE_NAME,
'1.3',
'Setting the "nijens_openapi.exceptions.enabled" option to "null" is deprecated. It will default to "true" as of version 2.0.'
);

return $value;
})
->end()
->defaultTrue()
->end()
->arrayNode('exceptions')
->useAttributeAsKey('class')
Expand Down
19 changes: 2 additions & 17 deletions src/DependencyInjection/NijensOpenapiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

namespace Nijens\OpenapiBundle\DependencyInjection;

use Nijens\OpenapiBundle\EventListener\JsonResponseExceptionSubscriber;
use Nijens\OpenapiBundle\ExceptionHandling\EventSubscriber\ProblemExceptionToJsonResponseSubscriber;
use Nijens\OpenapiBundle\ExceptionHandling\EventSubscriber\ThrowableToProblemExceptionSubscriber;
use Nijens\OpenapiBundle\ExceptionHandling\ThrowableToProblemExceptionTransformer;
use Nijens\OpenapiBundle\NijensOpenapiBundle;
use Nijens\OpenapiBundle\Routing\RouteLoader;
use Nijens\OpenapiBundle\Validation\EventSubscriber\RequestValidationSubscriber;
use Nijens\OpenapiBundle\Validation\RequestValidator\RequestParameterValidator;
Expand Down Expand Up @@ -58,15 +56,11 @@ public function load(array $configs, ContainerBuilder $container): void
}

/**
* Loads the deprecated services file with backwards compatibility for XML Schema.
* Loads the deprecated services file.
*/
private function loadDeprecatedServices(XmlFileLoader $loader): void
{
$deprecatedServicesFileSuffix = '';
if (NijensOpenapiBundle::getSymfonyVersion() >= 50100) {
$deprecatedServicesFileSuffix = '_5.1';
}
$loader->load(sprintf('services_deprecated%s.xml', $deprecatedServicesFileSuffix));
$loader->load('services_deprecated.xml');
}

private function registerRoutingConfiguration(array $config, ContainerBuilder $container): void
Expand All @@ -81,10 +75,6 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
$container->removeDefinition(RequestValidationSubscriber::class);
}

if ($config['enabled'] !== null) {
$container->removeDefinition('nijens_openapi.event_subscriber.json_request_body_validation');
}

if ($config['parameter_validation'] === false) {
$container->removeDefinition(RequestParameterValidator::class);
}
Expand All @@ -102,10 +92,5 @@ private function registerExceptionHandlingConfiguration(array $config, Container
$container->removeDefinition(ThrowableToProblemExceptionSubscriber::class);
$container->removeDefinition(ProblemExceptionToJsonResponseSubscriber::class);
}

if ($config['enabled'] !== null) {
$container->removeDefinition(JsonResponseExceptionSubscriber::class);
$container->removeDefinition('nijens_openapi.service.exception_json_response_builder');
}
}
}
163 changes: 0 additions & 163 deletions src/EventListener/JsonRequestBodyValidationSubscriber.php

This file was deleted.

77 changes: 0 additions & 77 deletions src/EventListener/JsonResponseExceptionSubscriber.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/Exception/BadJsonRequestHttpException.php

This file was deleted.

Loading

0 comments on commit 5cdab01

Please sign in to comment.