简体   繁体   中英

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 ?

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 . Which means they will be in the form

  • P1D for a one day duration
  • P1Y2D for a one year and two days duration

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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