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

Fix serialization of inline arrays of free-form objects [python] #10436

Closed
wants to merge 2 commits into from
Closed

Fix serialization of inline arrays of free-form objects [python] #10436

wants to merge 2 commits into from

Conversation

jsok
Copy link

@jsok jsok commented Sep 21, 2021

Given a spec like:

        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": true
        }

the generated code is unable to serialize it (reproduction in commit 834b4e3):

test_model_to_dict (tests_manual.test_model_utils.ModelUtilsTests) ... ERROR

======================================================================
ERROR: test_model_to_dict (tests_manual.test_model_utils.ModelUtilsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jsok/dev/github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/python/tests_manual/test_model_utils.py", line 32, in test_model_to_dict
    model_to_dict(model)
  File "/Users/jsok/dev/github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/python/petstore_api/model_utils.py", line 1690, in model_to_dict
    res.append(model_to_dict(v, serialize=serialize))
  File "/Users/jsok/dev/github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/python/petstore_api/model_utils.py", line 1662, in model_to_dict
    if model_instance._composed_schemas:
AttributeError: 'dict' object has no attribute '_composed_schemas'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

Subsequent commit 8332732 contains the fix in model_to_dict.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@spacether related to our earlier discussion: https://github.com/OpenAPITools/openapi-generator/pull/9153/files#r712601002
@arun-nalla @Jyhess @tomplus

Serialising a model fails in model_to_dict with:

```
AttributeError: 'dict' object has no attribute '_composed_schemas'
```
@jsok
Copy link
Author

jsok commented Jan 17, 2022

@tomplus @spacether is there any chance this PR could get some 👀 ?

@@ -1682,7 +1682,7 @@ def model_to_dict(model_instance, serialize=True):
else:
res = []
for v in value:
if isinstance(v, PRIMITIVE_TYPES) or v is None:
if isinstance(v, (dict,) + PRIMITIVE_TYPES) or v is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the dict contains model instances?
How about converting its values too?

@jsok
Copy link
Author

jsok commented Mar 3, 2022

Superseded by #11234

@jsok jsok closed this Mar 3, 2022
@jsok jsok deleted the python-array-of-objects branch March 3, 2022 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants