如何在OpenAPI 3.0中的对象中至少需要一个属性?
我有此OpenAPI架构:
components:
schemas:
User:
type: object
required:
- username
- email
- description
- profile_icon
properties:
username
type: string
email
type: string
format: email
description
type: string
profile_icon
type: string
所有属性都是必需的。这是put/user/profile
。
我将将其更改为补丁/用户/配置文件
。 用户仅发送参数仅要求更改。 系统验证至少需要一个参数。
我如何描述需要一个[用户名,电子邮件,描述,profile_icon]?
可接受的示例请求:
{
"username": "Will Smith"
}
{
"email": "[email protected]",
"profile_icon": "aaaaa.png"
}
不可接受的示例(错误):
{}
anyof
注释器已接近,但似乎仅适用于$ ref
schemas,而不是属性。
htttps://swagger.io/docs.io/docs/specification/data--data-------模型/单一单独/
I have this OpenAPI schema:
components:
schemas:
User:
type: object
required:
- username
- email
- description
- profile_icon
properties:
username
type: string
email
type: string
format: email
description
type: string
profile_icon
type: string
All of properties are required. This is for PUT /user/profile
.
I will change this to PATCH /user/profile
.
Users send parameters just they only request to change.
System validates that at least one parameter is required.
How can I describe one of [username, email, description, profile_icon] is required?
Acceptable example requests:
{
"username": "Will Smith"
}
{
"email": "[email protected]",
"profile_icon": "aaaaa.png"
}
Not acceptable example (error):
{}
The anyOf
annotator is close but it seems to be only for $ref
schemas, not properties.
https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在对象中至少需要1个属性的最简单方法是使用
minproperties:1
。The easiest way to require at least 1 property in an object is to use
minProperties: 1
.