Authress-Engineering / openapi-explorer

OpenAPI Web component to generate a UI from the spec.
Apache License 2.0
316 stars 42 forks source link

Query parameter form + explode does not explode for objects #262

Closed adam-homeboost closed 2 months ago

adam-homeboost commented 2 months ago

I may be misreading the OpenAPI spec, but I believe the following to be true:

According to the Openapi 3 spec, an in:query parameter that has:

=> This should result in a query string spec build from the properties of the schema object.

The explorer treats this as a text blob input instead of making parameters from each property. There are other "style" values that I believe allow for a blob entry but form + explode should be treated differently (also form + not-explode).

There is a large matrix of possibilities for these two fields). See: https://swagger.io/specification/#style-examples

So, for example, this schema should yield an endpoint that looks like .../some_path?var1=some_value&var2=123 (notice the name "params" does not appear):

{
    "openapi": "3.1.0",
    "info": {
        "title": "Some API",
        "version": "0.1.0"
    },
    "paths": {
        "/some_path": {
            "get": {
                "parameters": [
                    {
                        "name": "params",
                        "in": "query",
                        "style": "form",
                        "explode": true,
                        "schema": {
                            "type": "object",
                            "properties": {
                                "var1": {
                                    "type": "string",
                                    "description": "Something about var1"
                                },
                                "var2": {
                                    "type": "integer",
                                    "minimum": 10,
                                    "maximum": 100
                                }
                            },
                            "required": ["var1"]
                        }
                    }
                ]
            }
        }
    }
}

This should also work for $ref schemas such as:

{
    "openapi": "3.1.0",
    "info": {
        "title": "Some API",
        "version": "0.1.0"
    },
    "paths": {
        "/some_path": {
            "get": {
                "parameters": [
                    {
                        "name": "params",
                        "in": "query",
                        "style": "form",
                        "explode": true,
                        "schema": {
                           "$ref": "#/components/some/obj"
                        }
                    }
                ]
            }
        }
    },
   "components": {
      ...
   }
}

However, instead of rendering the individual properties as query parameters, the explorer shows this:

image

Note also that style=form and explode=true appear to be the defaults when not specified explicitly.

There are multiple other values for "style" and a table of combinations of style + explode and what that is supposed to mean for the query string formatting. I won't pretend to understand them all. but I would like to see if we can at least support the "form" style.

wparad commented 2 months ago

Thank you for reporting this. This is now fixed in 2.2.728 If you find any additional problems, feel free to open another issue.