在 ApiPlatform 文档中将自定义操作添加到不同的组
Add Custom Operation to different Group in ApiPlatform docs
我有一个自定义操作 CreatePerson
,它是通过 messenger
调度的。
/**
* @ApiResource(
* messenger=true,
* output=false,
* shortName="person",
* collectionOperations={
* "post"
* },
* itemOperations={}
* )
*
* @psalm-immutable
*/
final class CreatePerson
这与 POST /api/people
的预期一样有效(people 而不是 person,因为 ApiPlatform 使用变形来复数 collectionOperations
上的 shortname
。
API-文档看起来像这样:
我也想添加一个人员列表。
所以我创建了另一个 Api-Resource:
/**
* @ApiResource(
* collectionOperations={
* "get"
* },
* itemOperations={}
* )
*
* @psalm-immutable
*/
final class Person
我的 customOperation
的 shortname
是 person
。这也是我希望我的 list
操作在文档中的组。
一切正常。 Person
和 CreatePerson
是两个 ApiResource
。
但现在我的文档看起来像这样:
我想在 API-Docs 中将它们组合在一起(因为它们属于一起)。
这里之所以多用一个CreatePerson
-DTO是因为我
使用Api-完全没有主义的平台。 DTO 通过 Messenger 进行调度,并通过事件溯源创建一个 Person。
Person
-class 是只读投影。
我的解决方案是使用 openapi_context
。
/**
* @ApiResource(
* messenger=true,
* output=false,
* collectionOperations={
* "post"={
* "method"="POST",
* "path"="/people",
* "openapi_context"={
* "tags"={
* "Person"
* },
* },
* },
* },
* itemOperations={},
* )
*
* @psalm-immutable
*/
final class CreatePerson
和Person
:
/**
* @ApiResource(
* collectionOperations={
* "get"
* },
* itemOperations={},
* )
* @ORM\Entity(repositoryClass="App\Repository\PersonRepository")
*
* @psalm-immutable
*/
final class Person
(此处显示:https://github.com/api-platform/docs/issues/143)
文档中的结果如下:
我有一个自定义操作 CreatePerson
,它是通过 messenger
调度的。
/**
* @ApiResource(
* messenger=true,
* output=false,
* shortName="person",
* collectionOperations={
* "post"
* },
* itemOperations={}
* )
*
* @psalm-immutable
*/
final class CreatePerson
这与 POST /api/people
的预期一样有效(people 而不是 person,因为 ApiPlatform 使用变形来复数 collectionOperations
上的 shortname
。
API-文档看起来像这样:
我也想添加一个人员列表。 所以我创建了另一个 Api-Resource:
/**
* @ApiResource(
* collectionOperations={
* "get"
* },
* itemOperations={}
* )
*
* @psalm-immutable
*/
final class Person
我的 customOperation
的 shortname
是 person
。这也是我希望我的 list
操作在文档中的组。
一切正常。 Person
和 CreatePerson
是两个 ApiResource
。
但现在我的文档看起来像这样:
我想在 API-Docs 中将它们组合在一起(因为它们属于一起)。
这里之所以多用一个CreatePerson
-DTO是因为我
使用Api-完全没有主义的平台。 DTO 通过 Messenger 进行调度,并通过事件溯源创建一个 Person。
Person
-class 是只读投影。
我的解决方案是使用 openapi_context
。
/**
* @ApiResource(
* messenger=true,
* output=false,
* collectionOperations={
* "post"={
* "method"="POST",
* "path"="/people",
* "openapi_context"={
* "tags"={
* "Person"
* },
* },
* },
* },
* itemOperations={},
* )
*
* @psalm-immutable
*/
final class CreatePerson
和Person
:
/**
* @ApiResource(
* collectionOperations={
* "get"
* },
* itemOperations={},
* )
* @ORM\Entity(repositoryClass="App\Repository\PersonRepository")
*
* @psalm-immutable
*/
final class Person
(此处显示:https://github.com/api-platform/docs/issues/143)
文档中的结果如下: