【发布时间】:2021-04-20 02:42:46
【问题描述】:
我正在使用 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'],
]);
此代码运行良好并返回请求的文件,但我无法在文档中设置适当的响应类型。 我试过this way,所以mi注解是这样的:
* @OA\Response(
* response=200,
* description="My description",
* content="application/pdf",
* @OA\Schema(
* type="string",
* format="binary"
* )
* )
但响应是:
Warning: Invalid argument supplied for foreach()
问题从我设置 content 属性开始,但没有它 this is the result
【问题讨论】:
-
看起来您需要将
@OA\Schema放入@OA\MediaType- 请参阅this example。这行得通吗? -
我试过了,它成功了,谢谢,把你的评论作为回复,所以我可以像正确答案一样接受它
标签: symfony swagger php-7 symfony5 nelmioapidocbundle