OdooWiki OCA HUB

Base Rest Datamodel

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

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

auto_awesome What this module does

AI-generated from the code · Odoo 16.0

Lets developers use DataModel objects as input and output for REST API methods, with automatic validation and OpenAPI documentation.

This module is a technical bridge between the REST API framework and the DataModel library. It does not add any menu, screen, or button for end users. Instead, it changes how REST API endpoints are defined and documented.

When a REST API method is declared, developers can now specify that a parameter or a response is a DataModel object (or a list of them). The module then automatically:

  • Converts incoming JSON data into DataModel objects, ignoring unknown fields and optionally allowing partial data.
  • Validates the converted data; if validation fails, it raises a user error with the details.
  • Converts DataModel objects back into JSON for the response and validates the result before sending it.
  • Generates OpenAPI (Swagger) documentation for these parameters and responses, including query parameters, request bodies, and response schemas.

The module depends on base_rest and datamodel, and requires the Python libraries apispec and marshmallow. It touches the REST API layer only; no Odoo business models are modified.

Required by other modules

Text generated by AI (DeepSeek) from reading the Odoo 16.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 15.0

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

terminal Installation and usage

OCA documentation · Odoo 16.0

To use DataModel instances as request and/or response of a REST service endpoint you must:

  • Define your DataModel objects;
  • Provides the information required to the odoo.addons.base_rest.restapi.method decorator;
from marshmallow import fields

from odoo.addons.base_rest import restapi
from odoo.addons.component.core import Component
from odoo.addons.datamodel.core import Datamodel

class PingMessage(Datamodel):
    _name = "ping.message"

    message = fields.String(required=True, allow_none=False)


class PingService(Component):
    _inherit = 'base.rest.service'
    _name = 'ping.service'
    _usage = 'ping'
    _collection = 'my_module.services'


    @restapi.method(
        [(["/pong"], "GET")],
        input_param=restapi.Datamodel("ping.message"),
        output_param=restapi.Datamodel("ping.message"),
        auth="public",
    )
    def pong(self, ping_message):
        PingMessage = self.env.datamodels["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.