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

[18.0] [MIG] migrate base_rest_pydantic #505

Open
wants to merge 26 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9e5f121
[ADD] pydantic: allows pydantic usage into Odoo and withon base_rest
lmignon Nov 6, 2021
8ff8906
[UPD] Update base_rest_pydantic.pot
oca-travis Jun 14, 2022
2ed6450
[UPD] README.rst
OCA-git-bot Jun 14, 2022
b991352
base_rest_pydantic 14.0.4.2.0
OCA-git-bot Jun 14, 2022
4af733b
Forward port from 14.0
lmignon Jun 14, 2022
bd15402
[FIX] base_rest, base_rest_pydantic: Fix message translation
lmignon Jun 14, 2022
e4f9840
[UPD] Update base_rest_pydantic.pot
Jun 14, 2022
09dcb53
[UPD] README.rst
OCA-git-bot Jun 14, 2022
e7c6120
base_rest_pydantic 15.0.4.2.1
OCA-git-bot Jun 14, 2022
3904b3b
[IMP] allow to use multipart/form-data format
Oct 6, 2021
d1c3582
base_rest_pydantic 14.0.4.3.0
OCA-git-bot Jun 15, 2022
3b98317
base_rest_pydantic 15.0.4.3.0
OCA-git-bot Jun 15, 2022
ca41dad
Initialize 16.0 branch
lmignon Sep 27, 2022
376e602
[FIX] base_rest_pydantic: forword service to PydanticModel.from_params
petrus-v Aug 19, 2022
6f9a08e
[MIG] base_rest, base_rest_auth_api_key, base_rest_datamodel, base_re…
StefanRijnhart Dec 7, 2022
8db82f8
[MIG] base_rest, base_rest_auth_api_key, base_rest_datamodel, base_re…
StefanRijnhart Nov 28, 2022
96a31ad
[UPD] Update base_rest_pydantic.pot
Jan 26, 2023
cbbb8ee
[UPD] README.rst
OCA-git-bot Jan 26, 2023
f05c986
Migration to Pydantic v2
lmignon Jul 24, 2023
02b8b0c
[UPD] Update base_rest_pydantic.pot
Jul 25, 2023
b51a477
base_rest_pydantic 16.0.2.0.0
OCA-git-bot Jul 25, 2023
01ef8c0
[UPD] README.rst
OCA-git-bot Sep 3, 2023
3f3d356
[FIX] base_rest_pydantic: Fix schema generation after last changes in…
lmignon Sep 19, 2023
68ad7af
oca-github-bot post-merge updates
OCA-git-bot Sep 19, 2023
dc36045
[MIG] mark all modules installable=False
sbidoul Nov 12, 2023
e82fdf7
[MIG] base_rest_pydantic: migrate to 18.0
pierre-halleux Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions base_rest_pydantic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
===================
Base Rest Datamodel
===================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ed7868cc1a1d1a63a8b53b8e25e19ed162638e6f7eb3246bcc6cad2c5c0ca1a6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
:target: https://github.com/OCA/rest-framework/tree/18.0/base_rest_pydantic
:alt: OCA/rest-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_pydantic
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon allows you to use Pydantic objects as params and/or response
with your REST API methods.

**Table of contents**

.. contents::
:local:

Usage
=====

To use Pydantic instances as request and/or response of a REST service
endpoint you must:

- Define your Pydantic classes;
- Provides the information required to the
``odoo.addons.base_rest.restapi.method`` decorator;

.. code:: python

from odoo.addons.base_rest import restapi
from odoo.addons.component.core import Component
from odoo.addons.pydantic.models import BaseModel

class PingMessage(BaseModel):
message: str


class PingService(Component):
_inherit = 'base.rest.service'
_name = 'ping.service'
_usage = 'ping'
_collection = 'my_module.services'


@restapi.method(
[(["/pong"], "GET")],
input_param=restapi.PydanticModel(PingMessage),
output_param=restapi.PydanticModel(PingMessage),
auth="public",
)
def pong(self, ping_message):
return PingMessage(message = "Received: " + ping_message.message)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest_pydantic%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Laurent Mignon <laurent.mignon@acsone.eu>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/base_rest_pydantic>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions base_rest_pydantic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import restapi
18 changes: 18 additions & 0 deletions base_rest_pydantic/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2021 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

{
"name": "Base Rest Datamodel",
"summary": """
Pydantic binding for base_rest""",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/rest-framework",
"depends": ["base_rest"],
"external_dependencies": {
"python": [
"pydantic>=2.0.0",
]
},
}
26 changes: 26 additions & 0 deletions base_rest_pydantic/i18n/base_rest_datamodel.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_rest_datamodel
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: base_rest_datamodel
#: code:addons/base_rest_datamodel/restapi.py:0
#, python-format
msgid "BadRequest %s"
msgstr ""

#. module: base_rest_datamodel
#: code:addons/base_rest_datamodel/restapi.py:0
#, python-format
msgid "Invalid Response %s"
msgstr ""
42 changes: 42 additions & 0 deletions base_rest_pydantic/i18n/base_rest_pydantic.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_rest_pydantic
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: base_rest_pydantic
#. odoo-python
#: code:addons/base_rest_pydantic/restapi.py:0
#, python-format
msgid "BadRequest %s"
msgstr ""

#. module: base_rest_pydantic
#. odoo-python
#: code:addons/base_rest_pydantic/restapi.py:0
#, python-format
msgid "BadRequest: Not enough items in the list (%(current)s < %(expected)s)"
msgstr ""

#. module: base_rest_pydantic
#. odoo-python
#: code:addons/base_rest_pydantic/restapi.py:0
#, python-format
msgid "BadRequest: Too many items in the list (%(current)s > %(expected)s)"
msgstr ""

#. module: base_rest_pydantic
#. odoo-python
#: code:addons/base_rest_pydantic/restapi.py:0
#, python-format
msgid "Invalid Response"
msgstr ""
3 changes: 3 additions & 0 deletions base_rest_pydantic/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions base_rest_pydantic/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Laurent Mignon \<laurent.mignon@acsone.eu\>
2 changes: 2 additions & 0 deletions base_rest_pydantic/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This addon allows you to use Pydantic objects as params and/or response
with your REST API methods.
32 changes: 32 additions & 0 deletions base_rest_pydantic/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
To use Pydantic instances as request and/or response of a REST service
endpoint you must:

- Define your Pydantic classes;
- Provides the information required to the
`odoo.addons.base_rest.restapi.method` decorator;

``` python
from odoo.addons.base_rest import restapi
from odoo.addons.component.core import Component
from odoo.addons.pydantic.models import BaseModel

class PingMessage(BaseModel):
message: str


class PingService(Component):
_inherit = 'base.rest.service'
_name = 'ping.service'
_usage = 'ping'
_collection = 'my_module.services'


@restapi.method(
[(["/pong"], "GET")],
input_param=restapi.PydanticModel(PingMessage),
output_param=restapi.PydanticModel(PingMessage),
auth="public",
)
def pong(self, ping_message):
return PingMessage(message = "Received: " + ping_message.message)
```
Loading
Loading