src/Plugin/Deriver/ResourceDeriver.php | 2 +- src/Routing/Routes.php | 16 ++++++++-------- tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php | 2 +- tests/src/Unit/Routing/RoutesTest.php | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Plugin/Deriver/ResourceDeriver.php b/src/Plugin/Deriver/ResourceDeriver.php index 1ddb5bf..2c1d030 100644 --- a/src/Plugin/Deriver/ResourceDeriver.php +++ b/src/Plugin/Deriver/ResourceDeriver.php @@ -67,7 +67,7 @@ class ResourceDeriver extends DeriverBase implements ContainerDeriverInterface { 'hasBundle' => $this->resourceManager->hasBundle($resource->getEntityTypeId()), 'type' => $resource->getTypeName(), 'data' => [ - 'partialPath' => '/api' . $resource->getPath() + 'partialPath' => $resource->getPath() ] ]; diff --git a/src/Routing/Routes.php b/src/Routing/Routes.php index a534f46..3f16231 100644 --- a/src/Routing/Routes.php +++ b/src/Routing/Routes.php @@ -97,8 +97,8 @@ class Routes implements ContainerInjectionInterface { '_is_jsonapi' => TRUE, ]; - // Collection endpoint, like /api/file/photo. - $route_collection = (new Route($partial_path)) + // Collection endpoint, like /jsonapi/file/photo. + $route_collection = (new Route('/jsonapi' . $partial_path)) ->addDefaults($defaults) ->setRequirement('_entity_type', $entity_type) ->setRequirement('_permission', $plugin_definition['permission']) @@ -112,9 +112,9 @@ class Routes implements ContainerInjectionInterface { $route_collection->addOptions($options); $collection->add($route_key . 'collection', $route_collection); - // Individual endpoint, like /api/file/photo/123. + // Individual endpoint, like /jsonapi/file/photo/123. $parameters = [$entity_type => ['type' => 'entity:' . $entity_type]]; - $route_individual = (new Route(sprintf('%s/{%s}', $partial_path, $entity_type))) + $route_individual = (new Route('/jsonapi' . sprintf('%s/{%s}', $partial_path, $entity_type))) ->addDefaults($defaults) ->setRequirement('_entity_type', $entity_type) ->setRequirement('_permission', $plugin_definition['permission']) @@ -130,8 +130,8 @@ class Routes implements ContainerInjectionInterface { $route_individual->addOptions($options); $collection->add($route_key . 'individual', $route_individual); - // Related resource, like /api/file/photo/123/comments. - $route_related = (new Route(sprintf('%s/{%s}/{related}', $partial_path, $entity_type))) + // Related resource, like /jsonapi/file/photo/123/comments. + $route_related = (new Route('/jsonapi' . sprintf('%s/{%s}/{related}', $partial_path, $entity_type))) ->addDefaults($defaults) ->setRequirement('_entity_type', $entity_type) ->setRequirement('_permission', $plugin_definition['permission']) @@ -146,8 +146,8 @@ class Routes implements ContainerInjectionInterface { $route_related->addOptions($options); $collection->add($route_key . 'related', $route_related); - // Related endpoint, like /api/file/photo/123/relationships/comments. - $route_relationship = (new Route(sprintf('%s/{%s}/relationships/{related}', $partial_path, $entity_type))) + // Related endpoint, like /jsonapi/file/photo/123/relationships/comments. + $route_relationship = (new Route('/jsonapi' . sprintf('%s/{%s}/relationships/{related}', $partial_path, $entity_type))) ->addDefaults($defaults + ['_on_relationship' => TRUE]) ->setRequirement('_entity_type', $entity_type) ->setRequirement('_permission', $plugin_definition['permission']) diff --git a/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php b/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php index 3cc9b54..8442698 100644 --- a/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php +++ b/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php @@ -66,7 +66,7 @@ class ResourceDeriverTest extends UnitTestCase { 'hasBundle' => FALSE, 'type' => 'resource_type_1', 'data' => [ - 'partialPath' => '/api/entity_type_1/bundle_path_1', + 'partialPath' => '/entity_type_1/bundle_path_1', ], 'permission' => 'access content', 'controller' => '\\Drupal\\jsonapi\\RequestHandler::handle', diff --git a/tests/src/Unit/Routing/RoutesTest.php b/tests/src/Unit/Routing/RoutesTest.php index a85f7dd..203b88c 100644 --- a/tests/src/Unit/Routing/RoutesTest.php +++ b/tests/src/Unit/Routing/RoutesTest.php @@ -42,7 +42,7 @@ class RoutesTest extends UnitTestCase { 'hasBundle' => TRUE, 'type' => 'resource_type_1', 'data' => [ - 'partialPath' => '/api/entity_type_1/bundle_path_1', + 'partialPath' => '/entity_type_1/bundle_path_1', ], 'controller' => 'MyCustomController', 'permission' => 'access content', @@ -55,7 +55,7 @@ class RoutesTest extends UnitTestCase { 'hasBundle' => TRUE, 'type' => 'resource_type_2', 'data' => [ - 'partialPath' => '/api/entity_type_2/bundle_path_2', + 'partialPath' => '/entity_type_2/bundle_path_2', ], 'controller' => 'MyCustomController', 'permission' => 'access content', @@ -89,7 +89,7 @@ class RoutesTest extends UnitTestCase { // Check the collection route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('jsonapi.resource_type_1.collection'); - $this->assertSame('/api/entity_type_1/bundle_path_1', $route->getPath()); + $this->assertSame('/jsonapi/entity_type_1/bundle_path_1', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertSame(['lorem', 'ipsum'], $route->getOption('_auth')); @@ -109,7 +109,7 @@ class RoutesTest extends UnitTestCase { // Check the individual route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('jsonapi.resource_type_1.individual'); - $this->assertSame('/api/entity_type_1/bundle_path_1/{entity_type_1}', $route->getPath()); + $this->assertSame('/jsonapi/entity_type_1/bundle_path_1/{entity_type_1}', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertEquals(['GET', 'PATCH', 'DELETE'], $route->getMethods()); @@ -130,7 +130,7 @@ class RoutesTest extends UnitTestCase { // Check the related route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('jsonapi.resource_type_1.related'); - $this->assertSame('/api/entity_type_1/bundle_path_1/{entity_type_1}/{related}', $route->getPath()); + $this->assertSame('/jsonapi/entity_type_1/bundle_path_1/{entity_type_1}/{related}', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertEquals(['GET'], $route->getMethods()); @@ -150,7 +150,7 @@ class RoutesTest extends UnitTestCase { // Check the relationships route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('jsonapi.resource_type_1.relationship'); - $this->assertSame('/api/entity_type_1/bundle_path_1/{entity_type_1}/relationships/{related}', $route->getPath()); + $this->assertSame('/jsonapi/entity_type_1/bundle_path_1/{entity_type_1}/relationships/{related}', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertEquals(['GET', 'POST', 'PATCH', 'DELETE'], $route->getMethods());