在 swagger 文件对象中声明日期的正确方法是什么?我认为是:
startDate:
type: string
description: Start date
example: "2017-01-01"
format: date
但我看到很多这样的声明:
startDate:
type: string
description: Start date
example: "2017-01-01"
format: date
pattern: "YYYY-MM-DD"
minLength: 0
maxLength: 10
The 开放API规范 https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#data-types说你必须使用:
type: string
format: date # or date-time
OpenAPI 使用的互联网日期/时间标准定义在RFC 3339,第 5.6 节 https://www.rfc-editor.org/rfc/rfc3339#section-5.6(实际上是 ISO 8601),第 5.8 节提供了示例。因此对于date
值应类似于“2018-03-20”并且date-time
,“2018-03-20T09:12:28Z”。因此,当使用date
or date-time
, the pattern
应省略。
如果您需要支持以不同于 RFC 3339 的方式格式化的日期/时间,您可以not允许将您的参数指定为format: date
or format: date-time
。相反,您应该指定type: string
具有适当的pattern
并删除format
.
最后,请注意一个pattern
of "YYYY-MM-DD"
根据规范无效:pattern
必须是一个正则表达式,不是占位符或格式字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)