Skip to content

Commit 85bda5a

Browse files
committed
[IMP]fastapi: expose FastAPI docs only if field is set
1 parent a0da317 commit 85bda5a

File tree

5 files changed

+173
-145
lines changed

5 files changed

+173
-145
lines changed

fastapi/README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
============
62
Odoo FastAPI
73
============
@@ -17,7 +13,7 @@ Odoo FastAPI
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2218
:alt: License: LGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github

fastapi/models/fastapi_endpoint.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class FastapiEndpoint(models.Model):
6565
"unexpecteed disk space consumption.",
6666
default=True,
6767
)
68+
expose_doc_urls = fields.Boolean("Expose FastAPI docs", default=True)
6869

6970
@api.depends("root_path")
7071
def _compute_root_path(self):
@@ -150,7 +151,7 @@ def _handle_route_updates(self, vals):
150151
@api.model
151152
def _fastapi_app_fields(self) -> List[str]:
152153
"""The list of fields requiring to refresh the fastapi app if modified"""
153-
return []
154+
return ["expose_doc_urls"]
154155

155156
def _make_routing_rule(self, options=None):
156157
"""Generator of rule"""
@@ -258,12 +259,15 @@ def _get_app_dependencies_overrides(self) -> Dict[Callable, Callable]:
258259

259260
def _prepare_fastapi_app_params(self) -> Dict[str, Any]:
260261
"""Return the params to pass to the Fast API app constructor"""
261-
return {
262+
to_return = {
262263
"title": self.name,
263264
"description": self.description,
264265
"middleware": self._get_fastapi_app_middlewares(),
265266
"dependencies": self._get_fastapi_app_dependencies(),
266267
}
268+
if not self.expose_doc_urls:
269+
to_return |= {"docs_url": None, "redoc_url": None, "openapi_url": None}
270+
return to_return
267271

268272
def _get_fastapi_routers(self) -> List[APIRouter]:
269273
"""Return the api routers to use for the instance.

0 commit comments

Comments
 (0)