Skip to content

Broken _get_kwargs code generated with JSON body type string #487

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

Closed
Gelbpunkt opened this issue Sep 5, 2021 · 2 comments · Fixed by #550
Closed

Broken _get_kwargs code generated with JSON body type string #487

Gelbpunkt opened this issue Sep 5, 2021 · 2 comments · Fixed by #550
Labels
🐞bug Something isn't working
Milestone

Comments

@Gelbpunkt
Copy link

Gelbpunkt commented Sep 5, 2021

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://github.com/raw/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
@dbanty
Copy link
Collaborator

dbanty commented Oct 12, 2021

Thanks for reporting this! Sorry for the delayed response, I'll add this into my list of bugs to reproduce & fix this weekend.

@dbanty dbanty added this to the 0.10.6 milestone Oct 12, 2021
@dbanty dbanty modified the milestones: 0.10.6, 0.10.7, 0.10.8 Oct 25, 2021
dbanty added a commit that referenced this issue Dec 18, 2021
@dbanty
Copy link
Collaborator

dbanty commented Dec 18, 2021

Sorry for the delays, I finally got around to fixing this in #550. Will be included in 0.10.8 release. Not the prettiest code ever but at least it functions now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants