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

[14.0] base_rest_pydantic: New addon to use pydantic model into base_rest #221

Merged
merged 2 commits into from
Jun 14, 2022

Conversation

lmignon
Copy link
Contributor

@lmignon lmignon commented Nov 22, 2021

@lmignon lmignon changed the title [14.0] base_rest_pydantic: New addon to yse pydantic model into base_rest [14.0] base_rest_pydantic: New addon to use pydantic model into base_rest Nov 22, 2021
@lmignon lmignon force-pushed the 14.0-base-rest-pydantic-lmi branch 2 times, most recently from c9ff680 to 72d2e16 Compare November 23, 2021 09:16
return {"$ref": f"#/components/schemas/{schema_name}"}


class PydanticModelList(PydanticModel):
Copy link
Contributor Author

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):
        """
        """

Copy link
Member

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 ?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for sure...

Copy link
Member

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.

Copy link
Contributor Author

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.

@lmignon lmignon force-pushed the 14.0-base-rest-pydantic-lmi branch 2 times, most recently from a633ddb to c0a26bc Compare December 8, 2021 13:22
Copy link

@andreampiovesana andreampiovesana left a comment

Choose a reason for hiding this comment

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

merge?

@lmignon
Copy link
Contributor Author

lmignon commented Mar 31, 2022

@andreampiovesana did you have the opportunity to test the module and the 'extendable-pydantic' lib?

@lmignon
Copy link
Contributor Author

lmignon commented Mar 31, 2022

@andreampiovesana It seems I've to fix the demo addon

@@ -0,0 +1,26 @@
# Translation of Odoo Server.
Copy link
Contributor

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):
Copy link
Contributor

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

@lmignon lmignon force-pushed the 14.0-base-rest-pydantic-lmi branch from 30dbcf6 to 384feda Compare June 14, 2022 07:43
@lmignon lmignon force-pushed the 14.0-base-rest-pydantic-lmi branch from 384feda to 8787eaa Compare June 14, 2022 08:20
@lmignon
Copy link
Contributor Author

lmignon commented Jun 14, 2022

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 14.0-ocabot-merge-pr-221-by-lmignon-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit bc77286 into OCA:14.0 Jun 14, 2022
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 2d0c216. Thanks a lot for contributing to OCA. ❤️

@lmignon lmignon deleted the 14.0-base-rest-pydantic-lmi branch June 14, 2022 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants