Make res optional, and rename to good_response
This commit is contained in:
parent
0a9f61029a
commit
5031c26f7b
1 changed files with 24 additions and 18 deletions
|
@ -116,7 +116,8 @@ class MatrixUnits(Units):
|
||||||
"res_tables": [],
|
"res_tables": [],
|
||||||
"example": {
|
"example": {
|
||||||
"req": "",
|
"req": "",
|
||||||
"res": ""
|
"responses": [],
|
||||||
|
"good_response": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.log(".o.O.o. Endpoint: %s %s" % (method, path))
|
self.log(".o.O.o. Endpoint: %s %s" % (method, path))
|
||||||
|
@ -177,8 +178,10 @@ class MatrixUnits(Units):
|
||||||
endpoint["req_param_by_loc"][p["loc"]] = []
|
endpoint["req_param_by_loc"][p["loc"]] = []
|
||||||
endpoint["req_param_by_loc"][p["loc"]].append(p)
|
endpoint["req_param_by_loc"][p["loc"]].append(p)
|
||||||
|
|
||||||
endpoint["example"]["responses"] = [] # Ordered list of maps
|
good_response = None
|
||||||
for code, res in single_api.get("responses", {}).items():
|
for code, res in single_api.get("responses", {}).items():
|
||||||
|
if not good_response and code == 200:
|
||||||
|
good_response = res
|
||||||
description = res.get("description", "")
|
description = res.get("description", "")
|
||||||
example = res.get("examples", {}).get("application/json", "")
|
example = res.get("examples", {}).get("application/json", "")
|
||||||
if description and example:
|
if description and example:
|
||||||
|
@ -222,22 +225,25 @@ class MatrixUnits(Units):
|
||||||
)
|
)
|
||||||
|
|
||||||
# add response params if this API has any.
|
# add response params if this API has any.
|
||||||
res_type = Units.prop(res, "schema/type")
|
if good_response:
|
||||||
if res_type and res_type not in ["object", "array"]:
|
res_type = Units.prop(good_response, "schema/type")
|
||||||
# response is a raw string or something like that
|
if res_type and res_type not in ["object", "array"]:
|
||||||
endpoint["res_tables"].append({
|
# response is a raw string or something like that
|
||||||
"title": None,
|
endpoint["res_tables"].append({
|
||||||
"rows": [{
|
"title": None,
|
||||||
"key": res["schema"].get("name", ""),
|
"rows": [{
|
||||||
"type": res_type,
|
"key": good_response["schema"].get("name", ""),
|
||||||
"desc": res.get("description", "")
|
"type": res_type,
|
||||||
}]
|
"desc": res.get("description", "")
|
||||||
})
|
}]
|
||||||
elif res_type and Units.prop(res, "schema/properties"): # object
|
})
|
||||||
res_tables = get_json_schema_object_fields(res["schema"])
|
elif res_type and Units.prop(good_response, "schema/properties"):
|
||||||
for table in res_tables:
|
# response is an object:
|
||||||
if "no-table" not in table:
|
schema = good_response["schema"]
|
||||||
endpoint["res_tables"].append(table)
|
res_tables = get_json_schema_object_fields(schema)
|
||||||
|
for table in res_tables:
|
||||||
|
if "no-table" not in table:
|
||||||
|
endpoint["res_tables"].append(table)
|
||||||
|
|
||||||
endpoints.append(endpoint)
|
endpoints.append(endpoint)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue