[PYTHON] generate code based on pydantic v2#16685
[PYTHON] generate code based on pydantic v2#16685wing328 merged 14 commits intoOpenAPITools:masterfrom
Conversation
multani
left a comment
There was a problem hiding this comment.
Running the tests in samples/openapi3/client/petstore/python-aiohttp goes from:
148 passed, 2 skipped, 2100 warnings
to:
148 passed, 2 skipped, 60 warnings
and I don't see any Pydantic v2 warnings anymore 👏
|
FYI @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @arun-nalla (2019/11) @krjakbrjak (2023/02) |
|
tested locally and all those pydantic warnings are gone 👍 |
|
I am receiving It's caused by # raise errors for additional fields in the input
for _key in obj.keys():
> if _key not in cls.__properties:
E TypeError: argument of type 'ModelPrivateAttr' is not iterableWhole snippet __properties = ["sessionID"]
@classmethod
def from_dict(cls, obj: dict) -> Session:
"""Create an instance of Session from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Session.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError(
"Error due to additional fields (not defined in Session) in the input: "
+ obj
)
_obj = Session.model_validate(
{
"sessionID": obj.get("sessionID"),
}
)
return _objIt worked in #16655 |
@jakubno do you have an OpenAPI example where this happens? This was changed in #16624 but I think we missed a branch that was not covered by the tests. |
|
I will create minimal example and create issue |
Great, thanks 👍 If that helps, it seems it has something to do with "additional properties": this is the part in the code generator that may not be covered by the tests. |
|
Perhaps |
|
Yep, that's what I did in the branch that was covered by the tests 👍 |
|
If you test this, you need to set the |
|
NOTE: for users who still prefer using pydantic v1 in v7.1.0 release, they can use the |
PR checklist
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.
master(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)