-
-
Notifications
You must be signed in to change notification settings - Fork 498
Closed
Description
Description
Considering API Platform recipes set a prefix /api
in front of all API urls, recipes must add a server object to OpenAPI specification.
This way, it will be in line with OpenAPI specification and so, more compliant with OpenAPI specification related projects.
How to reproduce
For example, APIP api-doc-parser don't work out of the box (see this issue and I face the same kind of issue) with the /api
prefix, and APIP admin neither (because based on APIP api-doc-parser).
Possible solution
This could be done adding a decorator responsible to add server object to specification and remove prefix from all routes, see example below.
OpenApiFactoryDecorator.php (source)
#[AsDecorator('api_platform.openapi.factory', priority: -99)]
readonly class OpenApiFactoryDecorator implements OpenApiFactoryInterface
{
public function __construct(
private OpenApiFactoryInterface $decorated,
) {
}
public function __invoke(array $context = []): OpenApi
{
$openApi = $this->decorated->__invoke($context);
$paths = $openApi->getPaths()->getPaths();
$newPaths = new Paths();
foreach ($paths as $keyPath => $path) {
/** @var PathItem $path */
$newPaths->addPath(\str_replace('/api', '', $keyPath), $path);
}
$openApi = $openApi->withPaths($newPaths);
$openApi = $openApi->withServers([new Server('/api')]);
return $openApi;
}
}
Metadata
Metadata
Assignees
Labels
No labels