Reputation: 60
Using OpenAPI 3.0, I need to document how to provide an RFC3339 Date Time JSON input with an HTTP POST to my API endpoint.
The example date-time format will look like this:
"2021-06-20T01:02:03+00:00"
Consulting the Swagger documentation I have tried various methods including the following:
content:
application/json:
schema:
type: object
properties:
datetime:
type: date
pattern: /([0-9]{4})-(?:[0-9]{2})-([0-9]{2})T([0-9]{2}):(?:[0-9]{2}):(?:[0-9]{2})+(?:[0-9]{2}):(?:[0-9]{2})/
example: "2021-06-20T01:02:03+00:00"
example: "2021-06-20T01:02:03+00:00"
content:
application/json:
schema:
type: object
properties:
datetime:
type: string
description: RFC3339 Datetime to set
format: date-time
example: "2021-06-20T01:02:03+00:00"
Neither work - an both render the following errors in Swagger UI from the browser:
How do I correctly document this RFC3339 DateTime input in OpenAPI 3.0?
Upvotes: 1
Views: 9240
Reputation: 98082
Your second example is correct and is rendered correctly in https://editor.swagger.io - as shown below.
The first example is invalid, it results in a rendering error because the second example
keyword (the one alongside datetime
) is not expected at this position.
Upvotes: 3