-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
python-pydantic-v1: Return the primitive type in to_dict for anyOf models #19488
Conversation
Adding @cbornet @tomplus @krjakbrjak Requesting a review |
@multani Would appreciate a review on this. Currently this serialization bug is preventing me from using the pydantic v1 generator. |
@chiragjn Could you provide a test to exercise this code and prevent further regressions in the future? |
This file (or the whole folder actually) contains hand-written tests for such a case: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/petstore/python-pydantic-v1/tests/test_model.py (there's a similar folder for the asyncio generator) It would be great it you could extend this test suite to show how the issue is fixed by this change. Thanks! |
…into cj_fix_to_dict_python
|
||
# test to_dict, schema 3 | ||
p = petstore_api.AnyOfColor(actual_instance='#123456') | ||
self.assertEqual(p.to_dict(), '#123456') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this change, this would render as '"#123456"'
which is incorrect for to_dict
@multani Updated test, hope this helps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, @wing328 can you check?
Thanks for the added tests @chiragjn ! |
Sorry for being annoying, Bumping this again to @wing328 |
@chiragjn just merged the PR. Thanks again for your contributions. |
Python pydantic definitions for models with multiple schemas using anyOf implement to_dict incorrectly when one of the types is not a pydantic BaseModel.
The function should just return the type as is instead of json dumping it
I don't know if this is considered a breaking change
PR checklist
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*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)@fa0311 @multani