-
-
Notifications
You must be signed in to change notification settings - Fork 303
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
[14.0] base_rest_pydantic: New addon to use pydantic model into base_rest #221
Conversation
lmignon
commented
Nov 22, 2021
•
edited
Loading
edited
- uses the external python lib extendable_pydantic published on pypi
- includes [14.0][ADD] extendable: New addon to alllow usage of the Extendable python … #246
c9ff680
to
72d2e16
Compare
return {"$ref": f"#/components/schemas/{schema_name}"} | ||
|
||
|
||
class PydanticModelList(PydanticModel): |
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.
@sbidoul I wonder if I should delete this class. Lists could be supported by the base class by parsing the type given as a parameter and the specific list processing arguments only used in the case of a list.
from typing import List
...
@restapi.method(
[(["/", "/search"], "GET")],
input_param=PydanticModel(PartnerSearchParam),
output_param=PydanticModel(List[PartnerShortInfo]),
auth="public",
)
def search(self, partner_search_param):
"""
"""
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.
Do we actually need PydanticModel at all in the input/output param declaration ? Could it be
input_param=PartnerSearchParam,
output_param=List[PartnerShortInfo],
and let the framework detect they derive from pydantic.BaseModel to do its magic ?
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.
iow, PydanticModel and PydanticModelList could be internal to the base_rest framework with restapi.method
wrapping input_param and output_param in PydanticModel when it detects they derive from pydantic.BaseModel.
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.
for sure...
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.
I don't want to add more work on you. It can come as a future ergonomy improvement.
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.
I'll leave the code as is. It will be part of the next big evolution.
72d2e16
to
c509bd3
Compare
a633ddb
to
c0a26bc
Compare
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.
merge?
@andreampiovesana did you have the opportunity to test the module and the 'extendable-pydantic' lib? |
@andreampiovesana It seems I've to fix the demo addon |
@@ -0,0 +1,26 @@ | |||
# Translation of Odoo Server. |
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.
I don't know if this will break anything but this should be named base_rest_pydantic.pot
@@ -161,10 +161,10 @@ def _binary_content_schema(self): | |||
for mediatype in self._mediatypes | |||
} | |||
|
|||
def to_openapi_requestbody(self, service): | |||
def to_openapi_requestbody(self, services, spec): |
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.
I have the feeling that services
is an error here and should be singular service
30dbcf6
to
384feda
Compare
384feda
to
8787eaa
Compare
/ocabot merge minor |
What a great day to merge this nice PR. Let's do it! |
Congratulations, your PR was merged at 2d0c216. Thanks a lot for contributing to OCA. ❤️ |