我有一个要求,即请求以 YYYYMMDD 格式传递日期。根据 swagger 文档,在字符串类型下定义的日期归档。但是,它遵循 RFC 3339 第 5.6 节,文档(例如 2018-03-20 作为格式(
下面的代码不适用于 yaml。
dateOfBirth:
type: string
minLength: 8
maxLength: 8
format: date
example: 19000101
description: Birth date of the member in YYYYMMDD format.
如何为 YYYYMMDD 的日期格式定义 YAML 定义。
根据类型字符串的文档,您可以添加正则表达式模式来定义日期格式 YYYYMMDD :
模式: '^\d{4}(0[1-9]|1[012]((0[1-9]|[12][0-9]|3[01]($'
另外,我建议您使用类似20190317之类的日期更新示例日期格式,以便轻松理解预期的日期格式。
definitions:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
dateOfBirth:
type: string
minLength: 8
maxLength: 8
format: date
pattern: '^d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$'
example: 20190816
description: Birth date of the member in YYYYMMDD format.