Skip to content
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

Order of "null" in anyOf/oneOf array change the behaivor of produced docs #10225

Open
wallseat opened this issue Nov 26, 2024 · 1 comment
Open
Labels
P2 pull-request-welcome If a PR were to be made, we would help get it merged

Comments

@wallseat
Copy link

Q&A

  • OS: Any
  • Browser: Any
  • Method of installation: dist assets
  • Swagger-UI version: 3.18.2
  • Swagger/OpenAPI version: OpenAPI 3.1

Content & configuration

Order of "null" in "anyOf"/"oneOf" array change displaing info in SwaggerUI

This OAS (where null is the first element)

{
  "info": {
    "title": "Test API",
    "version": "0.0.1"
  },
  "openapi": "3.1.0",
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "summary": "Test",
        "operationId": "Test",
        "parameters": [
          {
            "name": "environment",
            "in": "query",
            "schema": {
              "anyOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/components/schemas/Environment"
                }
              ],
              "title": "Environment",
              "description": "The environment to filter by."
            },
            "description": "The environment to filter by.",
            "required": false,
            "deprecated": false,
            "allowEmptyValue": false,
            "allowReserved": false
          }
        ],
        "responses": {
          "200": {
            "description": "Request fulfilled, document follows",
            "headers": {
              
            },
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Environment"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad request syntax or unsupported method",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "status_code": {
                      "type": "integer"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "extra": {
                      "additionalProperties": {
                        
                      },
                      "type": [
                        "null",
                        "object",
                        "array"
                      ]
                    }
                  },
                  "type": "object",
                  "required": [
                    "detail",
                    "status_code"
                  ],
                  "description": "Validation Exception",
                  "examples": [
                    {
                      "status_code": 400,
                      "detail": "Bad Request",
                      "extra": {
                        
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "components": {
    "schemas": {
      "Environment": {
        "type": "string",
        "enum": [
          "dev",
          "test",
          "qa"
        ],
        "title": "Environment"
      }
    }
  }
}

Produce this generated UI:
image

This OAS (where null is the last):

{
  "info": {
    "title": "Test API",
    "version": "0.0.1"
  },
  "openapi": "3.1.0",
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "summary": "Test",
        "operationId": "Test",
        "parameters": [
          {
            "name": "environment",
            "in": "query",
            "schema": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/Environment"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Environment",
              "description": "The environment to filter by."
            },
            "description": "The environment to filter by.",
            "required": false,
            "deprecated": false,
            "allowEmptyValue": false,
            "allowReserved": false
          }
        ],
        "responses": {
          "200": {
            "description": "Request fulfilled, document follows",
            "headers": {
              
            },
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Environment"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad request syntax or unsupported method",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "status_code": {
                      "type": "integer"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "extra": {
                      "additionalProperties": {
                        
                      },
                      "type": [
                        "null",
                        "object",
                        "array"
                      ]
                    }
                  },
                  "type": "object",
                  "required": [
                    "detail",
                    "status_code"
                  ],
                  "description": "Validation Exception",
                  "examples": [
                    {
                      "status_code": 400,
                      "detail": "Bad Request",
                      "extra": {
                        
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "components": {
    "schemas": {
      "Environment": {
        "type": "string",
        "enum": [
          "dev",
          "test",
          "qa"
        ],
        "title": "Environment"
      }
    }
  }
}

Produce this:
image

Swagger-UI configuration options:

SwaggerUI(
 {
    url: 'XXX'
    dom_id: '#swagger-container',
    deepLinking: true,
    showExtensions: true,
    showCommonExtensions: true,
    presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIBundle.SwaggerUIStandalonePreset
    ],
 }
)
@ponelat ponelat added P2 pull-request-welcome If a PR were to be made, we would help get it merged labels Nov 29, 2024
@ponelat
Copy link
Member

ponelat commented Nov 29, 2024

This is (sorta) a feature request to support anyOf/oneOf inside of Try-It-Out for Parameters. I say sort-of, because without this we clearly can't use Try-it-out fully.
PRs would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 pull-request-welcome If a PR were to be made, we would help get it merged
Projects
None yet
Development

No branches or pull requests

2 participants