Swagger 打开api 3发布文件数组
我用招摇过市的枢纽;但是它不支持UI中的多文件,所以我不确定我是否做得对 我的目标是实现以下目标Swagger 打开api 3发布文件数组,swagger,openapi,Swagger,Openapi,我用招摇过市的枢纽;但是它不支持UI中的多文件,所以我不确定我是否做得对 我的目标是实现以下目标 item:{Json describe the item} images[] = images for item posted as an array titles[] = Parallel array to images that has the title for image alt_texts[] = Parallel array to images that has the alt text
item:{Json describe the item}
images[] = images for item posted as an array
titles[] = Parallel array to images that has the title for image
alt_texts[] = Parallel array to images that has the alt text for image
这必须是多部分的,因为它是文件;但我不确定我是否正确设置了结构
招摇过市/开放API代码
post:
summary: Add a new item to the store
description: ''
operationId: addItem
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/NewItemWithImage'
description: Item object that needs to be added to the store
required: true
NewItemWithImage:
type: object
properties:
item:
$ref: '#/components/schemas/NewItem'
images[]:
type: array
items:
type: string
format: binary
titles[]:
type: array
items:
type: string
alt_texts[]:
type: array
items:
type: string
variation_ids[]:
type: array
items:
type: string
required:
- item
根据OpenAPI 3规范中的章节:
文件上传
文件使用类型:string
模式和格式:binary
或格式:base64
,
取决于文件内容的编码方式
多文件上传
使用
多部分媒体类型,用于定义上载任意数量的文件
(文件数组):
requestBody:
内容:
多部分/表单数据:
模式:
类型:对象
特性:
文件名:
类型:数组
项目:
类型:字符串
格式:二进制
您当前的定义与规范完全对应:
requestBody:
内容:
应用程序/json:
模式:
$ref:“#/components/schemas/NewItemWithImageUrl”
多部分/表单数据:
模式:
$ref:“#/components/schemas/NewItemWithImage”
NewItemWithImage:
类型:对象
特性:
项目:
$ref:“#/components/schemas/NewItem”
图像[]:
类型:数组
项目:
类型:字符串
格式:二进制
标题[]:
类型:数组
项目:
类型:字符串
...
到今天为止,curlify.js中的swagger ui代码正在失败
if (v instanceof win.File) {
curlified.push( `"${k}=@${v.name}${v.type ? `;type=${v.type}` : ""}"` )
} else {
curlified.push( `"${k}=${v}"` )
}
curlify.js未考虑数组,正在发送:
curl-X POST”http://localhost:9122/upload-所有“-H”接受:*/*“-H”内容类型:多部分/表格数据“-F”我的附件=[对象文件],[对象文件]”
而不是像:
curl-X POST”https://foo/v1/api/upload/“-H”accept:application/json“-H”Content Type:multipart/form data“-F”myfile=@bla;Type=application/zip“-F”myfile=@foo;Type=application/zip”
尝试对字段使用Type:file
。看到这里,我在这个链接上问了一个问题——真正的问题是由swagger js库引起的,它没有检查它们的值是否是像文件一样更复杂的类型。所以curlify的curl函数甚至没有得到数组,而是已经得到了字符串化的参数。