diff --git a/templating/matrix_templates/sections.py b/templating/matrix_templates/sections.py index 09437b00..c9c6eeda 100644 --- a/templating/matrix_templates/sections.py +++ b/templating/matrix_templates/sections.py @@ -31,7 +31,15 @@ class MatrixSections(Sections): return "\n\n".join(sections) 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 filterFn(eventType): diff --git a/templating/matrix_templates/templates/http-api.tmpl b/templating/matrix_templates/templates/http-api.tmpl new file mode 100644 index 00000000..2bfb2e27 --- /dev/null +++ b/templating/matrix_templates/templates/http-api.tmpl @@ -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 %} +================== ================= =========== =============================== + diff --git a/templating/matrix_templates/units.py b/templating/matrix_templates/units.py index 05396218..d7f5a780 100644 --- a/templating/matrix_templates/units.py +++ b/templating/matrix_templates/units.py @@ -104,8 +104,8 @@ class MatrixUnits(Units): for method in api["paths"][path]: single_api = api["paths"][path][method] endpoint = { - "title": single_api.get("summary"), - "desc": single_api.get("description"), + "title": single_api.get("summary", ""), + "desc": single_api.get("description", ""), "method": method.upper(), "path": path, "requires_auth": "security" in single_api, @@ -118,7 +118,7 @@ class MatrixUnits(Units): self.log(".o.O.o. Endpoint: %s %s" % (method, path)) for param in single_api.get("parameters", []): # description - desc = param.get("description") + desc = param.get("description", "") if param.get("required"): desc = "**Required.** " + desc @@ -133,8 +133,8 @@ class MatrixUnits(Units): if val_type: endpoint["req_params"].append({ "name": param["name"], - "type": param["in"], - "val_type": val_type, + "loc": param["in"], + "type": val_type, "desc": desc }) continue @@ -159,8 +159,8 @@ class MatrixUnits(Units): for key in json_body: endpoint["req_params"].append({ "name": key, - "type": "JSON", - "val_type": json_body[key]["type"], + "loc": "JSON", + "type": json_body[key]["type"], "desc": json_body[key]["description"] })