Maintainers
+Maintainers
This module is maintained by the OCA.
@@ -1971,6 +1971,5 @@ diff --git a/fastapi/README.rst b/fastapi/README.rst index 7c164592c..f7c133f41 100644 --- a/fastapi/README.rst +++ b/fastapi/README.rst @@ -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 ============ @@ -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 @@ -263,6 +259,12 @@ Now, you can start your Odoo server, install your addon and create a new endpoint 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 diff --git a/fastapi/models/fastapi_endpoint.py b/fastapi/models/fastapi_endpoint.py index 660bb2c5d..a907ceadc 100644 --- a/fastapi/models/fastapi_endpoint.py +++ b/fastapi/models/fastapi_endpoint.py @@ -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): @@ -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""" @@ -321,12 +322,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. diff --git a/fastapi/readme/USAGE.md b/fastapi/readme/USAGE.md index 131d7f7b5..c53513a9d 100644 --- a/fastapi/readme/USAGE.md +++ b/fastapi/readme/USAGE.md @@ -178,6 +178,12 @@ Now, you can start your Odoo server, install your addon and create a new endpoint 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 diff --git a/fastapi/static/description/index.html b/fastapi/static/description/index.html index 9a7aefbae..446842b45 100644 --- a/fastapi/static/description/index.html +++ b/fastapi/static/description/index.html @@ -360,21 +360,16 @@
-This addon provides the basis to smoothly integrate the FastAPI framework into Odoo.
This integration allows you to use all the goodies from @@ -487,9 +482,9 @@
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints. This addons let’s you keep advantage of the fastapi framework and use it with Odoo.
@@ -653,6 +648,11 @@Now, you can start your Odoo server, install your addon and create a new endpoint 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 @@ -705,7 +705,7 @@
The ‘odoo.addons.fastapi.dependencies’ module provides a set of functions that you can use to inject reusable dependencies into your routes. For example, the ‘odoo_env’ function returns the current @@ -756,7 +756,7 @@
The ‘odoo_env’ dependency relies on a simple implementation that retrieves the current odoo environment from ContextVar variable initialized at the start of the request processing by the specific @@ -809,7 +809,7 @@
To make our app not tightly coupled with a specific authentication mechanism, we will use the ‘authenticated_partner’ dependency. As for the ‘fastapi_endpoint’ this dependency depends on an abstract @@ -974,7 +974,7 @@
As we have seen in the previous section, you can add configuration fields on the fastapi endpoint model to allow the user to configure your app (as for any odoo model you extend). When you need to access these @@ -1040,7 +1040,7 @@
The fastapi addon parses the Accept-Language header of the request to
determine the language to use. This parsing is done by respecting the
RFC 7231
@@ -1055,7 +1055,7 @@ Dealing with languages
app to instruct the api consumers how to request a specific language.
When you develop a fastapi app, in a native python app it’s not possible to extend an existing one. This limitation doesn’t apply to the fastapi addon because the fastapi endpoint model is designed to be extended. @@ -1084,7 +1084,7 @@
Let’s see how to do that.
Let’s say that you want to change the implementation of the route handler ‘/demo/echo’. Since a route handler is just a python method, it could seems a tedious task since we are not into a model method and @@ -1152,7 +1152,7 @@
As you’ve previously seen, the dependency injection mechanism of fastapi is very powerful. By designing your route handler to rely on dependencies with a specific functional scope, you can easily change the @@ -1165,7 +1165,7 @@
Let’s say that you want to add a new route handler ‘/demo/echo2’. You could be tempted to add this new route handler in your new addons by importing the router of the existing app and adding the new route @@ -1223,7 +1223,7 @@
The fastapi python library uses the pydantic library to define the models. By default, once a model is defined, it’s not possible to extend it. However, a companion python library called @@ -1294,7 +1294,7 @@
By default the route handlers are processed using the user configured on the ‘fastapi.endpoint’ model instance. (default is the Public user). You have seen previously how to define a dependency that will be used to @@ -1367,7 +1367,7 @@
Thanks to the starlette test client, it’s possible to test your fastapi app in a very simple way. With the test client, you can call your route handlers as if they were real http endpoints. The test client is @@ -1438,7 +1438,7 @@
Developing a fastapi app requires to follow some good practices to ensure that the app is robust and easy to maintain. Here are some of them:
@@ -1563,9 +1563,9 @@The ‘odoo-addon-fastapi’ module provides 2 useful piece of code to help you be consistent when writing a route handler for a search route.
The error handling is a very important topic in the design of the fastapi integration with odoo. By default, when instantiating the fastapi app, the fastapi library declare a default exception handler @@ -1634,7 +1634,7 @@
When you develop a new addon to expose an api with fastapi, it’s a good practice to follow the same directory structure and naming convention for the files related to the api. It will help you to easily find the @@ -1743,7 +1743,7 @@
The ‘odoo-addon-fastapi’ module is still in its early stage of development. It will evolve over time to integrate your feedback and to provide the missing features. It’s now up to you to try it and to @@ -1751,7 +1751,7 @@
The
roadmap
and known
@@ -1766,11 +1766,11 @@ Known issues / Roadmap
WebSockets and to stream large responses.
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -1941,22 +1941,22 @@
Do not contact contributors directly about support or help with technical issues.