Skip to content

Commit

Permalink
[IMP] openapi: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
azimkhankuat committed Oct 15, 2024
1 parent 1a858a1 commit d3e886d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions openapi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"website": "https://t.me/sync_studio",
"website": "https://github.com/it-projects-llc/sync-addons",
"license": "LGPL-3",
"depends": ["base_api", "mail"],
"external_dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion openapi/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
12 changes: 4 additions & 8 deletions openapi/controllers/pinguin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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__
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions openapi/models/openapi_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import collections
import inspect
import json
import logging
import types
import urllib.parse as urlparse
from inspect import getmro, isclass
Expand All @@ -15,6 +16,8 @@

from ..controllers import pinguin

_logger = logging.getLogger(__name__)

PARAM_ID = {
"name": "id",
"in": "path",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]})
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion openapi/models/openapi_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class Namespace(models.Model):

_name = "openapi.namespace"
_description = "Integration"

Expand Down
3 changes: 3 additions & 0 deletions openapi/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 0 additions & 1 deletion openapi/tests/test_json_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# generated from manifests external_dependencies
bravado_core
jsonschema<4
swagger_spec_validator

0 comments on commit d3e886d

Please sign in to comment.