API 平台现在不提供此配置,您将不得不OpenApiFactory
像这样装饰
大摇大摆的文档按他们的tags
<?php
// src/OpenApi/OpenApiFactory.php
namespace App\OpenApi;
use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\Core\OpenApi\OpenApi;
use ApiPlatform\Core\OpenApi\Model;
final class OpenApiFactory implements OpenApiFactoryInterface
{
private $decorated;
public function __construct(OpenApiFactoryInterface $decorated)
{
$this->decorated = $decorated;
}
public function __invoke(array $context = []): OpenApi
{
$openApi = $this->decorated->__invoke($context);
$paths = $openApi->getPaths()->getPaths();
$filteredPaths = new Model\Paths();
foreach ($paths as $path => $pathItem) {
// Here you can check the tags for each Operations
// Add custom logic with the snippet below
}
return $openApi->withPaths($filteredPaths);
}
}
脏的部分来了,标签将是EntityName
而不是完整的命名空间名称我会列出所有旧实体,过滤当前标签并更改为旧的或新的(下面是伪代码)
$OldEntityList = ['entity1', 'entity2', ...]
foreach ($Operations as $op) {
if (in_array($op->getTags(), $OldEntityList) {
$op->withTags('old');
} else {
$op->withTags('new');
}
}