Api平台--对特定路径使用特定的搜索过滤器。

问题描述 投票:0回答:1

在我的例子中,对于同一个实体,我为入站和出站链接创建了两个不同的路径。在文档(Swagger)中,我只想使用以下路径作为过滤器。网址 对于入境和 网页 为出站。目前,所有的字段都出现在这2个路径上,我使用的是Symfony 4.4和Api Platform 2.4,谢谢你的帮助。

/**
 * @ApiResource(
 *     shortName="page_links",
 *     collectionOperations={
 *          "inbound"={
 *              "path"="/page/links/inbound",
 *              "method"="GET",
 *          },
 *          "outbound"={
 *              "path"="/page/links/outbound",
 *              "method"="GET",
 *          }
 *     },
 *     itemOperations={"get"={"method"="GET", "path"="/page/links/{id}"}},
 * )
 * @ApiFilter(SearchFilter::class, properties={"href": "partial", "uid": "partial", "page": "partial"})
 * @ORM\Table("res_link_pages")
 * @ORM\Entity(repositoryClass="App\Repository\ResLinkPagesRepository")
 */
symfony api-platform.com
1个回答
0
投票

我找到了一个解决方案,添加了一些openapi_context属性。

/**
 * @ApiResource(
 *     shortName="page_links",
 *     collectionOperations={
 *          "inbound"={
 *              "path"="/page/links/inbound",
 *              "method"="GET",
 *              "openapi_context" = {
 *                  "parameters" = {
 *                      {
 *                          "name" = "page",
 *                          "type" = "string",
 *                          "in" = "query"
 *                      }
 *                  }
 *              }
 *          },
 *          "outbound"={
 *              "path"="/page/links/outbound",
 *              "method"="GET",
 *              "openapi_context" = {
 *                  "parameters" = {
 *                      {
 *                          "name" = "href",
 *                          "type" = "string",
 *                          "in" = "query"
 *                      }
 *                  }
 *              }
 *          }
 *     },
 *     itemOperations={"get"={"method"="GET", "path"="/page/links/{id}"}},
 * )
 * @ApiFilter(SearchFilter::class, properties={"href": "partial", "uid": "partial", "page": "partial"})
 * @ORM\Table("res_link_pages")
 * @ORM\Entity(repositoryClass="App\Repository\ResLinkPagesRepository")
 */
© www.soinside.com 2019 - 2024. All rights reserved.