Author: |
ACSONE SA/NV,Odoo Community Association (OCA) |
License: |
LGPL-3 |
Branch: |
14.0-fdl_master |
Repository: |
acsone/rest-framework |
Dependencies: |
base_rest |
Languages: |
HTML (360, 54.3%),
Python (260, 39.2%),
and
reStructuredText (43, 6.5%) |
Other branches: |
13.0-backport-base-rest-pydantic,
14.0,
14.0-base-rest-pydantic-lmi,
14.0-deprecated-implicit-rest-method,
14.0-fix-response-processing,
15.0,
16.0,
16.0-fastapi,
16.0-mfr_fix_base_rest_missing_argument,
and
16.0-upgrade-pre-commit |
Other repositories: |
Change2improve/rest-framework,
Digital5-Odoo/rest-framework,
Gabinete-Digital/rest-framework,
OCA/rest-framework,
SeuMarco/rest-framework,
akretion/rest-framework,
coopiteasy/rest-framework,
gastonfeng/rest-framework,
and
ursais/rest-framework |
<h1 class="title">Base Rest Datamodel</h1>
<p><a class="reference external" 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" 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" href="https://github.com/OCA/rest-framework/tree/14.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" href="https://translation.odoo-community.org/projects/rest-framework-14-0/rest-framework-14-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" href="https://runbot.odoo-community.org/runbot/271/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This addon allows you to use Pydantic objects as params and/or response with your
REST API methods.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<a name="usage"></a>
<h2><a class="toc-backref" href="#id1">Usage</a></h2>
<p>To use Pydantic instances as request and/or response of a REST service endpoint
you must:</p>
<ul class="simple">
<li>Define your Pydantic classes;</li>
<li>Provides the information required to the <code>odoo.addons.base_rest.restapi.method</code> decorator;</li>
</ul>
<pre>
<code lang="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)</code>
</pre>
<a name="bug-tracker"></a>
<h2><a class="toc-backref" href="#id2">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest_pydantic%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
<a name="credits"></a>
<h2><a class="toc-backref" href="#id3">Credits</a></h2>
<a name="authors"></a>
<h3><a class="toc-backref" href="#id4">Authors</a></h3>
<ul class="simple">
<li>ACSONE SA/NV</li>
</ul>
<a name="contributors"></a>
<h3><a class="toc-backref" href="#id5">Contributors</a></h3>
<ul class="simple">
<li>Laurent Mignon <<a class="reference external" href="mailto:laurent.mignon@acsone.eu">laurent.mignon@acsone.eu</a>></li>
</ul>
<a name="maintainers"></a>
<h3><a class="toc-backref" href="#id6">Maintainers</a></h3>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/14.0/base_rest_pydantic">OCA/rest-framework</a> project on GitHub.</p>
<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>