使用API​​ Platform捆绑包的自定义Symfony Action

编程入门 行业动态 更新时间:2024-10-14 14:17:29
本文介绍了使用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)文档以添加自定义端点或其他任何内容: 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

本文发布于:2023-11-28 12:32:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   Platform   API   Symfony   Action

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!