Skip to content

Commit

Permalink
Merge pull request #90 from niels-nijens/remove-x-symfony-controller-…
Browse files Browse the repository at this point in the history
…support

Remove 'x-symfony-controller-support' specification extension support
  • Loading branch information
niels-nijens authored Mar 28, 2024
2 parents 39253fd + 46bc4e4 commit 17fd68a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 119 deletions.
11 changes: 0 additions & 11 deletions src/Routing/RouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Nijens\OpenapiBundle\Routing;

use Nijens\OpenapiBundle\Controller\CatchAllController;
use Nijens\OpenapiBundle\DependencyInjection\Configuration;
use Nijens\OpenapiBundle\Json\JsonPointer;
use Nijens\OpenapiBundle\Json\SchemaLoaderInterface;
use stdClass;
Expand Down Expand Up @@ -161,16 +160,6 @@ private function parseOpenapiBundleSpecificationExtension(stdClass $operation, a
$defaults['_controller'] = $operation->{'x-openapi-bundle'}->controller;
}

if (isset($defaults['_controller']) === false && isset($operation->{'x-symfony-controller'})) {
trigger_deprecation(
Configuration::BUNDLE_NAME,
'1.5',
'Using the "x-symfony-controller" specification extension is deprecated and will be removed in 2.0. Please use the "x-openapi-bundle" specification extension instead.'
);

$defaults['_controller'] = $operation->{'x-symfony-controller'};
}

if (isset($operation->{'x-openapi-bundle'}->deserializationObject)) {
$openapiRouteContext[RouteContext::DESERIALIZATION_OBJECT] = $operation->{'x-openapi-bundle'}->deserializationObject;
}
Expand Down
21 changes: 14 additions & 7 deletions tests/Functional/App/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ paths:
tags:
- pet
post:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\CreatePetController'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\CreatePetController'
summary: Add a new pet to the store.
operationId: addPet
requestBody:
Expand Down Expand Up @@ -94,7 +95,8 @@ paths:

/pets/{petId}:
get:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\GetPetController'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\GetPetController'
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
Expand Down Expand Up @@ -179,7 +181,8 @@ paths:

/error/trigger-error:
get:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::triggerError'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::triggerError'
responses:
'500':
description: Returns an error.
Expand All @@ -188,7 +191,8 @@ paths:

/error/throw-error:
get:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwError'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwError'
responses:
'500':
description: Returns an error.
Expand All @@ -197,7 +201,8 @@ paths:

/error/throw-http-exception:
get:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwHttpException'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwHttpException'
responses:
'500':
description: Returns an error.
Expand All @@ -206,7 +211,8 @@ paths:

/error/throw-exception:
get:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwException'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwException'
responses:
'500':
description: Returns an error.
Expand All @@ -215,7 +221,8 @@ paths:

/error/throw-invalid-argument-exception:
get:
x-symfony-controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwInvalidArgumentException'
x-openapi-bundle:
controller: 'Nijens\OpenapiBundle\Tests\Functional\App\Controller\ErrorController::throwInvalidArgumentException'
responses:
'500':
description: Returns an error.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
}
}
},
"x-symfony-controller": "Nijens\\OpenapiBundle\\Controller\\FooController::bar"
"x-openapi-bundle": {
"controller": "Nijens\\OpenapiBundle\\Controller\\FooController::bar"
}
},
"parameters": [
{
Expand Down
43 changes: 0 additions & 43 deletions tests/Routing/RouteLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Nijens\OpenapiBundle\Routing\RouteContext;
use Nijens\OpenapiBundle\Routing\RouteLoader;
use Nijens\OpenapiBundle\Tests\Functional\App\Controller\CreatePetController;
use Nijens\OpenapiBundle\Tests\Functional\App\Controller\UpdatePetController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -122,21 +121,6 @@ public function testLoadFromUnsupportedExtension(): void
$this->routeLoader->load('route-loader-minimal.txt', 'openapi');
}

/**
* Tests if {@see RouteLoader::load} adds a '_controller' default
* when the 'x-symfony-controller' property of an operation is set.
*
* @depends testLoadMinimalFromJson
*/
public function testLoadWithSymfonyControllerConfigured(): void
{
$routes = $this->routeLoader->load('route-loader-symfony-controller.json', 'openapi');
$route = $routes->get('pets_uuid_put');

static::assertInstanceOf(Route::class, $route);
static::assertSame('Nijens\OpenapiBundle\Controller\FooController::bar', $route->getDefault('_controller'));
}

public function testCanLoadRoutesWithRouteContextForRequestParameterValidation(): void
{
$routes = $this->routeLoader->load('route-loader-request-validation.yaml', 'openapi');
Expand Down Expand Up @@ -216,33 +200,6 @@ public function testCanLoadRouteWithAdditionalRouteAttributesFromOpenapiBundleSp
static::assertSame('bar', $route->getDefault('foo'));
}

public function testCanLoadRouteWithDeprecatedSpecificationExtensionWhenControllerInOpenapiBundleSpecificationExtensionDoesNotExist(): void
{
$routes = $this->routeLoader->load(
'route-loader-load-openapi-bundle-extension-backward-compatibility.yaml',
'openapi'
);
$route = $routes->get('pets_get');

static::assertInstanceOf(Route::class, $route);
static::assertSame(
'Nijens\OpenapiBundle\Tests\Functional\App\Controller\GetPetsController',
$route->getDefault('_controller')
);
}

public function testCannotLoadRouteWithDeprecatedSpecificationExtensionWhenControllerInOpenapiBundleSpecificationExtensionExists(): void
{
$routes = $this->routeLoader->load(
'route-loader-load-openapi-bundle-extension-backward-compatibility.yaml',
'openapi'
);
$route = $routes->get('pets_post');

static::assertInstanceOf(Route::class, $route);
static::assertSame(UpdatePetController::class, $route->getDefault('_controller'));
}

private function createFileLocator(): FileLocator
{
return new FileLocator([
Expand Down

0 comments on commit 17fd68a

Please sign in to comment.