swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

GET parameters not exploded when `"in": "query","style": "form","explode": true` and the request can be `oneOf` a few different objects

Open JohnRDOrazio opened this issue 8 months ago • 1 comments

Q&A (please complete the following information)

  • OS: Ubuntu 20.04
  • Browser: Chrome
  • Version: 125.0.6422.113
  • Method of installation: dist assets
  • Swagger-UI version: 5.17.14
  • Swagger/OpenAPI version: OpenAPI 3.1

Content & configuration

Example Swagger/OpenAPI definition:

{
  "openapi": "3.1.0",
  "servers": [
    {
      "description": "Petstore Swagger API",
      "url": "https://petstore.swagger.io/v2"
    }
  ],
  "info": {
    "description": "This is a sample Petstore API.",
    "version": "1.0",
    "title": "Petstore",
    "contact": {
      "email": "[email protected]",
      "name": "Swagger API Team"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "paths": {
    "/petsearch": {
      "get": {
        "tags": ["pet"],
        "security": [{}],
        "summary": "Everything about your Pets",
        "operationId": "retrievePetGET",
        "description": "Returns a list of available pets that fit your desires",
        "parameters": [
          {
            "in": "query",
            "name": "parameters",
            "style": "form",
            "explode": true,
            "schema": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/RequestBody"
                }
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK: available pets that correspond with your criteria",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pets"
                }
              },
              "application/yaml": {
                "schema": {
                  "$ref": "#/components/schemas/Pets"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "RequestBody": {
        "type": "object",
        "title": "Pet Search Request",
        "description": "Search for a pet that correponds to certain criteria",
        "additionalProperties": false,
        "properties": {
          "animal": {
            "type": "string",
            "enum": ["dog", "cat", "bird"]
          },
          "color": {
            "type": "string",
            "enum": ["black", "white", "multicolored"]
          }
        },
        "required": ["animal"]
      },
      "Pets": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "animal": {
              "type": "string",
              "enum": ["cat", "dog", "bird"]
            },
            "color": {
              "type": "string",
              "enum": ["black", "white", "multicolored"]
            }
          }
        }
      }
    }
  }
}

Swagger-UI configuration options:

const ui = SwaggerUIBundle({
  url: "openapi.json",
  dom_id: "#swagger-ui",
  deepLinking: true,
  requestSnippetsEnabled: true,
  requestSnippets: {
    generators: {
      curl_bash: {
        title: "cURL (bash)",
        syntax: "bash",
        default: true,
      },
      curl_powershell: {
        title: "cURL (PowerShell)",
        syntax: "powershell",
      },
      curl_cmd: {
        title: "cURL (CMD)",
        syntax: "bash",
      },
    },
    defaultExpanded: true,
    languages: ["curl_bash", "curl_powershell", "curl_cmd"],
  },
  presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
  plugins: [SwaggerUIBundle.plugins.DownloadUrl],
  layout: "StandaloneLayout",
});
?animal=dog&color=black

Describe the bug you're encountering

The parameters are expanded just fine if there is only one possible request object. But if you have more than one "type" of request that can be formulated, and you express this with a oneOf, the parameters are no longer expanded / exploded. The whole object is simply serialized as the value of the named parameter. Even if there is only a single object inside the oneOf the exploding still gets messed up.

To reproduce...

Here's a live example on codesandbox.

Steps to reproduce the behavior in the live example on codesandbox:

  1. Expand the GET operation in right preview panel
  2. Click on Try it out
  3. Click on Execute
  4. In the request snippets you will see that the parameters are not exploded but simply serialized as a single object

Expected behavior

The parameters should be exploded / expanded even when there are multiple "types" to choose from that are defined in an anyOf.

Screenshots

image

JohnRDOrazio avatar Jun 06 '24 01:06 JohnRDOrazio