我正在使用 swagger hub 来创建这个 API;但它不支持用户界面中的多个文件,所以我不确定我这样做是否正确
我的目标是拥有以下
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
Run Code Online (Sandbox Code Playgroud)
由于它是文件,所以它必须是多部分的;但不确定我是否正确设置了结构。
Swagger/开放 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
Run Code Online (Sandbox Code Playgroud)
根据OpenAPI 3 规范中的文件上传部分:
上传文件
文件使用
type: string带有format: binary或 的架构format: base64,具体取决于文件内容的编码方式。
多个文件上传
使用多部分媒体类型定义上传任意数量的文件(文件数组):
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
filename:
type: array
items:
type: string
format: binary
Run Code Online (Sandbox Code Playgroud)
您当前的定义完全符合规范:
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
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6285 次 |
| 最近记录: |