diff --git a/openapi/__manifest__.py b/openapi/__manifest__.py index 9c56b85..0032799 100644 --- a/openapi/__manifest__.py +++ b/openapi/__manifest__.py @@ -6,11 +6,11 @@ "summary": """RESTful API to integrate Odoo with whatever system you need""", "category": "", "images": ["images/openapi-swagger.png"], - "version": "16.0.1.2.4", + "version": "17.0.1.2.4", "application": False, "author": "IT-Projects LLC, Ivan Yelizariev", "support": "help@itpp.dev", - "website": "https://t.me/sync_studio", + "website": "https://github.com/it-projects-llc/sync-addons", "license": "LGPL-3", "depends": ["base_api", "mail"], "external_dependencies": { diff --git a/openapi/controllers/main.py b/openapi/controllers/main.py index fc6aa67..32e0ade 100644 --- a/openapi/controllers/main.py +++ b/openapi/controllers/main.py @@ -47,5 +47,5 @@ def OAS_json_spec_download(self, namespace_name, **kwargs): return werkzeug.wrappers.Response( json.dumps(namespace.get_OAS(), default=date_utils.json_default), status=200, - **response_params + **response_params, ) diff --git a/openapi/controllers/pinguin.py b/openapi/controllers/pinguin.py index d617ed4..4931b2d 100644 --- a/openapi/controllers/pinguin.py +++ b/openapi/controllers/pinguin.py @@ -108,10 +108,8 @@ def successful_response(status, data=None): http://werkzeug.pocoo.org/docs/0.14/wrappers/#module-werkzeug.wrappers """ - try: + if hasattr(data, "ids"): data = data.ids - except AttributeError: - pass return request.make_json_response(data, status=status) @@ -315,10 +313,8 @@ def _create_log_record( elif namespace_log_request == "info": log_data["request_data"] = user_request.__dict__ for k in ["form", "files"]: - try: + if k in log_data["request_data"]: del log_data["request_data"][k] - except KeyError: - pass if namespace_log_response == "debug": log_data["response_data"] = user_response.__dict__ @@ -344,7 +340,6 @@ def route(controller_method): @functools.wraps(controller_method) def controller_method_wrapper(*iargs, **ikwargs): - auth_header = get_auth_header( request.httprequest.headers, raise_exception=True ) @@ -569,7 +564,7 @@ def wrap__resource__create_one(modelname, context, data, success_code, out_field """ model_obj = get_model_for_read(modelname) try: - created_obj = model_obj.with_context(context).create(data) + created_obj = model_obj.with_context(**context).create(data) test_mode = request.registry.test_cr if not test_mode: # Somehow don't making a commit here may lead to error @@ -804,6 +799,7 @@ def method_is_allowed(method, methods_conf, main=False, raise_exception=False): # Pinguin OAS # ############### + # Get definition name def get_definition_name(modelname, prefix="", postfix="", splitter="-"): """Concatenation of the prefix, modelname, postfix. diff --git a/openapi/models/openapi_access.py b/openapi/models/openapi_access.py index b4db505..dca4e11 100644 --- a/openapi/models/openapi_access.py +++ b/openapi/models/openapi_access.py @@ -5,6 +5,7 @@ import collections import inspect import json +import logging import types import urllib.parse as urlparse from inspect import getmro, isclass @@ -15,6 +16,8 @@ from ..controllers import pinguin +_logger = logging.getLogger(__name__) + PARAM_ID = { "name": "id", "in": "path", @@ -155,8 +158,7 @@ def _check_methods(self): def name_get(self): return [ - (record.id, "{}/{}".format(record.namespace_id.name, record.model)) - for record in self + (record.id, f"{record.namespace_id.name}/{record.model}") for record in self ] def get_OAS_paths_part(self): @@ -365,7 +367,6 @@ def get_OAS_paths_part(self): paths_object = {k: v for k, v in paths_object.items() if v} for _path_item_key, path_item_value in paths_object.items(): - for path_method in path_item_value.values(): # add tag path_method.update({"tags": [model_name]}) @@ -504,8 +505,8 @@ def getmembers(obj, predicate=None): for k, v in base.__dict__.items(): if isinstance(v, types.DynamicClassAttribute): names.append(k) - except AttributeError: - pass + except AttributeError as e: + _logger.warning(f"AttributeError encountered: {e}") for key in names: if key == "_cache": # NEW diff --git a/openapi/models/openapi_namespace.py b/openapi/models/openapi_namespace.py index 09b3fe8..78f4b41 100644 --- a/openapi/models/openapi_namespace.py +++ b/openapi/models/openapi_namespace.py @@ -14,7 +14,6 @@ class Namespace(models.Model): - _name = "openapi.namespace" _description = "Integration" diff --git a/openapi/pyproject.toml b/openapi/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/openapi/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/openapi/tests/test_json_spec.py b/openapi/tests/test_json_spec.py index 6ce73be..0d316f3 100644 --- a/openapi/tests/test_json_spec.py +++ b/openapi/tests/test_json_spec.py @@ -15,7 +15,6 @@ @tagged("post_install", "-at_install") class TestJsonSpec(HttpCase): def test_json_base(self): - resp = self.url_open( "http://localhost:%d/api/v1/demo/swagger.json?token=demo_token&download" % config["http_port"], diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a223b0b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +# generated from manifests external_dependencies +bravado_core +jsonschema<4 +swagger_spec_validator