Swagger.php : 如何更改 POST 请求 header Content-type
Swagger.php : how to change POST request header Content-type
我使用的库:darkaonline/l5-swagger (^5.5)(其中包含swagger-php + swagger-ui),我需要在我的[=38=中更改header Content-Type ] 请求上传文件(在 Laravel Input::file('photo') 中阅读)。我读到我应该在 swagger 中添加 consumes
和 produces
参数 - 这就是我所拥有的:
/**
*
* Create Building Photo
*
* @SWG\Post(
* path="/api/v1/buildings/{buildingId}/photo",
* security={{"oauth2": {"*"}}},
* tags={"building"},
* consumes={"text/plain", "application/json"},
* produces={"text/plain", "application/json"},
* description="Update building",
* @SWG\Parameter(
* name="buildingId",
* in="path",
* description="Building id",
* required=true,
* type="number",
* ),
* @SWG\Parameter(
* name="photo",
* in="formData",
* required=true,
* description="Building photo",
* type="file",
* ),
* @SWG\Response( response=200, description="ok"),
* @SWG\Response( response=404, description="Building not found"),
* )
*
*/
但是在请求 Content-type
和 Accept
中我总是得到 application/json
并且 laravel 无法读取上传的文件(当我使用 swagger-ui 生成请求时).我应该如何改变上面的招摇,以允许 laravel 读取 Input::file('photo') 表单 POST 由 swagger-ui 生成的请求?
这是解决方案:
* consumes={"multipart/form-data"},
* produces={"text/plain, application/json"},
:)
请在此处找到解决方案。
您应该按照此指南在 Laravel 中使用 Passport 身份验证等设置 Swagger
https://github.com/DarkaOnLine/L5-Swagger
此处列出了您在实施过程中可能遇到的一些问题。
我使用的库:darkaonline/l5-swagger (^5.5)(其中包含swagger-php + swagger-ui),我需要在我的[=38=中更改header Content-Type ] 请求上传文件(在 Laravel Input::file('photo') 中阅读)。我读到我应该在 swagger 中添加 consumes
和 produces
参数 - 这就是我所拥有的:
/**
*
* Create Building Photo
*
* @SWG\Post(
* path="/api/v1/buildings/{buildingId}/photo",
* security={{"oauth2": {"*"}}},
* tags={"building"},
* consumes={"text/plain", "application/json"},
* produces={"text/plain", "application/json"},
* description="Update building",
* @SWG\Parameter(
* name="buildingId",
* in="path",
* description="Building id",
* required=true,
* type="number",
* ),
* @SWG\Parameter(
* name="photo",
* in="formData",
* required=true,
* description="Building photo",
* type="file",
* ),
* @SWG\Response( response=200, description="ok"),
* @SWG\Response( response=404, description="Building not found"),
* )
*
*/
但是在请求 Content-type
和 Accept
中我总是得到 application/json
并且 laravel 无法读取上传的文件(当我使用 swagger-ui 生成请求时).我应该如何改变上面的招摇,以允许 laravel 读取 Input::file('photo') 表单 POST 由 swagger-ui 生成的请求?
这是解决方案:
* consumes={"multipart/form-data"},
* produces={"text/plain, application/json"},
:)
请在此处找到解决方案。
您应该按照此指南在 Laravel 中使用 Passport 身份验证等设置 Swagger
https://github.com/DarkaOnLine/L5-Swagger
此处列出了您在实施过程中可能遇到的一些问题。