5

I have a project with Hybris and we are providing a restful API throught swagger + swagger-ui. We have a problem with the format of the date-time attributes and params. It is shown with this format: "2018-06-22T08:00:19.130Z".

However, the format that we use and need to shown in the examples provided in the swagger-ui is "2018-06-22T08:00:19Z".

The params are DTO's autogenerated by spring.

Any idea on how to change the format of the date-time for the examples?

Thanks, Cris

crigore
  • 400
  • 5
  • 23

1 Answers1

3

This is highly dependent on what version of swagger-ui you have, the examples were not always supported, so my example below is assuming you are on the latest and greatest (if not you should consider upgrading).

If you need to show it in a query parameter you need to set the value in the default:

      "parameters": [
      {
        "name": "data.d1",
        "in": "query",
        "required": false,
        "type": "string",
        "format": "date-time",
        "default": "2018-06-22T08:00:19Z",
      }

And for definitions is just example:

"definitions": {
 "Data": {
  "properties": {
    "date0": {
      "example": "2018-06-22T08:00:19Z",
      "type": "string",
      "format": "date-time"
    }

Here is how something like that will look like

enter image description here Here is the link to the live version:
http://petstore.swagger.io/?url=https://raw.githack.com/heldersepu/hs-scripts/master/swagger/swagger_51019812.json#/ApiExplorer/ApiExplorer_Get

Helder Sepulveda
  • 15,500
  • 4
  • 29
  • 56