connexion icon indicating copy to clipboard operation
connexion copied to clipboard

Parameters at path and request level cause swagger UI to break

Open joshsmoore opened this issue 5 months ago • 1 comments

I found a bug that causes the incorrect openAPI schema to be sent to swagger UI when params are present at both path and request level. I have attached a sample project. But, will include details inline as well.

The API schema is :

openapi: "3.0.0"
info:
  title: Greeting application
  version: 0.0.1
paths:
  /greeting/{name}:
    parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
    get:
      operationId: run.post_greeting
      parameters:
        - name: last_name
          in: query
          required: true
          schema:
            type: string
      responses:
        '200':
          description: "Greeting response"
          content:
            text/plain:
              schema:
                type: string

When connexion loads the schema is (which is correct):

{
    "openapi": "3.0.0",
    "info": {
        "title": "Greeting application",
        "version": "0.0.1"
    },
    "paths": {
        "/greeting/{name}": {
            "parameters": [
                {
                    "name": "name",
                    "in": "path",
                    "required": True,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "get": {
                "operationId": "run.post_greeting",
                "parameters": [
                    {
                        "name": "last_name",
                        "in": "query",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Greeting response",
                        "content": {
                            "text/plain": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {}
}

This is printed from Specification __init__ method raw_spec

This is the schema that is passed to Specification __init__ method raw_spec when I load the swagger UI

{
    "openapi": "3.0.0",
    "info": {
        "title": "Greeting application",
        "version": "0.0.1"
    },
    "paths": {
        "/greeting/{name}": {
            "parameters": [
                {
                    "name": "name",
                    "in": "path",
                    "required": True,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "get": {
                "operationId": "run.post_greeting",
                "parameters": [
                    {
                        "name": "last_name",
                        "in": "query",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "name",
                        "in": "path",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "name",
                        "in": "path",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "name",
                        "in": "path",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "name",
                        "in": "path",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "name",
                        "in": "path",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "name",
                        "in": "path",
                        "required": True,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Greeting response",
                        "content": {
                            "text/plain": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {}
}

If I remove the path level parameters from the schema (see below) then this problem goes away.

openapi: "3.0.0"
info:
  title: Greeting application
  version: 0.0.1
paths:
  /greeting/{name}:
    get:
      operationId: run.post_greeting
      parameters:
        - name: last_name
          in: query
          required: true
          schema:
            type: string
      responses:
        '200':
          description: "Greeting response"
          content:
            text/plain:
              schema:
                type: string

Reproduce.

1. Unzip the files
2. poetry install
3. poetry run uvicorn run:app
4. visit http://127.0.0.1:8000/ui/

conn_test.zip

joshsmoore avatar Aug 05 '25 18:08 joshsmoore

This behavior sounds very similar to issues #2046 and #2028, please comment.

chrisinmtown avatar Aug 05 '25 20:08 chrisinmtown