Skip to content

[BUG][Python] Model template doesn't properly handle nested dicts and arrays. #22211

Description

@ottmar-zittlau

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have some components that contain dicts of dicts. With the default templates the generator doesn't generate valid python-code for these components.

Here is the generated code: https://gist.github.com/ottmar-zittlau/9d2d98ffd9b29c3bcb34b9e947228354

Some bugs:

Here the class on which from_dict is called is a type.

"array_of_dictionaries": [Dict[str, Vector3d].from_dict(_item) for _item in obj["array_of_dictionaries"]] if obj.get("array_of_dictionaries") is not None else None,

Here _item_array_of_dictionaries is a dictionary that doesn't have a to_dict method.

        if self.array_of_dictionaries:
            for _item_array_of_dictionaries in self.array_of_dictionaries:
                if _item_array_of_dictionaries:
                    _items.append(_item_array_of_dictionaries.to_dict())
            _dict['array_of_dictionaries'] = _items
openapi-generator version

7.16.0

OpenAPI declaration file content or url

https://gist.github.com/ottmar-zittlau/2e2a5357b1d1e60d41a2aef4ee6bde14

Generation Details

I generated code for python.

Steps to reproduce

Run

./openapi-generator-cli generate --generator-name python --input-spec openapi.yaml --output generated --package-name example
Related issues/PRs
Suggest a fix

I already have adapted the model_generic.mustache template file to deal with this, but before opening a merge request I wanted to know if this bug is known and whether there is already work going on to fix it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions