Add HTTP API wip template.
This commit is contained in:
parent
5795e1ceda
commit
c75fd6bcae
3 changed files with 35 additions and 8 deletions
|
@ -31,7 +31,15 @@ class MatrixSections(Sections):
|
||||||
return "\n\n".join(sections)
|
return "\n\n".join(sections)
|
||||||
|
|
||||||
def render_foo(self):
|
def render_foo(self):
|
||||||
return json.dumps(self.units.get("swagger_apis")["profile"]["__meta"], indent=2)
|
template = self.env.get_template("http-api.tmpl")
|
||||||
|
http_api = self.units.get("swagger_apis")["profile"]["__meta"]
|
||||||
|
sections = []
|
||||||
|
for endpoint in http_api["endpoints"]:
|
||||||
|
sections.append(template.render(
|
||||||
|
endpoint=endpoint,
|
||||||
|
title_kind="-"
|
||||||
|
))
|
||||||
|
return "\n\n".join(sections)
|
||||||
|
|
||||||
def render_room_events(self):
|
def render_room_events(self):
|
||||||
def filterFn(eventType):
|
def filterFn(eventType):
|
||||||
|
|
19
templating/matrix_templates/templates/http-api.tmpl
Normal file
19
templating/matrix_templates/templates/http-api.tmpl
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
``{{endpoint.method}} {{endpoint.path}}``
|
||||||
|
{{(5 + (endpoint.path | length) + (endpoint.method | length)) * title_kind}}
|
||||||
|
|
||||||
|
{{endpoint.desc | wrap(80)}}
|
||||||
|
|
||||||
|
{{":Rate-limited: Yes." if endpoint.rate_limited else ""}}
|
||||||
|
{{":Requires auth: Yes." if endpoint.requires_auth else ""}}
|
||||||
|
|
||||||
|
Request format:
|
||||||
|
|
||||||
|
================== ================= =========== ===============================
|
||||||
|
Parameter Param Location Param Type Description
|
||||||
|
================== ================= =========== ===============================
|
||||||
|
{% for param in endpoint.req_params -%}
|
||||||
|
{{param.name}}{{param.loc|indent(19-param.name|length)}}{{param.type|indent(37-19-
|
||||||
|
param.loc|length)}}{{param.desc|indent(12-param.type|length)|wrap(31)|indent_block(49)}}
|
||||||
|
{% endfor %}
|
||||||
|
================== ================= =========== ===============================
|
||||||
|
|
|
@ -104,8 +104,8 @@ class MatrixUnits(Units):
|
||||||
for method in api["paths"][path]:
|
for method in api["paths"][path]:
|
||||||
single_api = api["paths"][path][method]
|
single_api = api["paths"][path][method]
|
||||||
endpoint = {
|
endpoint = {
|
||||||
"title": single_api.get("summary"),
|
"title": single_api.get("summary", ""),
|
||||||
"desc": single_api.get("description"),
|
"desc": single_api.get("description", ""),
|
||||||
"method": method.upper(),
|
"method": method.upper(),
|
||||||
"path": path,
|
"path": path,
|
||||||
"requires_auth": "security" in single_api,
|
"requires_auth": "security" in single_api,
|
||||||
|
@ -118,7 +118,7 @@ class MatrixUnits(Units):
|
||||||
self.log(".o.O.o. Endpoint: %s %s" % (method, path))
|
self.log(".o.O.o. Endpoint: %s %s" % (method, path))
|
||||||
for param in single_api.get("parameters", []):
|
for param in single_api.get("parameters", []):
|
||||||
# description
|
# description
|
||||||
desc = param.get("description")
|
desc = param.get("description", "")
|
||||||
if param.get("required"):
|
if param.get("required"):
|
||||||
desc = "**Required.** " + desc
|
desc = "**Required.** " + desc
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ class MatrixUnits(Units):
|
||||||
if val_type:
|
if val_type:
|
||||||
endpoint["req_params"].append({
|
endpoint["req_params"].append({
|
||||||
"name": param["name"],
|
"name": param["name"],
|
||||||
"type": param["in"],
|
"loc": param["in"],
|
||||||
"val_type": val_type,
|
"type": val_type,
|
||||||
"desc": desc
|
"desc": desc
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
|
@ -159,8 +159,8 @@ class MatrixUnits(Units):
|
||||||
for key in json_body:
|
for key in json_body:
|
||||||
endpoint["req_params"].append({
|
endpoint["req_params"].append({
|
||||||
"name": key,
|
"name": key,
|
||||||
"type": "JSON",
|
"loc": "JSON",
|
||||||
"val_type": json_body[key]["type"],
|
"type": json_body[key]["type"],
|
||||||
"desc": json_body[key]["description"]
|
"desc": json_body[key]["description"]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue