Skip to content

Broken _get_kwargs code generated with JSON body type string #487

Closed
@Gelbpunkt

Description

@Gelbpunkt

Describe the bug
With a route definition that sets the content type to application/json but the schema type to a string, the code generated references an invalid variable.

To Reproduce

  1. Add a route definition like so:
        "/chat/web": {
            "parameters": [],
            "post": {
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "description": "Send a message to the chat",
                "responses": {
                    "204": {
                        "description": "Message sent"
                    } 
                },
                "requestBody": {
                    "description": "The text to send",
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
  1. Run openapi-python-client update ...
  2. Open the python file at api/.../post_chat_web.py
  3. See _get_kwargs code
def _get_kwargs(
    *,
    client: AuthenticatedClient,
    json_body: str,
) -> Dict[str, Any]:
    url = "{}/chat/web".format(client.base_url)

    headers: Dict[str, Any] = client.get_headers()
    cookies: Dict[str, Any] = client.get_cookies()

    return {
        "url": url,
        "headers": headers,
        "cookies": cookies,
        "timeout": client.get_timeout(),
        "json": json_json_body,
    }

Expected behavior
The code in post_chat_web.py should reference json_body and not json_json_body.

OpenAPI Spec File
https://raw.githubusercontent.com/Nadybot/Nadybot/unstable/html/api.json

Desktop (please complete the following information):

  • OS: Fedora 34
  • Python Version: 3.9.6
  • openapi-python-client version 0.10.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions