我正在尝试通过multipart/form-data
发送一个对象数组
post:
summary: Creates a user
requestBody:
content:
multipart/form-data:
schema:
type: object
properties: # Request parts
id:
type: string
format: uuid
address: # <---------
type: array
items:
type: object
properties:
street:
type: string
city:
type: string
profileImage:
type: string
format: base64
但是Swagger UI错误地发送了address
数组-作为{},{}
而不是[{},{}]
,也就是说,没有包括方括号:
我甚至尝试将其单独编码为JSON。
请问我漏掉了什么?
发布于 2021-09-17 22:00:23
后来,我通过添加示例使其正常工作
post:
summary: Creates a user
requestBody:
content:
multipart/form-data:
schema:
type: object
properties: # Request parts
id:
type: string
format: uuid
address:
type: array
items:
type: object
properties:
street:
type: string
city:
type: string
example:
- street: Jones Street, Manhattan
city: New York
- street: Hollywood Boulevard
city: Los Angeles
profileImage:
type: string
format: base64
我的观察是,只是发送或修改示例中已有的内容,添加新的内容将不会正确格式化。也就是说,如果数组中有两个项,请不要添加额外项
https://stackoverflow.com/questions/69054643
复制相似问题