0

我正在使用 NelmioApiDocBundle 4.0 来生成我的 API 文档。当我尝试将响应类型设置为文件时,问题就开始了。我有一个从数据库中获取文件并将其作为 StreamedResponse 返回的方法:

return new StreamedResponse(function () use ($consent) {
                    fpassthru($consent);
                    exit();
                }, 200, [
                    'Content-Transfer-Encoding', 'binary',
                    'Content-Type' => 'application/pdf',
                    'Content-Disposition' => sprintf('attachment; filename="%s.pdf"', 'filename'),
                    'Content-Length' => fstat($consent)['size'],
                ]);

此代码运行良好并返回请求的文件,但我无法在文档中设置适当的响应类型。我试过这种方式,所以 mi 注释看起来像这样:

     * @OA\Response(
     *     response=200,
     *     description="My description",
     *     content="application/pdf",
     *     @OA\Schema(
     *      type="string",
     *      format="binary"
     *    )
     * )

但回应是:

Warning: Invalid argument supplied for foreach()

当我设置内容属性时,问题就开始了,但没有它, 这就是结果

4

1 回答 1

0

你需要把@OA\Schema里面@OA\MediaType

     * @OA\Response(
     *     response=200,
     *     description="My description",
     *     @OA\MediaType(
     *         mediaType="application/pdf",
     *         @OA\Schema(
     *            type="string",
     *            format="binary"
     *         )
     *     )
     * )
于 2021-01-15T13:19:09.667 回答