我正在使用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'],
]);这段代码运行良好,并返回所请求的文件,但我无法在文档中设置适当的响应类型。我尝试了这边请,所以我的注释如下所示:
* @OA\Response(
* response=200,
* description="My description",
* content="application/pdf",
* @OA\Schema(
* type="string",
* format="binary"
* )
* )但答复是:
Warning: Invalid argument supplied for foreach()当我设置content属性时,问题就开始了,但是没有它,这就是结果
发布于 2021-01-15 13:19:09
你需要把@OA\Schema放在@OA\MediaType里面
* @OA\Response(
* response=200,
* description="My description",
* @OA\MediaType(
* mediaType="application/pdf",
* @OA\Schema(
* type="string",
* format="binary"
* )
* )
* )https://stackoverflow.com/questions/65729835
复制相似问题