symfony - 加载 API 文档时,“不支持“html”格式的序列化”
问题描述
我创建了一个新的 Symfony 5.3 项目并安装了 API-Platform。当我加载 API Doc 时/api
,我收到一个错误:
Symfony\Component\Serializer\Exception\NotEncodableValueException :不支持“html”格式的序列化。
我尝试将html
格式添加到api_platform.yml
配置文件中:
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
patch_formats:
json: ['application/merge-patch+json']
formats:
json: ['application/json']
html: ['text/html']
swagger:
versions: [3]
我不知道如何访问 API 文档。
解决方案
你有启用树枝捆绑吗
// config/bundles.php
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
也许你没有在你的
// config/packages/api_platform.yaml
enable_swagger: true
enable_swagger_ui: true
enable_re_doc: true
enable_entrypoint: true
enable_docs: true
这解决了我的问题
推荐阅读
- visual-studio - 如何为我的 c++ 程序修复这个 Visual Studio 错误?
- scala - 在 IntelliJ 中导入库 sbt
- javascript - 为什么无法读取属性“classList”?
- angular - Angular 9 升级,SASS 无法构建 - gyp ERR!这是“node-gyp”中的一个错误
- javascript - Javascript 函数返回一个对象,但答案未定义
- java - 如何使用连续的用户输入更新输出,直到以“。”终止?
- javascript - RSA 在 JavaScript 中加密并在 PHP 中解密
- c# - 在 C# ASP.NET 中将 ODT 转换为 PDF 文件(并添加内容)
- javascript - Reactjs + Redux 未处理拒绝(TypeError):无法读取未定义的属性“数据”
- angular - 以角度渲染侧面导航时如何使按钮不可移动?