OdooWiki OCA HUB

Base Rest Datamodel

base_rest_pydantic folder_open OCA/rest-framework open_in_new
Uncategorised License: LGPL-3

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

auto_awesome What this module does

AI-generated from the code · Odoo 18.0

This module lets developers use Pydantic data models as input and output for REST API methods in Odoo, adding automatic validation and OpenAPI documentation. It does not add any screen or menu for end users.

This is a technical add-on for the REST API framework (base_rest). It does not add menus, buttons, reports or business rules that a normal Odoo user would see. Instead, it changes how API endpoints are built and documented.

  • It allows API methods to accept structured data models (Pydantic models) as parameters and to return them as responses.
  • Incoming data is automatically validated; if it does not match the expected model, the request is rejected with a "BadRequest" error.
  • Outgoing data is also validated before being sent; if it does not match the expected model, an "Invalid Response" error is raised.
  • It supports lists of models, with optional minimum and maximum number of items, and a flag to document that items should be unique (not enforced).
  • It automatically generates OpenAPI documentation for these models, including query parameters, request bodies and responses, so API consumers can see the expected structure.

The module depends on the Python library pydantic version 2.0 or higher. It touches the REST API layer only; no Odoo models are added or modified.

Depends on

Required by other modules

Text generated by AI (DeepSeek) from reading the Odoo 18.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 5 confirmed, 4 with no information of 9 versions.

Sources · Odoo 14.0

Confirmed on 2026-11-03 in branch 14.0 of OCA/rest-framework.

terminal Installation and usage

OCA documentation · Odoo 18.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;
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)

No verified information in OCA: Installation, Configuration.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.