Merge pull request #130 from matrix-org/templating-nested-request-objects

Make nested request objects display correctly (search API)
markjh/event_syntax_highlighting
Kegsay 9 years ago
commit 532634aff6

@ -13,17 +13,17 @@
Request format:
=================================== ================= ===========================================
Parameter Value Description
=================================== ================= ===========================================
=========================================== ================= ===========================================
Parameter Value Description
=========================================== ================= ===========================================
{% for loc in endpoint.req_param_by_loc -%}
*{{loc}} parameters*
-------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
{% for param in endpoint.req_param_by_loc[loc] -%}
{{param.key}}{{param.type|indent(36-param.key|length)}}{{param.desc|indent(18-param.type|length)|wrap(43)|indent_block(54)}}
{{param.key}}{{param.type|indent(44-param.key|length)}}{{param.desc|indent(18-param.type|length)|wrap(43)|indent_block(62)}}
{% endfor -%}
{% endfor -%}
=================================== ================= ===========================================
=========================================== ================= ===========================================
{% if endpoint.res_tables|length > 0 -%}
Response format:

@ -121,6 +121,17 @@ def get_json_schema_object_fields(obj, enforce_title=False):
tables += nested_object
else:
value_type = "[%s]" % props[key_name]["items"]["type"]
array_enums = props[key_name]["items"].get("enum")
if array_enums:
if len(array_enums) > 1:
value_type = "[enum]"
desc += (
" One of: %s" % json.dumps(array_enums)
)
else:
desc += (
" Must be '%s'." % array_enums[0]
)
else:
value_type = props[key_name]["type"]
if props[key_name].get("enum"):
@ -252,13 +263,24 @@ class MatrixUnits(Units):
req_obj = req_obj["items"]
req_tables = get_json_schema_object_fields(req_obj)
if req_tables > 1:
for table in req_tables[1:]:
nested_key_name = [
s["key"] for s in req_tables[0]["rows"] if
s["type"] == ("{%s}" % (table["title"],))
][0]
for row in table["rows"]:
row["key"] = "%s.%s" % (nested_key_name, row["key"])
key_sep = "[0]." if is_array else "."
for table in req_tables:
if table.get("no-table"):
continue
for row in table["rows"]:
nested_key = key + key_sep + row["key"]
endpoint["req_params"].append({
"key": key + key_sep + row["key"],
"key": nested_key,
"loc": "JSON body",
"type": row["type"],
"desc": row["req_str"] + row["desc"]

Loading…
Cancel
Save