我正在寻找一种优雅的方式来定义一个可以使用 JSON 数据以及表单数据的 api。以下代码段有效,但它并不优雅,并且需要在后端使用各种丑陋的代码。有没有更好的方法来定义这个?
现在有效的方法:
paths:
/pets:
post:
consumes:
- application/x-www-form-urlencoded
- application/json
parameters:
- name: nameFormData
in: formData
description: Updated name of the pet
required: false
type: string
- name: nameJSON
in: body
description: Updated name of the pet
required: false
type: string
我希望它如何工作的基本想法:
paths:
/pets:
post:
consumes:
- application/x-www-form-urlencoded
- application/json
parameters:
- name: name
in:
- formData
- body
description: Updated name of the pet
required: true
type: string
但这不起作用,因为in
值必须是字符串,而不是数组。
有什么好主意吗?