我在swagger.yaml
:
User:
type: object
properties:
username:
type: string
description: the user name
colors:
type: array
items: {
type: string,
enum: [ "red", "blue", "green" ]
}
description: user must have one or more colors associated
required:
- username
- colors
但是,生成的服务器仍然很乐意接受使用此架构对象的POST请求作为不包含任何colors
字段的必需body参数。
我是否可以在color
架构对象中始终需要User
字段的方式配置Swagger,理想情况下还必须包含枚举中的至少一个或多个项目?
答案 0 :(得分:13)
使用minItems: 1
。此外,您可以在阵列中强制执行uniqueItems
。
colors:
type: array
minItems: 1
uniqueItems: true
items:
type: string
enum: [ "red", "blue", "green" ]