Skip to content

Commit f5a65fa

Browse files
[MIG] base_rest_pydantic: migrate to 18.0
1 parent dc36045 commit f5a65fa

14 files changed

+102
-96
lines changed

base_rest_pydantic/README.rst

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ Base Rest Datamodel
1717
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1818
:alt: License: LGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20-
:target: https://github.com/OCA/rest-framework/tree/16.0/base_rest_pydantic
20+
:target: https://github.com/OCA/rest-framework/tree/18.0/base_rest_pydantic
2121
:alt: OCA/rest-framework
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-base_rest_pydantic
23+
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_pydantic
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

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

3434
**Table of contents**
3535

@@ -39,65 +39,64 @@ REST API methods.
3939
Usage
4040
=====
4141

42-
To use Pydantic instances as request and/or response of a REST service endpoint
43-
you must:
42+
To use Pydantic instances as request and/or response of a REST service
43+
endpoint you must:
4444

45-
* Define your Pydantic classes;
46-
* Provides the information required to the ``odoo.addons.base_rest.restapi.method`` decorator;
45+
- Define your Pydantic classes;
46+
- Provides the information required to the
47+
``odoo.addons.base_rest.restapi.method`` decorator;
4748

49+
.. code:: python
4850
49-
.. code-block:: python
51+
from odoo.addons.base_rest import restapi
52+
from odoo.addons.component.core import Component
53+
from odoo.addons.pydantic.models import BaseModel
5054
55+
class PingMessage(BaseModel):
56+
message: str
5157
52-
from odoo.addons.base_rest import restapi
53-
from odoo.addons.component.core import Component
54-
from odoo.addons.pydantic.models import BaseModel
5558
56-
class PingMessage(BaseModel):
57-
message: str
59+
class PingService(Component):
60+
_inherit = 'base.rest.service'
61+
_name = 'ping.service'
62+
_usage = 'ping'
63+
_collection = 'my_module.services'
5864
5965
60-
class PingService(Component):
61-
_inherit = 'base.rest.service'
62-
_name = 'ping.service'
63-
_usage = 'ping'
64-
_collection = 'my_module.services'
65-
66-
67-
@restapi.method(
68-
[(["/pong"], "GET")],
69-
input_param=restapi.PydanticModel(PingMessage),
70-
output_param=restapi.PydanticModel(PingMessage),
71-
auth="public",
72-
)
73-
def pong(self, ping_message):
74-
return PingMessage(message = "Received: " + ping_message.message)
66+
@restapi.method(
67+
[(["/pong"], "GET")],
68+
input_param=restapi.PydanticModel(PingMessage),
69+
output_param=restapi.PydanticModel(PingMessage),
70+
auth="public",
71+
)
72+
def pong(self, ping_message):
73+
return PingMessage(message = "Received: " + ping_message.message)
7574
7675
Bug Tracker
7776
===========
7877

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

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

8685
Credits
8786
=======
8887

8988
Authors
90-
~~~~~~~
89+
-------
9190

9291
* ACSONE SA/NV
9392

9493
Contributors
95-
~~~~~~~~~~~~
94+
------------
9695

97-
* Laurent Mignon <[email protected]>
96+
- Laurent Mignon <[email protected]>
9897

9998
Maintainers
100-
~~~~~~~~~~~
99+
-----------
101100

102101
This module is maintained by the OCA.
103102

@@ -109,6 +108,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
109108
mission is to support the collaborative development of Odoo features and
110109
promote its widespread use.
111110

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

114113
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

base_rest_pydantic/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
"name": "Base Rest Datamodel",
66
"summary": """
77
Pydantic binding for base_rest""",
8-
"version": "16.0.2.0.1",
8+
"version": "18.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/rest-framework",
1212
"depends": ["base_rest"],
13-
"installable": False,
1413
"external_dependencies": {
1514
"python": [
1615
"pydantic>=2.0.0",

base_rest_pydantic/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Laurent Mignon \<[email protected]\>

base_rest_pydantic/readme/CONTRIBUTORS.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This addon allows you to use Pydantic objects as params and/or response with your
2-
REST API methods.
1+
This addon allows you to use Pydantic objects as params and/or response
2+
with your REST API methods.

base_rest_pydantic/readme/USAGE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
To use Pydantic instances as request and/or response of a REST service
2+
endpoint you must:
3+
4+
- Define your Pydantic classes;
5+
- Provides the information required to the
6+
`odoo.addons.base_rest.restapi.method` decorator;
7+
8+
``` python
9+
from odoo.addons.base_rest import restapi
10+
from odoo.addons.component.core import Component
11+
from odoo.addons.pydantic.models import BaseModel
12+
13+
class PingMessage(BaseModel):
14+
message: str
15+
16+
17+
class PingService(Component):
18+
_inherit = 'base.rest.service'
19+
_name = 'ping.service'
20+
_usage = 'ping'
21+
_collection = 'my_module.services'
22+
23+
24+
@restapi.method(
25+
[(["/pong"], "GET")],
26+
input_param=restapi.PydanticModel(PingMessage),
27+
output_param=restapi.PydanticModel(PingMessage),
28+
auth="public",
29+
)
30+
def pong(self, ping_message):
31+
return PingMessage(message = "Received: " + ping_message.message)
32+
```

base_rest_pydantic/readme/USAGE.rst

Lines changed: 0 additions & 33 deletions
This file was deleted.

base_rest_pydantic/restapi.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,21 @@ def _do_validate(self, values, direction):
175175
if self._min_items is not None and len(values) < self._min_items:
176176
raise ExceptionClass(
177177
_(
178-
"BadRequest: Not enough items in the list (%(current)s < %(expected)s)",
178+
(
179+
"BadRequest: Not enough items in the list (%(current)s < "
180+
"%(expected)s)"
181+
),
179182
current=len(values),
180183
expected=self._min_items,
181184
)
182185
)
183186
if self._max_items is not None and len(values) > self._max_items:
184187
raise ExceptionClass(
185188
_(
186-
"BadRequest: Too many items in the list (%(current)s > %(expected)s)",
189+
(
190+
"BadRequest: Too many items in the list (%(current)s > "
191+
"%(expected)s)"
192+
),
187193
current=len(values),
188194
expected=self._max_items,
189195
)

base_rest_pydantic/static/description/index.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -369,9 +368,9 @@ <h1 class="title">Base Rest Datamodel</h1>
369368
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370369
!! source digest: sha256:ed7868cc1a1d1a63a8b53b8e25e19ed162638e6f7eb3246bcc6cad2c5c0ca1a6
371370
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/base_rest_pydantic"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-base_rest_pydantic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373-
<p>This addon allows you to use Pydantic objects as params and/or response with your
374-
REST API methods.</p>
371+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest_pydantic"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_pydantic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p>This addon allows you to use Pydantic objects as params and/or response
373+
with your REST API methods.</p>
375374
<p><strong>Table of contents</strong></p>
376375
<div class="contents local topic" id="contents">
377376
<ul class="simple">
@@ -387,22 +386,23 @@ <h1 class="title">Base Rest Datamodel</h1>
387386
</div>
388387
<div class="section" id="usage">
389388
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
390-
<p>To use Pydantic instances as request and/or response of a REST service endpoint
391-
you must:</p>
389+
<p>To use Pydantic instances as request and/or response of a REST service
390+
endpoint you must:</p>
392391
<ul class="simple">
393392
<li>Define your Pydantic classes;</li>
394-
<li>Provides the information required to the <tt class="docutils literal">odoo.addons.base_rest.restapi.method</tt> decorator;</li>
393+
<li>Provides the information required to the
394+
<tt class="docutils literal">odoo.addons.base_rest.restapi.method</tt> decorator;</li>
395395
</ul>
396396
<pre class="code python literal-block">
397-
<span class="kn">from</span> <span class="nn">odoo.addons.base_rest</span> <span class="kn">import</span> <span class="n">restapi</span><span class="w">
398-
</span><span class="kn">from</span> <span class="nn">odoo.addons.component.core</span> <span class="kn">import</span> <span class="n">Component</span><span class="w">
399-
</span><span class="kn">from</span> <span class="nn">odoo.addons.pydantic.models</span> <span class="kn">import</span> <span class="n">BaseModel</span><span class="w">
397+
<span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.base_rest</span><span class="w"> </span><span class="kn">import</span> <span class="n">restapi</span><span class="w">
398+
</span><span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.component.core</span><span class="w"> </span><span class="kn">import</span> <span class="n">Component</span><span class="w">
399+
</span><span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.pydantic.models</span><span class="w"> </span><span class="kn">import</span> <span class="n">BaseModel</span><span class="w">
400400

401-
</span><span class="k">class</span> <span class="nc">PingMessage</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span><span class="w">
401+
</span><span class="k">class</span><span class="w"> </span><span class="nc">PingMessage</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span><span class="w">
402402
</span> <span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="w">
403403

404404

405-
</span><span class="k">class</span> <span class="nc">PingService</span><span class="p">(</span><span class="n">Component</span><span class="p">):</span><span class="w">
405+
</span><span class="k">class</span><span class="w"> </span><span class="nc">PingService</span><span class="p">(</span><span class="n">Component</span><span class="p">):</span><span class="w">
406406
</span> <span class="n">_inherit</span> <span class="o">=</span> <span class="s1">'base.rest.service'</span><span class="w">
407407
</span> <span class="n">_name</span> <span class="o">=</span> <span class="s1">'ping.service'</span><span class="w">
408408
</span> <span class="n">_usage</span> <span class="o">=</span> <span class="s1">'ping'</span><span class="w">
@@ -415,7 +415,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
415415
</span> <span class="n">output_param</span><span class="o">=</span><span class="n">restapi</span><span class="o">.</span><span class="n">PydanticModel</span><span class="p">(</span><span class="n">PingMessage</span><span class="p">),</span><span class="w">
416416
</span> <span class="n">auth</span><span class="o">=</span><span class="s2">&quot;public&quot;</span><span class="p">,</span><span class="w">
417417
</span> <span class="p">)</span><span class="w">
418-
</span> <span class="k">def</span> <span class="nf">pong</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ping_message</span><span class="p">):</span><span class="w">
418+
</span> <span class="k">def</span><span class="w"> </span><span class="nf">pong</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ping_message</span><span class="p">):</span><span class="w">
419419
</span> <span class="k">return</span> <span class="n">PingMessage</span><span class="p">(</span><span class="n">message</span> <span class="o">=</span> <span class="s2">&quot;Received: &quot;</span> <span class="o">+</span> <span class="n">ping_message</span><span class="o">.</span><span class="n">message</span><span class="p">)</span>
420420
</pre>
421421
</div>
@@ -424,7 +424,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
424424
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>.
425425
In case of trouble, please check there if your issue has already been reported.
426426
If you spotted it first, help us to smash it by providing a detailed and welcomed
427-
<a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest_pydantic%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
427+
<a class="reference external" href="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**">feedback</a>.</p>
428428
<p>Do not contact contributors directly about support or help with technical issues.</p>
429429
</div>
430430
<div class="section" id="credits">
@@ -448,7 +448,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
448448
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
449449
mission is to support the collaborative development of Odoo features and
450450
promote its widespread use.</p>
451-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/16.0/base_rest_pydantic">OCA/rest-framework</a> project on GitHub.</p>
451+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest_pydantic">OCA/rest-framework</a> project on GitHub.</p>
452452
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
453453
</div>
454454
</div>

base_rest_pydantic/tests/test_from_params.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2021 Wakari SRL
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3-
from typing import Type
43
from unittest import mock
54

65
from odoo.exceptions import UserError
@@ -13,15 +12,15 @@
1312

1413
class TestPydantic(TransactionCase):
1514
def setUp(self):
16-
super(TestPydantic, self).setUp()
15+
super().setUp()
1716

1817
class Model1(BaseModel):
1918
name: str
2019
description: str = None
2120

2221
self.Model1: BaseModel = Model1
2322

24-
def _from_params(self, pydantic_cls: Type[BaseModel], params: dict, **kwargs):
23+
def _from_params(self, pydantic_cls: type[BaseModel], params: dict, **kwargs):
2524
restapi_pydantic_cls = (
2625
restapi.PydanticModelList
2726
if isinstance(params, list)

base_rest_pydantic/tests/test_response.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2021 Wakari SRL
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3-
from typing import List
43
from unittest import mock
54

65
from odoo.tests.common import TransactionCase
@@ -17,7 +16,7 @@ def _to_response(self, instance: BaseModel):
1716
mock_service.env = self.env
1817
return restapi_pydantic.to_response(mock_service, instance)
1918

20-
def _to_response_list(self, instance: List[BaseModel]):
19+
def _to_response_list(self, instance: list[BaseModel]):
2120
restapi_pydantic = restapi.PydanticModelList(instance[0].__class__)
2221
mock_service = mock.Mock()
2322
mock_service.env = self.env

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
a2wsgi>=1.10.6
33
fastapi>=0.110.0
44
parse-accept-language
5+
pydantic>=2.0.0
56
python-multipart
67
ujson

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
httpx
2+
odoo-addon-base-rest @ git+https://github.com/OCA/rest-framework.git@refs/pull/506/head#subdirectory=base_rest

0 commit comments

Comments
 (0)