Riduidel
Riduidel

Reputation: 22292

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

Upvotes: 3

Views: 2215

Answers (1)

Riduidel
Riduidel

Reputation: 22292

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.

Upvotes: 2

Related Questions