使用API​​ Platform捆绑包的自定义Symfony Action [英] Custom Symfony Action with API Platform bundle

查看:54
本文介绍了使用API​​ Platform捆绑包的自定义Symfony Action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用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)文档以添加自定义端点或其他任何内容:

Anyway, you can always customize the Swagger (and Hydra) docs to add custom endpoints or anything else: https://github.com/api-platform/docs/blob/master/core/swagger.md#override-swagger-documentation (this documentation will be available on the website soon).

这篇关于使用API​​ Platform捆绑包的自定义Symfony Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆