Skip to content
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

[BUG][python] Errors in to_dict() with additionalProperties of type array #16630

Closed
4 of 6 tasks
robertschweizer opened this issue Sep 20, 2023 · 0 comments · Fixed by #16779
Closed
4 of 6 tasks

[BUG][python] Errors in to_dict() with additionalProperties of type array #16630

robertschweizer opened this issue Sep 20, 2023 · 0 comments · Fixed by #16779

Comments

@robertschweizer
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

The below OpenAPI spec leads to the following Python code block in ModelWithDict.to_dict():

    dict_property: Optional[Dict[str, conlist(StrictStr)]] = Field(None, alias="dictProperty")

    ...

        _field_dict_of_array = {}
        if self.dict_property:
            for _key in self.dict_property:
                if self.dict_property[_key]:
                    _field_dict_of_array[_key] = [
                        _item.to_dict() for _item in self.dict_property[_key]
                    ]
            _dict['dictProperty'] = _field_dict_of_array

This has two errors:

  1. .to_dict() is called on the list items, which fails because they are strings.
  2. if self.dict_property[_key]: wrongly skips dictionary keys where the value is an empty list.
openapi-generator version

7.0.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: ""
  version: ""
paths: {}
components:
  schemas:
    ModelWithDict:
      type: object
      properties:
        dictProperty:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
robertschweizer added a commit to robertschweizer/openapi-generator that referenced this issue Oct 10, 2023
wing328 pushed a commit that referenced this issue Oct 11, 2023
* test: Add two extra models for testing

* Fix unnamed dicts with additional properties

Closes #16630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant