首页 > 解决方案 > 加载 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 文档。

标签: symfonyapi-platform.comsymfony5

解决方案


你有启用树枝捆绑吗

// 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

这解决了我的问题


推荐阅读