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
12 changes: 7 additions & 5 deletions fastapi/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

============
Odoo FastAPI
============
Expand All @@ -17,7 +13,7 @@ Odoo FastAPI
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
: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
Expand Down Expand Up @@ -251,6 +247,12 @@ Now, you can start your Odoo server, install your addon and create a new endpoin
instance for your app. Once it's done click on the docs url to access the
interactive documentation of your app.

**Note**: FastAPI automatically exposes three services to easily interact with
the APIs and their structure (Swagger, Redoc, OpenAPI).
When exposing your Odoo instance to the open internet you might want to disable
these services. To do so toggle the "Expose FastAPI docs" checkbox in the FastAPI
Endpoint form view.

Before trying to test your app, you need to define on the endpoint instance the
user that will be used to run the app. You can do it by setting the **'user_id'**
field. This information is the most important one because it's the basis for
Expand Down
8 changes: 6 additions & 2 deletions fastapi/models/fastapi_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class FastapiEndpoint(models.Model):
"unexpecteed disk space consumption.",
default=True,
)
expose_doc_urls = fields.Boolean("Expose FastAPI docs", default=True)

@api.depends("root_path")
def _compute_root_path(self):
Expand Down Expand Up @@ -150,7 +151,7 @@ def _handle_route_updates(self, vals):
@api.model
def _fastapi_app_fields(self) -> List[str]:
"""The list of fields requiring to refresh the fastapi app if modified"""
return []
return ["expose_doc_urls"]

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

def _prepare_fastapi_app_params(self) -> Dict[str, Any]:
"""Return the params to pass to the Fast API app constructor"""
return {
to_return = {
"title": self.name,
"description": self.description,
"middleware": self._get_fastapi_app_middlewares(),
"dependencies": self._get_fastapi_app_dependencies(),
}
if not self.expose_doc_urls:
to_return |= {"docs_url": None, "redoc_url": None, "openapi_url": None}
return to_return

def _get_fastapi_routers(self) -> List[APIRouter]:
"""Return the api routers to use for the instance.
Expand Down
6 changes: 6 additions & 0 deletions fastapi/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ Now, you can start your Odoo server, install your addon and create a new endpoin
instance for your app. Once it's done click on the docs url to access the
interactive documentation of your app.

**Note**: FastAPI automatically exposes three services to easily interact with
the APIs and their structure (Swagger, Redoc, OpenAPI).
When exposing your Odoo instance to the open internet you might want to disable
these services. To do so toggle the "Expose FastAPI docs" checkbox in the FastAPI
Endpoint form view.

Before trying to test your app, you need to define on the endpoint instance the
user that will be used to run the app. You can do it by setting the **'user_id'**
field. This information is the most important one because it's the basis for
Expand Down
Loading