Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^base_rest/|
^base_rest_auth_api_key/|
^base_rest_pydantic/|
^extendable/|
Expand Down
87 changes: 44 additions & 43 deletions base_rest/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Base Rest
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
:target: https://github.com/OCA/rest-framework/tree/18.0/base_rest
:target: https://github.com/OCA/rest-framework/tree/19.0/base_rest
:alt: OCA/rest-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest
:target: https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-0-base_rest
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -89,8 +89,8 @@ Usage

To add your own REST service you must provides at least 2 classes.

- A Component providing the business logic of your service,
- A Controller to register your service.
- A Component providing the business logic of your service,
- A Controller to register your service.

The business logic of your service must be implemented into a component
(``odoo.addons.component.core.Component``) that inherit from
Expand All @@ -99,22 +99,22 @@ The business logic of your service must be implemented into a component
Initially, base_rest expose by default all public methods defined in a
service. The conventions for accessing methods via HTTP were as follows:

- The method ``def get(self, _id)`` if defined, is accessible via HTTP
GET routes ``<string:_service_name>/<int:_id>`` and
``<string:_service_name>/<int:_id>/get``.
- The method ``def search(self, **params)`` if defined, is accessible
via the HTTP GET routes ``<string:_service_name>/`` and
``<string:_service_name>/search``.
- The method ``def delete(self, _id)`` if defined, is accessible via the
HTTP DELETE route ``<string:_service_name>/<int:_id>``.
- The ``def update(self, _id, **params)`` method, if defined, is
accessible via the HTTP PUT route
``<string:_service_name>/<int:_id>``.
- Other methods are only accessible via HTTP POST routes
``<string:_service_name>`` or
``<string:_service_name>/<string:method_name>`` or
``<string:_service_name>/<int:_id>`` or
``<string:_service_name>/<int:_id>/<string:method_name>``
- The method ``def get(self, _id)`` if defined, is accessible via HTTP
GET routes ``<string:_service_name>/<int:_id>`` and
``<string:_service_name>/<int:_id>/get``.
- The method ``def search(self, **params)`` if defined, is accessible
via the HTTP GET routes ``<string:_service_name>/`` and
``<string:_service_name>/search``.
- The method ``def delete(self, _id)`` if defined, is accessible via
the HTTP DELETE route ``<string:_service_name>/<int:_id>``.
- The ``def update(self, _id, **params)`` method, if defined, is
accessible via the HTTP PUT route
``<string:_service_name>/<int:_id>``.
- Other methods are only accessible via HTTP POST routes
``<string:_service_name>`` or
``<string:_service_name>/<string:method_name>`` or
``<string:_service_name>/<int:_id>`` or
``<string:_service_name>/<int:_id>/<string:method_name>``

.. code:: python

Expand Down Expand Up @@ -231,10 +231,10 @@ schemas <https://docs.python-cerberus.org/en/stable/>`__ and associated
to the methods using the following naming convention. For a method
\`my_method\`:

- ``def _validator_my_method(self):`` will be called to get the schema
required to validate the input parameters.
- ``def _validator_return_my_method(self):`` if defined, will be called
to get the schema used to validate the response.
- ``def _validator_my_method(self):`` will be called to get the schema
required to validate the input parameters.
- ``def _validator_return_my_method(self):`` if defined, will be called
to get the schema used to validate the response.

In order to offer even more flexibility, a new API has been developed.

Expand Down Expand Up @@ -363,32 +363,33 @@ Changelog

**Features**

- Add support for oauth2 security scheme in the Swagger UI. If your
openapi specification contains a security scheme of type oauth2, the
Swagger UI will display a login button in the top right corner. In
order to finalize the login process, a redirect URL must be provided
when initializing the Swagger UI. The Swagger UI is now initialized
with a oauth2RedirectUrl option that references a oauth2-redirect.html
file provided by the swagger-ui lib and served by the current addon.
(`#379 <https://github.com/OCA/rest-framework/issues/379>`__)
- Add support for oauth2 security scheme in the Swagger UI. If your
openapi specification contains a security scheme of type oauth2, the
Swagger UI will display a login button in the top right corner. In
order to finalize the login process, a redirect URL must be provided
when initializing the Swagger UI. The Swagger UI is now initialized
with a oauth2RedirectUrl option that references a
oauth2-redirect.html file provided by the swagger-ui lib and served
by the current addon.
(`#379 <https://github.com/OCA/rest-framework/issues/379>`__)

12.0.2.0.1
----------

- validator\_...() methods can now return a cerberus ``Validator``
object instead of a schema dictionnary, for additional flexibility
(e.g. allowing validator options such as ``allow_unknown``).
- validator\_...() methods can now return a cerberus ``Validator``
object instead of a schema dictionnary, for additional flexibility
(e.g. allowing validator options such as ``allow_unknown``).

12.0.2.0.0
----------

- Licence changed from AGPL-3 to LGPL-3
- Licence changed from AGPL-3 to LGPL-3

12.0.1.0.1
----------

- Fix issue when rendering the jsonapi documentation if no documentation
is provided on a method part of the REST api.
- Fix issue when rendering the jsonapi documentation if no
documentation is provided on a method part of the REST api.

12.0.1.0.0
----------
Expand All @@ -404,7 +405,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand All @@ -419,8 +420,8 @@ Authors
Contributors
------------

- Laurent Mignon <laurent.mignon@acsone.eu>
- Sébastien Beau <sebastien.beau@akretion.com>
- Laurent Mignon <laurent.mignon@acsone.eu>
- Sébastien Beau <sebastien.beau@akretion.com>

Maintainers
-----------
Expand All @@ -435,6 +436,6 @@ 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.

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/base_rest>`_ project on GitHub.
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/19.0/base_rest>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion base_rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import models
from . import components
from . import models
from . import http
19 changes: 13 additions & 6 deletions base_rest/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
"summary": """
Develop your own high level REST APIs for Odoo thanks to this addon.
""",
"version": "18.0.1.1.1",
"version": "19.0.1.0.0",
"development_status": "Beta",
"license": "LGPL-3",
"author": "ACSONE SA/NV, " "Odoo Community Association (OCA)",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"maintainers": [],
"website": "https://github.com/OCA/rest-framework",
"depends": ["component", "web"],
"depends": ["bus", "component", "web", "web_tour"],
"data": [
"views/openapi_template.xml",
"views/base_rest_view.xml",
],
"assets": {
"web.assets_frontend": [
"base_rest/static/src/scss/base_rest.scss",
"base_rest/static/src/js/swagger_ui.js",
"base_rest/static/src/js/swagger.js",
],
"web.assets_tests": [
"base_rest/static/tests/tours/**/*.js",
],
"base_rest.assets_tour_openapi": [
("include", "web._assets_helpers"),
("include", "web._assets_frontend_helpers"),
("include", "web._assets_primary_variables"),
("include", "web.assets_frontend"),
("include", "web.assets_tests"),
],
},
"external_dependencies": {
Expand All @@ -33,5 +41,4 @@
"apispec",
]
},
"installable": False,
}
3 changes: 1 addition & 2 deletions base_rest/components/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def _get_openapi_default_responses(self):
return {
"400": {"description": "One of the given parameter is not valid"},
"401": {
"description": "The user is not authorized. Authentication "
"is required"
"description": "The user is not authorized. Authentication is required"
},
"404": {"description": "Requested resource not found"},
"403": {
Expand Down
2 changes: 1 addition & 1 deletion base_rest/controllers/api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def index(self, **params):
self._get_api_urls()
primary_name = params.get("urls.primaryName")
swagger_settings = {
"urls": self._get_api_urls(),
"urls": self._get_api_urls() or None,
"urls.primaryName": primary_name,
}
values = {"swagger_settings": swagger_settings}
Expand Down
4 changes: 2 additions & 2 deletions base_rest/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
ValidationError,
)
from odoo.http import (
CSRF_FREE_METHODS,
MISSING_CSRF_WARNING,
SAFE_HTTP_METHODS,
Dispatcher,
SessionExpiredException,
request,
Expand Down Expand Up @@ -162,7 +162,7 @@ def dispatch(self, endpoint, args):

# Check for CSRF token for relevant requests
if (
self.request.httprequest.method not in CSRF_FREE_METHODS
self.request.httprequest.method not in SAFE_HTTP_METHODS
and endpoint.routing.get("csrf", True)
):
token = params.pop("csrf_token", None)
Expand Down
8 changes: 4 additions & 4 deletions base_rest/models/rest_service_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,18 @@ def build_registry(self, services_registry, states=None, exclude_addons=None):
# dependencies to ensure that controllers defined in a more
# specialized addon and overriding more generic one takes precedences
# on the generic one into the registry
graph = odoo.modules.graph.Graph()
graph.add_module(self.env.cr, "base")
graph = odoo.modules.module_graph.ModuleGraph(self.env.cr)
graph.extend(["base"])

query = "SELECT name " "FROM ir_module_module " "WHERE state IN %s "
query = "SELECT name FROM ir_module_module WHERE state IN %s "
params = [tuple(states)]
if exclude_addons:
query += " AND name NOT IN %s "
params.append(tuple(exclude_addons))
self.env.cr.execute(query, params)

module_list = [name for (name,) in self.env.cr.fetchall() if name not in graph]
graph.add_modules(self.env.cr, module_list)
graph.extend(module_list)

for module in graph:
self.load_services(module.name, services_registry)
Expand Down
12 changes: 8 additions & 4 deletions base_rest/restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ def from_params(self, service, params):
validator = self.get_cerberus_validator(service, "input")
if validator.validate(params):
return validator.document
raise UserError(service.env._("BadRequest %s") % validator.errors)
raise UserError(service.env._("BadRequest %s", validator.errors))

def to_response(self, service, result):
validator = self.get_cerberus_validator(service, "output")
if validator.validate(result):
return validator.document
raise SystemError(service.env._("Invalid Response %s") % validator.errors)
raise SystemError(service.env._("Invalid Response %s", validator.errors))

def to_openapi_query_parameters(self, service, spec):
json_schema = self.to_json_schema(service, spec, "input")
Expand Down Expand Up @@ -276,7 +276,7 @@ def get_cerberus_validator(self, service, direction):
if isinstance(schema, dict):
return Validator(schema, purge_unknown=True)
raise Exception(
service.env._("Unable to get cerberus schema from %s") % self._schema
service.env._("Unable to get cerberus schema from %s", self._schema)
)

def to_json_schema(self, service, spec, direction):
Expand Down Expand Up @@ -412,7 +412,11 @@ def from_params(self, service, params):
) # multipart ony sends its parts as string
except json.JSONDecodeError as error:
raise ValidationError(
service.env._(f"{key}'s JSON content is malformed: {error}")
service.env._(
"%(key)s's JSON content is malformed: %(error)s",
key=key,
error=error,
)
) from error
param = part.from_params(service, json_param)
params[key] = param
Expand Down
Loading
Loading