Skip to content

Swagger UI is generating incorrect Example Value for a nullable property in openapi 3.1.1 #10388

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 Mar 28, 2025 · 2 comments · Fixed by #10390
Closed

Comments

@ctyar
Copy link
Contributor

ctyar commented Mar 28, 2025

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

{
  "openapi": "3.1.1",
  "info": {
    "title": "Playground | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5150"
    }
  ],
  "paths": {
    "/todos": {
      "post": {
        "tags": [
          "TodoEndpoints"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TodoRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "NullableOfPriority": {
        "enum": [
          "Low",
          "Medium",
          "High",
          "Critical",
          null
        ]
      },
      "TodoRequest": {
        "required": [
          "description",
          "priority"
        ],
        "type": "object",
        "properties": {
          "description": {
            "type": [
              "null",
              "string"
            ]
          },
          "dueDate": {
            "type": [
              "null",
              "string"
            ],
            "format": "date-time"
          },
          "priority": {
            "$ref": "#/components/schemas/NullableOfPriority"
          },
          "tags": {
            "type": [
              "null",
              "array"
            ],
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "TodoEndpoints"
    }
  ]
}

Describe the bug you're encountering

Swagger UI produces nulls for Description and DueDate properties in the Example Value section:

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 following for the example value:

Image

Additional context or thoughts

In the specification above, if we change the order of members in the type array from:

"description": {
            "type": [
              "null",
              "string"
            ]
          },

To:

"description": {
            "type": [
              "string",
              "null"
            ]
          },

Swagger UI will produce the correct example value.

@glowcloud
Copy link
Contributor

Addressed in #10390.

@glowcloud
Copy link
Contributor

Released as https://github.com/swagger-api/swagger-ui/releases/tag/v5.20.4

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