gpt4 book ai didi

java - 如何在 Swagger Open API 3.0 规范中定义电子邮件格式?

转载 作者:行者123 更新时间:2023-12-05 03:51:06 25 4
gpt4 key购买 nike

在我 Swagger 的 Open API 文档中,我给出了如下的对象定义:

"definitions": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},

"firstName": {
"type": "string"
},

"email": {
"type": "string"
},
"shipDate": {
"type": "string",
"format": "date-time"
},
"status": {
"type": "string",
"description": "Order Status",
"enum": [
"placed",
"approved",
"delivered"
]
}
}

我找不到电子邮件地址的格式,例如:

 "email": {
"type": "string",
"format" : "####"
}

我通过了官方Doc ,他们说:

Formats such as "email", "uuid", and so on, MAY be used even thoughundefined by this specification. Types that are not accompanied by aformat property follow the type definition in the JSON Schema.

我正在努力实现这一目标,有什么提示可以实现吗?

最佳答案

您可以使用正则表达式 pattern 来限制可接受的电子邮件域。例如,如果电子邮件必须以 .io 结尾,您可以使用 \.[Ii][Oo]$ 模式:

"email": {
"type": "string",
"format": "email",
"pattern": "\\.[Ii][Oo]$"
}

请注意,字符串中的 \ 字符被转义为 \\

关于java - 如何在 Swagger Open API 3.0 规范中定义电子邮件格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63191398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com