Skip to content

Commit 34648dc

Browse files
pierre-halleuxlmignon
authored andcommitted
[MIG] base_rest_pydantic: migrate to 18.0
1 parent b614980 commit 34648dc

14 files changed

Lines changed: 109 additions & 102 deletions

File tree

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 <laurent.mignon@acsone.eu>
96+
- Laurent Mignon <laurent.mignon@acsone.eu>
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 \<laurent.mignon@acsone.eu\>

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: 22 additions & 19 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>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

278-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
279279
pre.code, code { background-color: #eeeeee }
280280
pre.code .comment, code .comment { color: #5C6576 }
281281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@
301301
span.pre {
302302
white-space: pre }
303303

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -369,9 +369,9 @@ <h1 class="title">Base Rest Datamodel</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:ed7868cc1a1d1a63a8b53b8e25e19ed162638e6f7eb3246bcc6cad2c5c0ca1a6
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
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>
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/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>
373+
<p>This addon allows you to use Pydantic objects as params and/or response
374+
with your REST API methods.</p>
375375
<p><strong>Table of contents</strong></p>
376376
<div class="contents local topic" id="contents">
377377
<ul class="simple">
@@ -387,22 +387,23 @@ <h1 class="title">Base Rest Datamodel</h1>
387387
</div>
388388
<div class="section" id="usage">
389389
<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>
390+
<p>To use Pydantic instances as request and/or response of a REST service
391+
endpoint you must:</p>
392392
<ul class="simple">
393393
<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>
394+
<li>Provides the information required to the
395+
<tt class="docutils literal">odoo.addons.base_rest.restapi.method</tt> decorator;</li>
395396
</ul>
396397
<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">
398+
<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">
399+
</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">
400+
</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">
400401

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">
402+
</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">
402403
</span> <span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="w">
403404

404405

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">
406+
</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">
406407
</span> <span class="n">_inherit</span> <span class="o">=</span> <span class="s1">'base.rest.service'</span><span class="w">
407408
</span> <span class="n">_name</span> <span class="o">=</span> <span class="s1">'ping.service'</span><span class="w">
408409
</span> <span class="n">_usage</span> <span class="o">=</span> <span class="s1">'ping'</span><span class="w">
@@ -415,7 +416,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
415416
</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">
416417
</span> <span class="n">auth</span><span class="o">=</span><span class="s2">&quot;public&quot;</span><span class="p">,</span><span class="w">
417418
</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">
419+
</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">
419420
</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>
420421
</pre>
421422
</div>
@@ -424,7 +425,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
424425
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>.
425426
In case of trouble, please check there if your issue has already been reported.
426427
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>
428+
<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>
428429
<p>Do not contact contributors directly about support or help with technical issues.</p>
429430
</div>
430431
<div class="section" id="credits">
@@ -444,11 +445,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
444445
<div class="section" id="maintainers">
445446
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
446447
<p>This module is maintained by the OCA.</p>
447-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
448+
<a class="reference external image-reference" href="https://odoo-community.org">
449+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
450+
</a>
448451
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
449452
mission is to support the collaborative development of Odoo features and
450453
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>
454+
<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>
452455
<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>
453456
</div>
454457
</div>

0 commit comments

Comments
 (0)