diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d5b36e76..8b7b498eb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: | (?x) # NOT INSTALLABLE ADDONS - ^extendable/| + ^fastapi_auth_jwt_demo/| # END NOT INSTALLABLE ADDONS # Files and folders generated by bots, to avoid loops ^setup/|/static/description/index\.html$| diff --git a/base_rest/README.rst b/base_rest/README.rst index 5f93be562..2dad8464f 100644 --- a/base_rest/README.rst +++ b/base_rest/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 - ========= Base Rest ========= @@ -17,7 +13,7 @@ Base Rest .. |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 diff --git a/base_rest/__manifest__.py b/base_rest/__manifest__.py index f52490813..584dae570 100644 --- a/base_rest/__manifest__.py +++ b/base_rest/__manifest__.py @@ -20,8 +20,7 @@ "assets": { "web.assets_frontend": [ "base_rest/static/src/scss/base_rest.scss", - "base_rest/static/src/js/swagger_ui.js", - "base_rest/static/src/js/swagger.js", + "base_rest/static/src/js/components/swagger_ui.esm.js", ], }, "external_dependencies": { diff --git a/base_rest/static/description/index.html b/base_rest/static/description/index.html index 11068ef2a..b7b999a91 100644 --- a/base_rest/static/description/index.html +++ b/base_rest/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Base Rest -
+
+

Base Rest

- - -Odoo Community Association - -
-

Base Rest

-

Beta License: LGPL-3 OCA/rest-framework Translate me on Weblate Try me on Runboat

+

Beta License: LGPL-3 OCA/rest-framework Translate me on Weblate Try me on Runboat

This addon is deprecated and not fully supported anymore from Odoo 16. Please migrate to the FastAPI migration module. See https://github.com/OCA/rest-framework/pull/291.

@@ -414,7 +409,7 @@

Base Rest

-

Configuration

+

Configuration

If an error occurs when calling a method of a service (ie missing parameter, ..) the system returns only a general description of the problem without details. This is done on purpose to ensure maximum @@ -436,7 +431,7 @@

Configuration

mode in production.

-

Usage

+

Usage

To add your own REST service you must provides at least 2 classes.

  • A Component providing the business logic of your service,
  • @@ -466,10 +461,10 @@

    Usage

    <string:_service_name>/<int:_id>/<string:method_name>
-from odoo.addons.component.core import Component
+from odoo.addons.component.core import Component
 
 
-class PingService(Component):
+class PingService(Component):
     _inherit = 'base.rest.service'
     _name = 'ping.service'
     _usage = 'ping'
@@ -477,37 +472,37 @@ 

Usage

# The following method are 'public' and can be called from the controller. - def get(self, _id, message): + def get(self, _id, message): return { 'response': 'Get called with message ' + message} - def search(self, message): + def search(self, message): return { 'response': 'Search called search with message ' + message} - def update(self, _id, message): + def update(self, _id, message): return {'response': 'PUT called with message ' + message} # pylint:disable=method-required-super - def create(self, **params): + def create(self, **params): return {'response': 'POST called with message ' + params['message']} - def delete(self, _id): + def delete(self, _id): return {'response': 'DELETE called with id %s ' % _id} # Validator - def _validator_search(self): + def _validator_search(self): return {'message': {'type': 'string'}} # Validator - def _validator_get(self): + def _validator_get(self): # no parameters by default return {} - def _validator_update(self): + def _validator_update(self): return {'message': {'type': 'string'}} - def _validator_create(self): + def _validator_create(self): return {'message': {'type': 'string'}}

Once you have implemented your services (ping, …), you must tell to @@ -515,9 +510,9 @@

Usage

implementing a controller that inherits from odoo.addons.base_rest.controllers.main.RestController

-from odoo.addons.base_rest.controllers import main
+from odoo.addons.base_rest.controllers import main
 
-class MyRestController(main.RestController):
+class MyRestController(main.RestController):
     _root_path = '/my_services_api/'
     _collection_name = my_module.services
 
@@ -533,7 +528,7 @@

Usage

ROOT_PATH + '<string:_service_name>/<int:_id>', ROOT_PATH + '<string:_service_name>/<int:_id>/get' ], methods=['GET'], auth="user", csrf=False) -def get(self, _service_name, _id=None, **params): +def get(self, _service_name, _id=None, **params): method_name = 'get' if _id else 'search' return self._process_method(_service_name, method_name, _id, params) @@ -543,7 +538,7 @@

Usage

ROOT_PATH + '<string:_service_name>/<int:_id>', ROOT_PATH + '<string:_service_name>/<int:_id>/<string:method_name>' ], methods=['POST'], auth="user", csrf=False) -def modify(self, _service_name, _id=None, method_name=None, **params): +def modify(self, _service_name, _id=None, method_name=None, **params): if not method_name: method_name = 'update' if _id else 'create' if method_name == 'get': @@ -555,13 +550,13 @@

Usage

@route([ ROOT_PATH + '<string:_service_name>/<int:_id>', ], methods=['PUT'], auth="user", csrf=False) -def update(self, _service_name, _id, **params): +def update(self, _service_name, _id, **params): return self._process_method(_service_name, 'update', _id, params) @route([ ROOT_PATH + '<string:_service_name>/<int:_id>', ], methods=['DELETE'], auth="user", csrf=False) -def delete(self, _service_name, _id): +def delete(self, _service_name, _id): return self._process_method(_service_name, 'delete', _id)

As result an HTTP GET call to ‘http://my_odoo/my_services_api/ping’ will @@ -583,7 +578,7 @@

Usage

the use of a python decorator to explicitly mark a method as being available via the REST API: odoo.addons.base_rest.restapi.method.

-class PartnerNewApiService(Component):
+class PartnerNewApiService(Component):
     _inherit = "base.rest.service"
     _name = "partner.new_api.service"
     _usage = "partner"
@@ -598,10 +593,10 @@ 

Usage

output_param=restapi.CerberusValidator("_get_partner_schema"), auth="public", ) - def get(self, _id): + def get(self, _id): return {"name": self.env["res.partner"].browse(_id).name} - def _get_partner_schema(self): + def _get_partner_schema(self): return { "name": {"type": "string", "required": True} } @@ -611,7 +606,7 @@

Usage

output_param=restapi.CerberusListValidator("_get_partner_schema"), auth="public", ) - def list(self): + def list(self): partners = self.env["res.partner"].search([]) return [{"name": p.name} for p in partners]
@@ -620,28 +615,28 @@

Usage

For example, base_rest_datamodel allows you to use Datamodel object instance into your services.

-from marshmallow import fields
+from marshmallow import fields
 
-from odoo.addons.base_rest import restapi
-from odoo.addons.component.core import Component
-from odoo.addons.datamodel.core import Datamodel
+from odoo.addons.base_rest import restapi
+from odoo.addons.component.core import Component
+from odoo.addons.datamodel.core import Datamodel
 
 
-class PartnerSearchParam(Datamodel):
+class PartnerSearchParam(Datamodel):
     _name = "partner.search.param"
 
     id = fields.Integer(required=False, allow_none=False)
     name = fields.String(required=False, allow_none=False)
 
 
-class PartnerShortInfo(Datamodel):
+class PartnerShortInfo(Datamodel):
     _name = "partner.short.info"
 
     id = fields.Integer(required=True, allow_none=False)
     name = fields.String(required=True, allow_none=False)
 
 
-class PartnerNewApiService(Component):
+class PartnerNewApiService(Component):
     _inherit = "base.rest.service"
     _name = "partner.new_api.service"
     _usage = "partner"
@@ -657,7 +652,7 @@ 

Usage

output_param=restapi.Datamodel("partner.short.info", is_list=True), auth="public", ) - def search(self, partner_search_param): + def search(self, partner_search_param): """ Search for partners :param partner_search_param: An instance of partner.search.param @@ -683,7 +678,7 @@

Usage

evaluation context.

-

Changelog

+

Changelog

-

16.0.1.0.2 (2023-10-07)

+

16.0.1.0.2 (2023-10-07)

Features

-

12.0.2.0.1

+

12.0.2.0.1

  • validator_…() methods can now return a cerberus Validator object instead of a schema dictionnary, for additional flexibility @@ -715,20 +710,20 @@

    12.0.2.0.1

-

12.0.2.0.0

+

12.0.2.0.0

  • Licence changed from AGPL-3 to LGPL-3
-

12.0.1.0.1

+

12.0.1.0.1

  • Fix issue when rendering the jsonapi documentation if no documentation is provided on a method part of the REST api.
-

12.0.1.0.0

+

12.0.1.0.0

First official version. The addon has been incubated into the Shopinvader repository from @@ -736,7 +731,7 @@

12.0.1.0.0

-

Bug Tracker

+

Bug Tracker

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 @@ -744,22 +739,22 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • ACSONE SA/NV
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -772,6 +767,5 @@

Maintainers

-
diff --git a/base_rest/static/src/js/components/swagger_ui.js b/base_rest/static/src/js/components/swagger_ui.esm.js similarity index 98% rename from base_rest/static/src/js/components/swagger_ui.js rename to base_rest/static/src/js/components/swagger_ui.esm.js index a63d1ed8a..a7f6bd5ec 100644 --- a/base_rest/static/src/js/components/swagger_ui.js +++ b/base_rest/static/src/js/components/swagger_ui.esm.js @@ -58,6 +58,7 @@ class SwaggerUI extends Component { } (function () { + // eslint-disable-next-line "use strict"; whenReady(() => { diff --git a/base_rest/views/openapi_template.xml b/base_rest/views/openapi_template.xml index de42ff5b7..3551e06bd 100644 --- a/base_rest/views/openapi_template.xml +++ b/base_rest/views/openapi_template.xml @@ -60,7 +60,7 @@