简体   繁体   English

使用摇摇欲坠,如何定义持续时间参数?

[英]Using swagger, how can I define a duration parameter?

In one of the request I use, I want some attribute to be a moment duration. 在我使用的一项请求中,我希望某些属性是片刻持续时间。

How can I define that in Swagger descriptor ? 我如何在Swagger描述符中定义它?

As far as I understand, something like 据我了解,类似

type: string
format: iso8601

would be good. 会很好。 But is it the right way yo do ? 但这是正确的方法吗?

EDIT Durations will be expressed using ISO8601 durations . 编辑持续时间将使用ISO8601持续时间表示。 Which means they will be in the form 这意味着它们将采用以下形式

  • P1D for a one day duration P1D持续一天
  • P1Y2D for a one year and two days duration P1Y2D持续一年零两天

I chose the following solution 我选择了以下解决方案

 warrantyDuration:
   type: string
   format: iso8601
   description: Warranty duration expressed as an iso8601 duration. Typical values are P1Y, P2Y, ...
   example: P1Y

I use the string type as values are transferred as strings, and the iso8601 format, which is the parent format for dates and durations. 我使用string类型,因为值以string形式传输,以及iso8601格式,这是日期和持续时间的父格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM