Skip to content
Merged
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
2 changes: 1 addition & 1 deletion base_rest/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Base Rest
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae655c2ed1894f216ac24019353f50cedcc8d4af9c6fb1a1f6119fd0585e091a
!! source digest: sha256:4dcc7d7ecd1b0925d3833b03e31a3ca205378816faa55cd09a53816c0c63ddc7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion base_rest/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"cerberus",
"pyquerystring",
"parse-accept-language",
"apispec>=4.0.0",
"apispec",
]
},
"installable": True,
Expand Down
2 changes: 1 addition & 1 deletion base_rest/apispec/base_rest_service_apispec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, service_component, **params):
super(BaseRestServiceAPISpec, self).__init__(
title="%s REST services" % self._service._usage,
version="",
openapi_version="3.0.0",
openapi_version="3.1.0",
info={
"description": textwrap.dedent(
getattr(self._service, "_description", "") or ""
Expand Down
2 changes: 1 addition & 1 deletion base_rest/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Base Rest</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae655c2ed1894f216ac24019353f50cedcc8d4af9c6fb1a1f6119fd0585e091a
!! source digest: sha256:4dcc7d7ecd1b0925d3833b03e31a3ca205378816faa55cd09a53816c0c63ddc7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/14.0/base_rest"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-14-0/rest-framework-14-0-base_rest"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon provides the basis to develop high level REST APIs for Odoo.</p>
Expand Down
60 changes: 0 additions & 60 deletions base_rest/static/lib/swagger-ui-3.51.1/index.html

This file was deleted.

3 changes: 0 additions & 3 deletions base_rest/static/lib/swagger-ui-3.51.1/swagger-ui-bundle.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions base_rest/static/lib/swagger-ui-3.51.1/swagger-ui.css

This file was deleted.

1 change: 0 additions & 1 deletion base_rest/static/lib/swagger-ui-3.51.1/swagger-ui.css.map

This file was deleted.

3 changes: 0 additions & 3 deletions base_rest/static/lib/swagger-ui-3.51.1/swagger-ui.js

This file was deleted.

1 change: 0 additions & 1 deletion base_rest/static/lib/swagger-ui-3.51.1/swagger-ui.js.map

This file was deleted.

16 changes: 16 additions & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
19 changes: 19 additions & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
</head>

<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var isValid, qp, arr;

if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
qp = window.location.hash.substring(1).replace('?', '&');
} else {
qp = location.search.substring(1);
}
Expand All @@ -38,7 +38,7 @@
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
});
}

Expand All @@ -58,7 +58,7 @@
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
});
}
} else {
Expand All @@ -67,9 +67,13 @@
window.close();
}

window.addEventListener('DOMContentLoaded', function () {
run();
});
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/swagger-initializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">

// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});

//</editor-fold>
};
3 changes: 3 additions & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/swagger-ui-bundle.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/swagger-ui.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/swagger-ui.css.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/swagger-ui.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions base_rest/static/lib/swagger-ui-5.11.6/swagger-ui.js.map

Large diffs are not rendered by default.

120 changes: 65 additions & 55 deletions base_rest/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def _get_field_props(spec): # noqa: C901
"datetime": ("string", "date-time"),
"float": ("number", "float"),
}
_type = spec.get("type")
if _type is None:
_types = spec.get("type")
if _types is None:
return resp
if type(_types) is not list:
_types = [_types]

if "description" in spec:
resp["description"] = spec["description"]
Expand All @@ -57,26 +59,6 @@ def _get_field_props(spec): # noqa: C901
if "default" in spec:
resp["default"] = spec["default"]

if "minlength" in spec:
if _type == "string":
resp["minLength"] = spec["minlength"]
elif _type == "list":
resp["minItems"] = spec["minlength"]

if "maxlength" in spec:
if _type == "string":
resp["maxLength"] = spec["maxlength"]
elif _type == "list":
resp["maxItems"] = spec["maxlength"]

if "min" in spec:
if _type in ["number", "integer", "float"]:
resp["minimum"] = spec["min"]

if "max" in spec:
if _type in ["number", "integer", "float"]:
resp["maximum"] = spec["max"]

if "readonly" in spec:
resp["readOnly"] = spec["readonly"]

Expand All @@ -89,40 +71,68 @@ def _get_field_props(spec): # noqa: C901
if "allowed" in spec:
resp["enum"] = spec["allowed"]

json_type = type_map.get(_type, (_type,))

resp["type"] = json_type[0]
if json_type[0] == "object":
if "schema" in spec:
resp.update(cerberus_to_json(spec["schema"]))
additional_properties = {}
if "keysrules" in spec:
rule_value_type = spec["keysrules"].get("type", "string")
if rule_value_type != "string":
_logger.debug(
"Openapi only support key/value mapping definition where"
" the keys are strings. Received %s",
rule_value_type,
)
if "valuesrules" in spec:
values_rules = spec["valuesrules"]
rule_value_type = values_rules.get("type", "string")
additional_properties["type"] = rule_value_type
if "schema" in values_rules:
additional_properties.update(cerberus_to_json(values_rules["schema"]))
if additional_properties:
resp["additionalProperties"] = additional_properties
elif json_type[0] == "array":
if "schema" in spec:
resp["items"] = _get_field_props(spec["schema"])
resp["type"] = [] if len(_types) > 1 else ""
for _type in _types:
if "minlength" in spec:
if _type == "string":
resp["minLength"] = spec["minlength"]
elif _type == "list":
resp["minItems"] = spec["minlength"]

if "maxlength" in spec:
if _type == "string":
resp["maxLength"] = spec["maxlength"]
elif _type == "list":
resp["maxItems"] = spec["maxlength"]

if "min" in spec:
if _type in ["number", "integer", "float"]:
resp["minimum"] = spec["min"]

if "max" in spec:
if _type in ["number", "integer", "float"]:
resp["maximum"] = spec["max"]

json_type = type_map.get(_type, (_type,))

if type(resp["type"]) is list:
resp["type"].append(json_type[0])
else:
resp["type"] = json_type[0]

if json_type[0] == "object":
if "schema" in spec:
resp.update(cerberus_to_json(spec["schema"]))
additional_properties = {}
if "keysrules" in spec:
rule_value_type = spec["keysrules"].get("type", "string")
if rule_value_type != "string":
_logger.debug(
"Openapi only support key/value mapping definition where"
" the keys are strings. Received %s",
rule_value_type,
)
if "valuesrules" in spec:
values_rules = spec["valuesrules"]
rule_value_type = values_rules.get("type", "string")
additional_properties["type"] = rule_value_type
if "schema" in values_rules:
additional_properties.update(
cerberus_to_json(values_rules["schema"])
)
if additional_properties:
resp["additionalProperties"] = additional_properties
elif json_type[0] == "array":
if "schema" in spec:
resp["items"] = _get_field_props(spec["schema"])
else:
resp["items"] = {"type": "string"}
else:
resp["items"] = {"type": "string"}
else:
try:
resp["format"] = json_type[1]
# pylint:disable=except-pass
except IndexError:
pass
try:
resp["format"] = json_type[1]
# pylint:disable=except-pass
except IndexError:
pass

return resp

Expand Down
6 changes: 3 additions & 3 deletions base_rest/views/assets_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link
rel="stylesheet"
type="text/css"
href="/base_rest/static/lib/swagger-ui-3.51.1/swagger-ui.css"
href="/base_rest/static/lib/swagger-ui-5.11.6/swagger-ui.css"
/>
<link
rel="stylesheet"
Expand All @@ -15,11 +15,11 @@
/>
<script
type="text/javascript"
src="/base_rest/static/lib/swagger-ui-3.51.1/swagger-ui-bundle.js"
src="/base_rest/static/lib/swagger-ui-5.11.6/swagger-ui-bundle.js"
/>
<script
type="text/javascript"
src="/base_rest/static/lib/swagger-ui-3.51.1/swagger-ui-standalone-preset.js"
src="/base_rest/static/lib/swagger-ui-5.11.6/swagger-ui-standalone-preset.js"
/>
<script type="text/javascript" src="/base_rest/static/src/js/swagger_ui.js" />
</template>
Expand Down
4 changes: 2 additions & 2 deletions base_rest/views/openapi_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
<link
rel="icon"
type="image/png"
href="/base_rest/static/lib/swagger-ui-3.51.1/favicon-32x32.png"
href="/base_rest/static/lib/swagger-ui-5.11.6/favicon-32x32.png"
sizes="32x32"
/>
<link
rel="icon"
type="image/png"
href="/base_rest/static/lib/swagger-ui-3.51.1/favicon-16x16.png"
href="/base_rest/static/lib/swagger-ui-5.11.6/favicon-16x16.png"
sizes="16x16"
/>

Expand Down
2 changes: 1 addition & 1 deletion base_rest_demo/tests/data/partner_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@
]
}
},
"openapi": "3.0.0",
"openapi": "3.1.0",
"components": {
"securitySchemes": {
"user": {
Expand Down
2 changes: 1 addition & 1 deletion base_rest_demo/tests/data/partner_image_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
]
}
},
"openapi": "3.0.0",
"openapi": "3.1.0",
"components": {
"securitySchemes": {
"user": {
Expand Down
Loading