Spi*_*ral 2 laravel swagger-php
我想在 json requestBody 中的 swagger-php 中上传一个文件如何在 swagger anonations 的帮助下上传
从很多小时开始尝试但不走运如何在应用程序/ json数组中发送和文件,如果有关于此的任何信息,您能否提供帮助,那么我将解决我的问题我对此没有概念
当此代码在终端中生成时也没有任何错误并且未显示在 swagger ui 的请求正文中
/**
* @OA\Post(
* path="/products/save",
* tags={"Product"},
* summary="Post bulk products",
* description="Return bulk products",
* @OA\RequestBody(
* required=true,
* description="Bulk products Body",
* @OA\JsonContent(
* @OA\Property(
* property="products",
* @OA\Items(
* @OA\Property(property="first_name", type="string"),
* @OA\Property(property="last_name", type="string"),
* @OA\Property(property="email", type="string"),
* @OA\Property(property="phone", type="string"),
* @OA\Property(property="resume", type="string", format="base64"),
* ),
* )
* )
* ),
* )
*/
Run Code Online (Sandbox Code Playgroud)
我想要这种类型的 swagger-ui 正文,以便用户可以填写属性并以 base64 格式添加简历
{
"products": [
{
"first_name": "string",
"last_name": "string",
"email": "string",
"phone": "string",
"resume": "string" ==> here i will send base64 format of resume file
}
]
}
``
Run Code Online (Sandbox Code Playgroud)
您可以@OA\Property(property="file", type="string", format="binary"),用来定义文件属性:
/**
* @OA\Schema(
* schema="ProductRequest",
* required={"products"},
* @OA\Property(
* property="products",
* type="array",
* @OA\Items(
* @OA\Property(property="first_name", type="string"),
* @OA\Property(property="last_name", type="string"),
* @OA\Property(property="email", type="string"),
* @OA\Property(property="phone", type="string"),
* @OA\Property(property="resume", type="string", format="binary"),
* ),
* )
* )
*/
Run Code Online (Sandbox Code Playgroud)
然后,您必须在RequestBodyusing上设置媒体类型@OA\MediaType:
/**
* @OA\RequestBody(
* request="Product",
* required=true,
* description="Bulk products Body",
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(ref="#/components/schemas/ProductRequest")
* )
* )
*/
Run Code Online (Sandbox Code Playgroud)
最后在你的@OA\Post:
/**
* @OA\Post(
* path="/products/save",
* tags={"Product"},
* summary="Post bulk products",
* description="Return bulk products",
* @OA\RequestBody(ref="#/components/requestBodies/Product"),
* @OA\Response(response=200, ref="#/components/responses/Product")
* )
*/
Run Code Online (Sandbox Code Playgroud)
另请参阅有关文件数据类型和文件上传的Swagger 文档了解更多信息。
更新:如果您不想单独声明,只需像这样合并它们:
/**
* @OA\Post(
* path="/products/save",
* tags={"Product"},
* summary="Post bulk products",
* description="Return bulk products",
* @OA\RequestBody(
* required=true,
* description="Bulk products Body",
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(
* property="products",
* type="array",
* @OA\Items(
* @OA\Property(property="first_name", type="string"),
* @OA\Property(property="last_name", type="string"),
* @OA\Property(property="email", type="string"),
* @OA\Property(property="phone", type="string"),
* @OA\Property(property="resume", type="string", format="binary"),
* )
* )
* )
* )
* )
* )
*/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2272 次 |
| 最近记录: |