Skip to content

Commit 58a01b1

Browse files
committed
base_rest: api-docs add current server option
Sometimes the current domain is not what is used in web.base.url. If this is the case, show the option to use the current domain as server.
1 parent 7902d60 commit 58a01b1

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

base_rest/apispec/base_rest_service_apispec.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from apispec import APISpec
88

9+
from odoo.http import request
10+
911
from ..core import _rest_services_databases
1012
from ..tools import ROUTING_DECORATOR_ATTR
1113
from .rest_method_param_plugin import RestMethodParamPlugin
@@ -42,15 +44,24 @@ def _get_servers(self):
4244
if spec["collection_name"] == self._service._collection:
4345
collection_path = path
4446
break
45-
base_url = env["ir.config_parameter"].sudo().get_param("web.base.url")
46-
return [
47-
{
48-
"url": (
49-
f"{base_url.strip('/')}/{collection_path.strip('/')}"
50-
f"/{self._service._usage}"
51-
)
52-
}
53-
]
47+
base_domain = (
48+
env["ir.config_parameter"].sudo().get_param("web.base.url").strip("/")
49+
)
50+
current_domain = request.httprequest.url_root.strip("/")
51+
domains = [base_domain]
52+
if base_domain != current_domain:
53+
domains.append(current_domain)
54+
res = []
55+
for domain in domains:
56+
res.append(
57+
{
58+
"url": "/".join(
59+
[domain, collection_path.strip("/"), self._service._usage]
60+
)
61+
}
62+
)
63+
64+
return res
5465

5566
def _get_plugins(self):
5667
return [

0 commit comments

Comments
 (0)