在OpenAPI/Swagger文件中声明日期的正确方法是什么? [英] What is the correct way to declare a date in an OpenAPI / Swagger-file?

查看:777
本文介绍了在OpenAPI/Swagger文件中声明日期的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在swagger文件对象中声明日期的正确方法是什么?我认为是这样:

What is the correct way to declare a date in a swagger-file object? I would think it is:

  startDate:
    type: string
    description: Start date
    example: "2017-01-01"
    format: date

但是我看到很多这样的声明:

But I see a lot of declarations like these:

  startDate:
    type: string
    description: Start date
    example: "2017-01-01"
    format: date
    pattern: "YYYY-MM-DD"
    minLength: 0
    maxLength: 10

谢谢.

推荐答案

要使用的模式在 RFC 3339第5.6节中定义. br> 因此,对于date,该值应类似于"2018-03-20",对于date-time,其值应类似于"2018-03-20T09:12:28Z".

The pattern to use is defined in RFC 3339, section 5.6.
So for date the value should look like "2018-03-20" and for date-time "2018-03-20T09:12:28Z".

我不知道为什么人们要明确指定pattern,因为它是在format定义中隐式定义的.

I don't know why people specify the pattern explicitly because it is implicitly defined in the format definition.

这篇关于在OpenAPI/Swagger文件中声明日期的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆