Moving func args generation into the template

This commit is contained in:
Honza Král
2019-12-22 16:32:49 +01:00
committed by Honza Král
parent 77f084dc0d
commit e44f5266d9
3 changed files with 19 additions and 16 deletions
+5 -15
View File
@@ -128,7 +128,8 @@ class API:
self.description = definition["documentation"].get("description", "")
self.doc_url = definition["documentation"].get("url", "")
def _all_parts(self):
@property
def all_parts(self):
parts = {}
for url in self._def["url"]["paths"]:
parts.update(url.get("parts", {}))
@@ -155,7 +156,7 @@ class API:
@property
def params(self):
parts = self._all_parts()
parts = self.all_parts
return chain(
((p, parts[p]) for p in parts if parts[p]["required"]),
self.body.items() if self.body["body"] else (),
@@ -175,7 +176,7 @@ class API:
return (
k
for k in sorted(self._def.get("params", {}).keys())
if k not in self._all_parts()
if k not in self.all_parts
)
@property
@@ -210,20 +211,9 @@ class API:
return dynamic, parts
@property
def func_params(self):
parts = self._all_parts()
return chain(
(p for p in parts if parts[p]["required"]),
(b for b in self.body if self.body[b].get("required")),
(f"{b}=None" for b in self.body if not self.body[b].get("required", True)),
(f"{p}=None" for p in parts if not parts[p]["required"]),
("params=None",),
)
@property
def required_parts(self):
parts = self._all_parts()
parts = self.all_parts
return [p for p in parts if parts[p]["required"]] + [
b for b in self.body if self.body[b].get("required")
]
+1 -1
View File
@@ -1,6 +1,6 @@
@query_params({{ api.query_params|map("tojson")|join(", ")}})
def {{ api.name }}(self, {{ api.func_params|join(", ") }}):
def {{ api.name }}(self, {% include "func_params" %}):
"""
{% if api.description %}
{{ api.description|replace("\n", " ")|wordwrap(wrapstring="\n ") }}
+13
View File
@@ -0,0 +1,13 @@
{% for p, info in api.all_parts.items() %}
{% if info.required %}{{ p }}, {% endif %}
{% endfor %}
{% if api.body.body %}
body{% if not api.body.body.required %}=None{% endif %},
{% endif %}
{% for p, info in api.all_parts.items() %}
{% if not info.required %}{{ p }}=None, {% endif %}
{% endfor %}
params=None