Skip to content

Swagger UI is not producing correct example for a string with time format #10420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ctyar opened this issue Apr 18, 2025 · 2 comments · Fixed by #10421
Closed

Swagger UI is not producing correct example for a string with time format #10420

ctyar opened this issue Apr 18, 2025 · 2 comments · Fixed by #10421

Comments

@ctyar
Copy link
Contributor

ctyar commented Apr 18, 2025

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Mvc | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5125/"
    }
  ],
  "paths": {
    "/WeatherForecast": {
      "get": {
        "tags": [
          "WeatherForecast"
        ],
        "operationId": "GetWeatherForecast",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WeatherForecast"
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WeatherForecast"
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WeatherForecast"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "WeatherForecast": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "time": {
            "type": "string",
            "format": "time"
          },
          "duration": {
            "pattern": "^-?(\\d+\\.)?\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,7})?$",
            "type": "string"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "WeatherForecast"
    }
  ]
}

Describe the bug you're encountering

As you can see in the screenshot, Swagger UI is not producing an example for the time property, which is a string with format set to time:

Image

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io/
  2. Import the OpenAPI specification above
  3. Check the Example Value

Expected behavior

The current time as the example value

@ctyar
Copy link
Contributor Author

ctyar commented Apr 19, 2025

On second thought the https://spec.openapis.org/oas/v3.0.4.html#data-type-format doesn't mention time, is this why this format is not supported?

@char0n
Copy link
Member

char0n commented May 26, 2025

Hi @ctyar,

yes, that's right. The time format is not part of core OpenAPI 3.0.x spec, but it's now part of Official format registry, and supported by OpenAPI 3.1.x out of the box. It's good to have it in OpenAPI 3.0.x as well.

Thank you for the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants