Skip to content

Commit 640e90e

Browse files
[MIG] base_rest, base_rest_auth_api_key, base_rest_datamodel, base_rest_demo, base_rest_pydantic, datamodel, extendable: Migration to 16.0
Co-authored-by: Nikul-OSI <nchaudhary@opensourceintegrators.com>
1 parent e58a391 commit 640e90e

35 files changed

+357
-238
lines changed

base_rest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from . import models
23
from . import components
34
from . import http

base_rest/__manifest__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"summary": """
77
Develop your own high level REST APIs for Odoo thanks to this addon.
88
""",
9-
"version": "15.0.1.2.0",
9+
"version": "16.0.1.0.0",
1010
"development_status": "Beta",
1111
"license": "LGPL-3",
1212
"author": "ACSONE SA/NV, " "Odoo Community Association (OCA)",
@@ -18,18 +18,19 @@
1818
"views/base_rest_view.xml",
1919
],
2020
"assets": {
21-
"web.assets_common": [
21+
"web.assets_frontend": [
2222
"base_rest/static/src/scss/base_rest.scss",
2323
"base_rest/static/src/js/swagger_ui.js",
24+
"base_rest/static/src/js/swagger.js",
2425
],
2526
},
26-
"demo": [],
2727
"external_dependencies": {
2828
"python": [
2929
"cerberus",
3030
"pyquerystring",
3131
"parse-accept-language",
32-
"apispec>=4.0.0",
32+
# adding version causes missing-manifest-dependency false positives
33+
"apispec",
3334
]
3435
},
3536
"installable": True,

base_rest/apispec/base_rest_service_apispec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ def _get_plugins(self):
6262

6363
def _add_method_path(self, method):
6464
description = textwrap.dedent(method.__doc__ or "")
65-
routing = method.routing
65+
routing = method.original_routing
6666
for paths, method in routing["routes"]:
6767
for path in paths:
6868
self.path(
6969
path,
7070
operations={method.lower(): {"summary": description}},
71-
routing=routing,
71+
original_routing=routing,
7272
)
7373

7474
def generate_paths(self):
7575
for _name, method in inspect.getmembers(self._service, inspect.ismethod):
76-
routing = getattr(method, "routing", None)
76+
routing = getattr(method, "original_routing", None)
7777
if not routing:
7878
continue
7979
self._add_method_path(method)

base_rest/apispec/rest_method_param_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ def init_spec(self, spec):
2525
self.openapi_version = spec.openapi_version
2626

2727
def operation_helper(self, path=None, operations=None, **kwargs):
28-
routing = kwargs.get("routing")
28+
routing = kwargs.get("original_routing")
2929
if not routing:
3030
super(RestMethodParamPlugin, self).operation_helper(
3131
path, operations, **kwargs
3232
)
3333
if not operations:
3434
return
3535
for method, params in operations.items():
36-
parameters = self._generate_pamareters(routing, method, params)
36+
parameters = self._generate_parameters(routing, method, params)
3737
if parameters:
3838
params["parameters"] = parameters
3939
responses = self._generate_responses(routing, method, params)
4040
if responses:
4141
params["responses"] = responses
4242

43-
def _generate_pamareters(self, routing, method, params):
43+
def _generate_parameters(self, routing, method, params):
4444
parameters = params.get("parameters", [])
4545
# add default paramters provided by the sevice
4646
parameters.extend(self._default_parameters)

base_rest/apispec/rest_method_security_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def init_spec(self, spec):
2323
spec.components.security_scheme("user", user_scheme)
2424

2525
def operation_helper(self, path=None, operations=None, **kwargs):
26-
routing = kwargs.get("routing")
26+
routing = kwargs.get("original_routing")
2727
if not routing:
2828
super(RestMethodSecurityPlugin, self).operation_helper(
2929
path, operations, **kwargs

base_rest/components/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _prepare_input_params(self, method, params):
9393
method_name = method.__name__
9494
if hasattr(method, "skip_secure_params"):
9595
return params
96-
routing = getattr(method, "routing", None)
96+
routing = getattr(method, "original_routing", None)
9797
if not routing:
9898
_logger.warning(
9999
"Method %s is not a public method of service %s",
@@ -122,7 +122,7 @@ def _prepare_response(self, method, result):
122122
method_name = method.__name__
123123
if hasattr(method, "skip_secure_response"):
124124
return result
125-
routing = getattr(method, "routing", None)
125+
routing = getattr(method, "original_routing", None)
126126
output_param = routing["output_param"]
127127
if not output_param:
128128
_logger.warning(

base_rest/controllers/main.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from werkzeug.exceptions import BadRequest
88

99
from odoo import models
10-
from odoo.http import Controller, ControllerType, Response, request
10+
from odoo.http import Controller, Response, request
1111

1212
from odoo.addons.component.core import WorkContext, _get_addon_name
1313

@@ -25,43 +25,7 @@ def __init__(self, name, env):
2525
self.id = None
2626

2727

28-
class RestControllerType(ControllerType):
29-
30-
# pylint: disable=E0213
31-
def __init__(cls, name, bases, attrs): # noqa: B902
32-
if (
33-
"RestController" in globals()
34-
and RestController in bases
35-
and Controller not in bases
36-
):
37-
# to be registered as a controller into the ControllerType,
38-
# our RestConrtroller must be a direct child of Controller
39-
bases += (Controller,)
40-
super(RestControllerType, cls).__init__(name, bases, attrs)
41-
if "RestController" not in globals() or not any(
42-
issubclass(b, RestController) for b in bases
43-
):
44-
return
45-
# register the rest controller into the rest controllers registry
46-
root_path = getattr(cls, "_root_path", None)
47-
collection_name = getattr(cls, "_collection_name", None)
48-
if root_path and collection_name:
49-
cls._module = _get_addon_name(cls.__module__)
50-
_rest_controllers_per_module[cls._module].append(
51-
{
52-
"root_path": root_path,
53-
"collection_name": collection_name,
54-
"controller_class": cls,
55-
}
56-
)
57-
_logger.debug(
58-
"Added rest controller %s for module %s",
59-
_rest_controllers_per_module[cls._module][-1],
60-
cls._module,
61-
)
62-
63-
64-
class RestController(Controller, metaclass=RestControllerType):
28+
class RestController(Controller):
6529
"""Generic REST Controller
6630
6731
This controller is the base controller used by as base controller for all the REST
@@ -130,6 +94,38 @@ class ControllerB(ControllerB):
13094

13195
_component_context_provider = "component_context_provider"
13296

97+
@classmethod
98+
def __init_subclass__(cls):
99+
if (
100+
"RestController" in globals()
101+
and RestController in cls.__bases__
102+
and Controller not in cls.__bases__
103+
):
104+
# Ensure that Controller's __init_subclass__ kicks in.
105+
cls.__bases__ += (Controller,)
106+
super().__init_subclass__()
107+
if "RestController" not in globals() or not any(
108+
issubclass(b, RestController) for b in cls.__bases__
109+
):
110+
return
111+
# register the rest controller into the rest controllers registry
112+
root_path = getattr(cls, "_root_path", None)
113+
collection_name = getattr(cls, "_collection_name", None)
114+
if root_path and collection_name:
115+
cls._module = _get_addon_name(cls.__module__)
116+
_rest_controllers_per_module[cls._module].append(
117+
{
118+
"root_path": root_path,
119+
"collection_name": collection_name,
120+
"controller_class": cls,
121+
}
122+
)
123+
_logger.debug(
124+
"Added rest controller %s for module %s",
125+
_rest_controllers_per_module[cls._module][-1],
126+
cls._module,
127+
)
128+
133129
def _get_component_context(self, collection=None):
134130
"""
135131
This method can be inherited to add parameter into the component

0 commit comments

Comments
 (0)