我正在使用swagger hub来create this API;但它不支持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 for image
这必须是多部分,因为它是文件;但我不确定我是否正确设置了结构。
Swagger / Open 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
答案 0 :(得分:1)
根据OpenAPI 3规范中的File Upload部分:
文件上传
文件使用
spring.security.user.roles
架构与type: string
或format: binary
, 取决于文件内容的编码方式。
多个文件上传
使用 多部分媒体类型,用于定义上传任意数量的文件 (文件数组):
format: base64
您当前的定义与规范完全对应:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
filename:
type: array
items:
type: string
format: binary
答案 1 :(得分:0)
swagger-ui的代码到今天为止在curlify.js中失败
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-all" -H "accept: */*" -H "Content-Type: multipart/form-data" -F "my-attachment=[object File],[object File]"
而不是类似的东西
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"