From 65504db7bb3c4c17e58cff52583699c69e45b9a9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 8 Oct 2015 13:40:21 +0100 Subject: [PATCH] Display nested keys on arrays of objects. Make it valid swagger. --- api/client-server/v1/push_notifier.yaml | 5 +++++ api/client-server/v1/pushrules.yaml | 2 ++ templating/matrix_templates/units.py | 30 +++++++++++++++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/api/client-server/v1/push_notifier.yaml b/api/client-server/v1/push_notifier.yaml index 54576b6c..0a0204c0 100644 --- a/api/client-server/v1/push_notifier.yaml +++ b/api/client-server/v1/push_notifier.yaml @@ -151,12 +151,17 @@ paths: pushkey was last updated. data: type: object + title: PusherData description: |- A dictionary of additional pusher-specific data. For 'http' pushers, this is the data dictionary passed in at pusher creation minus the ``url`` key. + properties: + foo: + type: string tweaks: type: object + title: Tweaks description: |- A dictionary of customisations made to the way this notification is to be presented. These are added by push rules. diff --git a/api/client-server/v1/pushrules.yaml b/api/client-server/v1/pushrules.yaml index eef0b2c7..31e84f55 100644 --- a/api/client-server/v1/pushrules.yaml +++ b/api/client-server/v1/pushrules.yaml @@ -413,6 +413,8 @@ paths: always matches. items: type: object + title: conditions + allOf: [ "$ref": "definitions/push_condition.json" ] required: ["actions"] responses: 200: diff --git a/templating/matrix_templates/units.py b/templating/matrix_templates/units.py index 558461b9..83376fba 100644 --- a/templating/matrix_templates/units.py +++ b/templating/matrix_templates/units.py @@ -219,23 +219,39 @@ class MatrixUnits(Units): if Units.prop(param, "schema/required"): required_params = Units.prop(param, "schema/required") for key in json_body: - pdesc = json_body[key]["description"] + req_obj = json_body[key] + pdesc = req_obj["description"] if key in required_params: pdesc = "**Required.** " + pdesc + + is_array = req_obj["type"] == "array" + is_array_of_objects = ( + is_array and req_obj["items"]["type"] == "object" + ) endpoint["req_params"].append({ "key": key, "loc": "JSON body", - "type": json_body[key]["type"], + "type": ( + req_obj["type"] if not is_array else + "array[%s]" % req_obj["items"]["type"] + ), "desc": pdesc }) - if json_body[key]["type"] in ["object"]: - req_tables = get_json_schema_object_fields( - json_body[key] - ) + if not is_array_of_objects and req_obj["type"] == "array": + continue + # Put in request.dot.notation for nested keys + if req_obj["type"] in ["object", "array"]: + if is_array_of_objects: + req_obj = req_obj["items"] + + req_tables = get_json_schema_object_fields(req_obj) + key_sep = "[0]." if is_array else "." for table in req_tables: + if table.get("no-table"): + continue for row in table["rows"]: endpoint["req_params"].append({ - "key": key + "." + row["key"], + "key": key + key_sep + row["key"], "loc": "JSON body", "type": row["type"], "desc": row["req_str"] + row["desc"]