我尝试使用Symfony捆绑包 API平台来构建API.
I try to build an API with the Symfony bundle API-Platform.
Api资源使用HTTP动词POST,GET,PUT,DELETE提供自动CRUD操作.
Api resource offer automatic CRUD action with the HTTP verbs POST, GET, PUT, DELETE.
我想要添加一个端点来处理自定义POST操作,并具有自定义的有效负载/主体,而不依赖于任何资源.
What I want is adding an endpoint to handle a custom POST action, with a custom payload/body, not depending on any resource.
我要阻止的是将此端点添加到自动API平台文档中.
Where I block it is to add this endpoint to the automatic API-Platform documentation.
在GitHub上寻找此类问题时,我发现API平台v2应该可以做到.
When looking for this kind of issue on GitHub, I found that the API-Platform v2 should be able to do it.
请参见> 问题#385:自定义操作+ ApiDoc
See Issue #385 : Custom action + ApiDoc
似乎有些人找到了使用NelmioApiDoc @ApiDoc批注的方法.
It looks like some people find the way to use NelmioApiDoc @ApiDoc annotation.
请参见> 问题#17:用于自定义的文档操作
See Issue #17 : Documentation for custom operation
推荐答案使用 @ApiDoc 注释是不可行的,将在API Platform 3中删除对NelmioApiDoc的支持,而采用内置的Swagger/Hydra支持.
Using the @ApiDoc annotation is a no go, support for NelmioApiDoc will be removed in API Platform 3 in favor of the builtin Swagger/Hydra support.
如果您使用自定义API平台操作,则该操作应自动记录在案Swagger和Hydra文档中.
If you use a custom API Platform action, the action should automatically be documented in Swagger and Hydra docs.
无论如何,您始终可以自定义Swagger(和Hydra)文档以添加自定义端点或其他任何内容: github/api-platform/docs/blob/master/core/swagger.md#override-swagger-documentation (该文档将很快在网站上提供.
Anyway, you can always customize the Swagger (and Hydra) docs to add custom endpoints or anything else: github/api-platform/docs/blob/master/core/swagger.md#override-swagger-documentation (this documentation will be available on the website soon).
更多推荐
使用API Platform捆绑包的自定义Symfony Action
发布评论