Reputation: 14542
I'm working on a Sylius shop application.
Its API provides frontend / shop endpoints (sub-routes of /shop
), admin backend endpoints (sub-routes of /admin
), and some further endpoints not related to any of these areas (directly under /
).
I'm not using the /admin
sub-routes now, and it's also not planned for the near future. So I want to disable the Sylius Admin API routes and also want the Swagger UI to show only the routes / endpoints, that are actually being used.
So I need to exclude (somehow) all the endpoints under /admin/***
from the API docu generating.
The Sylius docu article "How to disable default shop, admin or API of Sylius?" shows, how to disable some parts of the system. But excactly this case is not covered.
How to remove the Admin API endpoints (in the best case: "centrally") from the Sylius API?
Upvotes: 0
Views: 714
Reputation: 517
You can decorate the Open API specification factory and remove these routes. Sylius currently is locked to API Platform v2.5 and does not work with v2.6, so here's the corresponding docs on how to customize the Open API docs: https://github.com/api-platform/docs/blob/2.5/core/swagger.md#overriding-the-openapi-specification. The code could look like this:
foreach ($docs['paths'] as $path => $pathItem) {
if (false !== strpos($path, '/admin/')) {
unset($docs['paths'][$path]);
}
}
You may also want to remove the schemas for admin operations as well.
Edit note: This will only remove the routes from the documentation, but the routes will still be active. You can either add a firewall rule to restrict access to these routes, or add a request event listener/subscriber and return a 404 or something similar when such route is requested.
Upvotes: 1
Reputation: 81
If I understand right, you need to override the Swagger on Sylius to hide the endpoint that you don't need.
I not a Sylius expert, but your problem seans some like this https://api-platform.com/docs/core/openapi/#overriding-the-ui-template
Upvotes: -1