Implement nested tables for HTTP APIs. It even works(!)

pull/977/head
Kegan Dougal 9 years ago
parent 0275c2ffa0
commit 14d004146b

@ -25,13 +25,14 @@ class Sections(object):
if not func_name.startswith("render_"): if not func_name.startswith("render_"):
continue continue
section_key = func_name[len("render_"):] section_key = func_name[len("render_"):]
self.log("Generating section '%s'" % section_key)
section = func() section = func()
if not isinstance(section, basestring): if not isinstance(section, basestring):
raise Exception( raise Exception(
"Section function '%s' didn't return a string!" % func_name "Section function '%s' didn't return a string!" % func_name
) )
section_dict[section_key] = section section_dict[section_key] = section
self.log("Generated section '%s' : %s" % ( self.log(
section_key, section[:60].replace("\n","") " Generated. Snippet => %s" % section[:60].replace("\n","")
)) )
return section_dict return section_dict

@ -20,17 +20,27 @@ Request format:
{% endfor -%} {% endfor -%}
================== ================= =========================================== ================== ================= ===========================================
{% if endpoint.res_params|length > 0 -%} {% if endpoint.res_tables|length > 0 -%}
Response format: Response format:
{% for table in endpoint.res_tables -%}
{{"``"+table.title+"``" if table.title else "" }}
================== ================= =========================================== ================== ================= ===========================================
Parameter Value Description Param Type Description
================== ================= =========================================== ================== ================= ===========================================
{% for param in endpoint.res_params -%} {% for row in table.rows -%}
{{param.key}}{{param.type|indent(19-param.key|length)}}{{param.desc|indent(18-param.type|length)|wrap(43)|indent_block(37)}} {# -#}
{# Row type needs to prepend spaces to line up with the type column (19 ch) -#}
{# Desc needs to prepend the required text (maybe) and prepend spaces too -#}
{# It also needs to then wrap inside the desc col (43 ch width) -#}
{# -#}
{{row.key}}{{row.type|indent(19-row.key|length)}}{{row.desc|wrap(43,row.req_str | indent(18 - (row.type|length))) |indent_block(37)}}
{% endfor -%} {% endfor -%}
================== ================= =========================================== ================== ================= ===========================================
{% endif %}
{% endfor %}
{% endif -%}
Example request:: Example request::

@ -113,7 +113,7 @@ class MatrixUnits(Units):
"requires_auth": "security" in single_api, "requires_auth": "security" in single_api,
"rate_limited": 429 in single_api.get("responses", {}), "rate_limited": 429 in single_api.get("responses", {}),
"req_params": [], "req_params": [],
"res_params": [], "res_tables": [],
"example": { "example": {
"req": "", "req": "",
"res": "" "res": ""
@ -219,16 +219,19 @@ class MatrixUnits(Units):
res_type = Units.prop(res, "schema/type") res_type = Units.prop(res, "schema/type")
if res_type and res_type not in ["object", "array"]: if res_type and res_type not in ["object", "array"]:
# response is a raw string or something like that # response is a raw string or something like that
endpoint["res_params"].append({ endpoint["res_tables"].append({
"key": res["schema"].get("name", ""), "title": None,
"type": res_type, "rows": [{
"desc": res.get("description", "") "key": res["schema"].get("name", ""),
"type": res_type,
"desc": res.get("description", "")
}]
}) })
elif res_type and Units.prop(res, "schema/properties"): # object elif res_type and Units.prop(res, "schema/properties"): # object
res_tables = get_json_schema_object_fields(res["schema"]) res_tables = get_json_schema_object_fields(res["schema"])
# TODO: Is this good enough or should we be doing multiple for table in res_tables:
# tables for HTTP responses?! if "no-table" not in table:
endpoint["res_params"] = res_tables[0]["rows"] endpoint["res_tables"].append(table)
endpoints.append(endpoint) endpoints.append(endpoint)

Loading…
Cancel
Save