From 9f72b45be64056019360d9d372be001c6829712d Mon Sep 17 00:00:00 2001 From: Harrison Heck Date: Wed, 7 Mar 2018 17:33:37 -0500 Subject: [PATCH] Fixed duplicate route names with multiple http methods when using invokable controllers. This fixes the duplicate names that would occur when using multiple http methods for a single endpoint when using invokable controllers. For example: GET /example would return swagger.api.example.action POST /example would return swagger.api.example.action --- src/Routing/OpenApiRouteLoader.php | 5 ++++- tests/unit/Routing/OpenApiRouteLoaderTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Routing/OpenApiRouteLoader.php b/src/Routing/OpenApiRouteLoader.php index 7423029..64f61dc 100644 --- a/src/Routing/OpenApiRouteLoader.php +++ b/src/Routing/OpenApiRouteLoader.php @@ -199,9 +199,12 @@ private function createRouteId(string $resource, string $path, string $controlle { $controllerSegments = explode(':', $controllerKey); - $operationName = 'action'; if (count($controllerSegments) === 2) { list(, $operationName) = $controllerSegments; + } else { + $className = basename(str_replace('\\', '/', $controllerKey)); + // Convert class name to snake_case + $operationName = strtolower(preg_replace('/(?loader->load(self::DOCUMENT_PATH); - $actual = $routes->get('customname.path.a.action'); + $actual = $routes->get('customname.path.a.invokable_controller'); $this->assertNotNull($actual); $this->assertSame($expected, $actual->getDefault('_controller')); }