我正在使用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发布于 2018-03-31 16:04:23
根据OpenAPI 3规范中的File Upload部分:
文件上传
文件使用带有
format: binary或format: base64的type: string架构,具体取决于文件内容的编码方式。
多文件上传
使用multipart媒体类型来定义上传任意数量的文件(文件数组):
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
filename:
type: array
items:
type: string
format: binary您当前的定义完全符合规范:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/NewItemWithImageUrl'
multipart/form-data:
schema:
$ref: '#/components/schemas/NewItemWithImage'
NewItemWithImage:
type: object
properties:
item:
$ref: '#/components/schemas/NewItem'
images[]:
type: array
items:
type: string
format: binary
titles[]:
type: array
items:
type: string
...发布于 2019-01-29 06:37:48
到目前为止,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"
https://stackoverflow.com/questions/49433984
复制相似问题