diff --git a/base_rest_pydantic/README.rst b/base_rest_pydantic/README.rst
index 1280e78b5..7555d2aee 100644
--- a/base_rest_pydantic/README.rst
+++ b/base_rest_pydantic/README.rst
@@ -17,19 +17,19 @@ Base Rest Datamodel
: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/16.0/base_rest_pydantic
+ :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-16-0/rest-framework-16-0-base_rest_pydantic
+ :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=16.0
+ :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.
+This addon allows you to use Pydantic objects as params and/or response
+with your REST API methods.
**Table of contents**
@@ -39,39 +39,38 @@ REST API methods.
Usage
=====
-To use Pydantic instances as request and/or response of a REST service endpoint
-you must:
+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;
+- Define your Pydantic classes;
+- Provides the information required to the
+ ``odoo.addons.base_rest.restapi.method`` decorator;
+.. code:: python
-.. code-block:: 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
- 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'
- 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)
+ @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
===========
@@ -79,7 +78,7 @@ Bug Tracker
Bugs are tracked on `GitHub 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -87,17 +86,17 @@ Credits
=======
Authors
-~~~~~~~
+-------
* ACSONE SA/NV
Contributors
-~~~~~~~~~~~~
+------------
-* Laurent Mignon
+- Laurent Mignon
Maintainers
-~~~~~~~~~~~
+-----------
This module is maintained by the OCA.
@@ -109,6 +108,6 @@ 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 `_ project on GitHub.
+This module is part of the `OCA/rest-framework `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/base_rest_pydantic/__manifest__.py b/base_rest_pydantic/__manifest__.py
index 4a389927b..0b94bbd77 100644
--- a/base_rest_pydantic/__manifest__.py
+++ b/base_rest_pydantic/__manifest__.py
@@ -5,12 +5,11 @@
"name": "Base Rest Datamodel",
"summary": """
Pydantic binding for base_rest""",
- "version": "16.0.2.0.1",
+ "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"],
- "installable": False,
"external_dependencies": {
"python": [
"pydantic>=2.0.0",
diff --git a/base_rest_pydantic/pyproject.toml b/base_rest_pydantic/pyproject.toml
new file mode 100644
index 000000000..4231d0ccc
--- /dev/null
+++ b/base_rest_pydantic/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["whool"]
+build-backend = "whool.buildapi"
diff --git a/base_rest_pydantic/readme/CONTRIBUTORS.md b/base_rest_pydantic/readme/CONTRIBUTORS.md
new file mode 100644
index 000000000..dc42b35f3
--- /dev/null
+++ b/base_rest_pydantic/readme/CONTRIBUTORS.md
@@ -0,0 +1 @@
+- Laurent Mignon \
diff --git a/base_rest_pydantic/readme/CONTRIBUTORS.rst b/base_rest_pydantic/readme/CONTRIBUTORS.rst
deleted file mode 100644
index 172b2d223..000000000
--- a/base_rest_pydantic/readme/CONTRIBUTORS.rst
+++ /dev/null
@@ -1 +0,0 @@
-* Laurent Mignon
diff --git a/base_rest_pydantic/readme/DESCRIPTION.rst b/base_rest_pydantic/readme/DESCRIPTION.md
similarity index 64%
rename from base_rest_pydantic/readme/DESCRIPTION.rst
rename to base_rest_pydantic/readme/DESCRIPTION.md
index a5311dcef..c5f8ebaee 100644
--- a/base_rest_pydantic/readme/DESCRIPTION.rst
+++ b/base_rest_pydantic/readme/DESCRIPTION.md
@@ -1,2 +1,2 @@
-This addon allows you to use Pydantic objects as params and/or response with your
-REST API methods.
+This addon allows you to use Pydantic objects as params and/or response
+with your REST API methods.
diff --git a/base_rest_pydantic/readme/USAGE.md b/base_rest_pydantic/readme/USAGE.md
new file mode 100644
index 000000000..36f78b1e4
--- /dev/null
+++ b/base_rest_pydantic/readme/USAGE.md
@@ -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)
+```
diff --git a/base_rest_pydantic/readme/USAGE.rst b/base_rest_pydantic/readme/USAGE.rst
deleted file mode 100644
index 47d6506a0..000000000
--- a/base_rest_pydantic/readme/USAGE.rst
+++ /dev/null
@@ -1,33 +0,0 @@
-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-block:: 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)
diff --git a/base_rest_pydantic/restapi.py b/base_rest_pydantic/restapi.py
index f7301074e..f9fb27c0d 100644
--- a/base_rest_pydantic/restapi.py
+++ b/base_rest_pydantic/restapi.py
@@ -175,7 +175,10 @@ def _do_validate(self, values, direction):
if self._min_items is not None and len(values) < self._min_items:
raise ExceptionClass(
_(
- "BadRequest: Not enough items in the list (%(current)s < %(expected)s)",
+ (
+ "BadRequest: Not enough items in the list (%(current)s < "
+ "%(expected)s)"
+ ),
current=len(values),
expected=self._min_items,
)
@@ -183,7 +186,10 @@ def _do_validate(self, values, direction):
if self._max_items is not None and len(values) > self._max_items:
raise ExceptionClass(
_(
- "BadRequest: Too many items in the list (%(current)s > %(expected)s)",
+ (
+ "BadRequest: Too many items in the list (%(current)s > "
+ "%(expected)s)"
+ ),
current=len(values),
expected=self._max_items,
)
diff --git a/base_rest_pydantic/static/description/index.html b/base_rest_pydantic/static/description/index.html
index c65e24c88..25ff4e357 100644
--- a/base_rest_pydantic/static/description/index.html
+++ b/base_rest_pydantic/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -369,9 +368,9 @@ Base Rest Datamodel
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ed7868cc1a1d1a63a8b53b8e25e19ed162638e6f7eb3246bcc6cad2c5c0ca1a6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

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

+This addon allows you to use Pydantic objects as params and/or response
+with your REST API methods.
Table of contents
@@ -387,22 +386,23 @@ Base Rest Datamodel
-
To use Pydantic instances as request and/or response of a REST service endpoint
-you must:
+
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;
+- Provides the information required to the
+odoo.addons.base_rest.restapi.method decorator;
-from odoo.addons.base_rest import restapi
-from odoo.addons.component.core import Component
-from odoo.addons.pydantic.models import BaseModel
+from odoo.addons.base_rest import restapi
+from odoo.addons.component.core import Component
+from odoo.addons.pydantic.models import BaseModel
-class PingMessage(BaseModel):
+class PingMessage(BaseModel):
message: str
-class PingService(Component):
+class PingService(Component):
_inherit = 'base.rest.service'
_name = 'ping.service'
_usage = 'ping'
@@ -415,7 +415,7 @@
output_param=restapi.PydanticModel(PingMessage),
auth="public",
)
- def pong(self, ping_message):
+ def pong(self, ping_message):
return PingMessage(message = "Received: " + ping_message.message)
@@ -424,7 +424,7 @@
Bugs are tracked on GitHub 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.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -448,7 +448,7 @@
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 project on GitHub.
+
This module is part of the OCA/rest-framework project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/base_rest_pydantic/tests/test_from_params.py b/base_rest_pydantic/tests/test_from_params.py
index 54e4074e9..b0e39b872 100644
--- a/base_rest_pydantic/tests/test_from_params.py
+++ b/base_rest_pydantic/tests/test_from_params.py
@@ -1,6 +1,5 @@
# Copyright 2021 Wakari SRL
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
-from typing import Type
from unittest import mock
from odoo.exceptions import UserError
@@ -13,7 +12,7 @@
class TestPydantic(TransactionCase):
def setUp(self):
- super(TestPydantic, self).setUp()
+ super().setUp()
class Model1(BaseModel):
name: str
@@ -21,7 +20,7 @@ class Model1(BaseModel):
self.Model1: BaseModel = Model1
- def _from_params(self, pydantic_cls: Type[BaseModel], params: dict, **kwargs):
+ def _from_params(self, pydantic_cls: type[BaseModel], params: dict, **kwargs):
restapi_pydantic_cls = (
restapi.PydanticModelList
if isinstance(params, list)
diff --git a/base_rest_pydantic/tests/test_response.py b/base_rest_pydantic/tests/test_response.py
index e224ef549..9bafff3ea 100644
--- a/base_rest_pydantic/tests/test_response.py
+++ b/base_rest_pydantic/tests/test_response.py
@@ -1,6 +1,5 @@
# Copyright 2021 Wakari SRL
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
-from typing import List
from unittest import mock
from odoo.tests.common import TransactionCase
@@ -17,7 +16,7 @@ def _to_response(self, instance: BaseModel):
mock_service.env = self.env
return restapi_pydantic.to_response(mock_service, instance)
- def _to_response_list(self, instance: List[BaseModel]):
+ def _to_response_list(self, instance: list[BaseModel]):
restapi_pydantic = restapi.PydanticModelList(instance[0].__class__)
mock_service = mock.Mock()
mock_service.env = self.env
diff --git a/requirements.txt b/requirements.txt
index bcba9b734..123926406 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,5 +2,6 @@
a2wsgi>=1.10.6
fastapi>=0.110.0
parse-accept-language
+pydantic>=2.0.0
python-multipart
ujson