Skip to content

Commit e634810

Browse files
committed
Merge PR #537 into 16.0
Signed-off-by lmignon
2 parents 1390f0d + 4eea801 commit e634810

6 files changed

Lines changed: 199 additions & 145 deletions

File tree

fastapi/README.rst

Lines changed: 7 additions & 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
@@ -251,6 +247,12 @@ Now, you can start your Odoo server, install your addon and create a new endpoin
251247
instance for your app. Once it's done click on the docs url to access the
252248
interactive documentation of your app.
253249

250+
**Note**: FastAPI automatically exposes three services to easily interact with
251+
the APIs and their structure (Swagger, Redoc, OpenAPI).
252+
When exposing your Odoo instance to the open internet you might want to disable
253+
these services. To do so toggle the "Expose FastAPI docs" checkbox in the FastAPI
254+
Endpoint form view.
255+
254256
Before trying to test your app, you need to define on the endpoint instance the
255257
user that will be used to run the app. You can do it by setting the **'user_id'**
256258
field. This information is the most important one because it's the basis for

fastapi/models/fastapi_endpoint.py

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

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

154155
def _make_routing_rule(self, options=None):
155156
"""Generator of rule"""
@@ -325,12 +326,15 @@ def _get_app_dependencies_overrides(self) -> Dict[Callable, Callable]:
325326

326327
def _prepare_fastapi_app_params(self) -> Dict[str, Any]:
327328
"""Return the params to pass to the Fast API app constructor"""
328-
return {
329+
to_return = {
329330
"title": self.name,
330331
"description": self.description,
331332
"middleware": self._get_fastapi_app_middlewares(),
332333
"dependencies": self._get_fastapi_app_dependencies(),
333334
}
335+
if not self.expose_doc_urls:
336+
to_return |= {"docs_url": None, "redoc_url": None, "openapi_url": None}
337+
return to_return
334338

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

fastapi/readme/USAGE.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ Now, you can start your Odoo server, install your addon and create a new endpoin
170170
instance for your app. Once it's done click on the docs url to access the
171171
interactive documentation of your app.
172172

173+
**Note**: FastAPI automatically exposes three services to easily interact with
174+
the APIs and their structure (Swagger, Redoc, OpenAPI).
175+
When exposing your Odoo instance to the open internet you might want to disable
176+
these services. To do so toggle the "Expose FastAPI docs" checkbox in the FastAPI
177+
Endpoint form view.
178+
173179
Before trying to test your app, you need to define on the endpoint instance the
174180
user that will be used to run the app. You can do it by setting the **'user_id'**
175181
field. This information is the most important one because it's the basis for

0 commit comments

Comments
 (0)