openapi-generators / openapi-generators/openapi-python-client

TypeError when model default value is a list

Open
#721 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐞bug
Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Description

Describe the bug
When generating models for an API where a default argument is a list of enums, a TypeError is raised on this line:

return f"{prop.class_info.name}.{inverse_values[default]}"

A possible fix could be to explicitly check for this case. Below is a proposed fix, but I'm not familiar enough with the codebase to know whether this is a correct fix. However, I was able to parse the API docs correctly with this fix in place:

if type(default) is list:
    return [f"prop.class_info.name.inverse_values[d]" for d in default]
else:
    return f"{prop.class_info.name}.{inverse_values[default]}"

To Reproduce
Steps to reproduce the behavior:

  1. Run openapi-python-client generate --url https://sand-docs.ilevelsolutions.eu/openapi.yaml
  2. See error

Expected behavior
The API docs should be able to be parsed

OpenAPI Spec File
https://sand-docs.ilevelsolutions.eu/openapi.yaml

Desktop (please complete the following information):

  • OS: macOS 13.1
  • Python Version: 3.10
  • openapi-python-client version: 0.13.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in openapi_python_client/parser/properties/init.py around line 463 and reproduce the failure with openapi-python-client generate --url https://sand-docs.ilevelsolutions.eu/openapi.yaml. Trace how list-valued enum defaults are represented and check the relevant parser tests. Done means the specification generates successfully without the TypeError and existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.