mirror of
https://github.com/matrix-org/matrix-spec
synced 2025-12-23 17:48:37 +01:00
Start pre-processing swagger APIs before passing to sections.
This commit is contained in:
parent
1dc3d82664
commit
d090389d01
|
|
@ -6,7 +6,7 @@ host: localhost:8008
|
||||||
schemes:
|
schemes:
|
||||||
- https
|
- https
|
||||||
- http
|
- http
|
||||||
basePath: /_matrix/client/api/v1/profile
|
basePath: /_matrix/client/api/v1
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
produces:
|
produces:
|
||||||
|
|
@ -18,7 +18,7 @@ securityDefinitions:
|
||||||
name: access_token
|
name: access_token
|
||||||
in: query
|
in: query
|
||||||
paths:
|
paths:
|
||||||
"/{userId}/displayname":
|
"/profile/{userId}/displayname":
|
||||||
put:
|
put:
|
||||||
summary: Set the user's display name.
|
summary: Set the user's display name.
|
||||||
security:
|
security:
|
||||||
|
|
@ -67,7 +67,7 @@ paths:
|
||||||
description: The user's display name if they have set one.
|
description: The user's display name if they have set one.
|
||||||
404:
|
404:
|
||||||
description: There is no display name for this user or this user does not exist.
|
description: There is no display name for this user or this user does not exist.
|
||||||
"/{userId}/avatar_url":
|
"/profile/{userId}/avatar_url":
|
||||||
put:
|
put:
|
||||||
summary: Set the user's avatar URL.
|
summary: Set the user's avatar URL.
|
||||||
security:
|
security:
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ class MatrixSections(Sections):
|
||||||
))
|
))
|
||||||
return "\n\n".join(sections)
|
return "\n\n".join(sections)
|
||||||
|
|
||||||
|
def render_foo(self):
|
||||||
|
return json.dumps(self.units.get("swagger_apis")["profile"]["__meta"], indent=2)
|
||||||
|
|
||||||
def render_room_events(self):
|
def render_room_events(self):
|
||||||
def filterFn(eventType):
|
def filterFn(eventType):
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,77 @@ import yaml
|
||||||
|
|
||||||
class MatrixUnits(Units):
|
class MatrixUnits(Units):
|
||||||
|
|
||||||
|
def _load_swagger_meta(self, api, group_name):
|
||||||
|
endpoints = []
|
||||||
|
for path in api["paths"]:
|
||||||
|
for method in api["paths"][path]:
|
||||||
|
single_api = api["paths"][path][method]
|
||||||
|
endpoint = {
|
||||||
|
"title": single_api.get("summary"),
|
||||||
|
"desc": single_api.get("description"),
|
||||||
|
"method": method.upper(),
|
||||||
|
"path": path,
|
||||||
|
"requires_auth": "security" in single_api,
|
||||||
|
"rate_limited": 429 in single_api.get("responses", {}),
|
||||||
|
"req_params": []
|
||||||
|
}
|
||||||
|
self.log(".o.O.o. Endpoint: %s %s" % (method, path))
|
||||||
|
for param in single_api.get("parameters", []):
|
||||||
|
# description
|
||||||
|
desc = param.get("description")
|
||||||
|
if param.get("required"):
|
||||||
|
desc = "**Required.** " + desc
|
||||||
|
|
||||||
|
# assign value expected for this param
|
||||||
|
val_type = param.get("type") # integer/string
|
||||||
|
refType = Units.prop(param, "schema/$ref/") # Error,Event
|
||||||
|
schemaFmt = Units.prop(param, "schema/format") # bytes e.g. uploads
|
||||||
|
if not val_type and refType:
|
||||||
|
val_type = refType # TODO: Resolve to human-readable.
|
||||||
|
if not val_type and schemaFmt:
|
||||||
|
val_type = schemaFmt
|
||||||
|
if val_type:
|
||||||
|
endpoint["req_params"].append({
|
||||||
|
"name": param["name"],
|
||||||
|
"type": param["in"],
|
||||||
|
"val_type": val_type,
|
||||||
|
"desc": desc
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
# If we're here, either the param has no value or it is an
|
||||||
|
# object which we haven't $reffed (so probably just a json
|
||||||
|
# object with some keys; we'll add entries f.e one)
|
||||||
|
if "schema" not in param:
|
||||||
|
raise Exception(
|
||||||
|
"API endpoint group=%s path=%s method=%s param=%s"+
|
||||||
|
" has no valid parameter value." % (
|
||||||
|
group_name, path, method, param
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if Units.prop(param, "schema/type") != "object":
|
||||||
|
raise Exception(
|
||||||
|
("API endpoint group=%s path=%s method=%s defines a"+
|
||||||
|
" param with a schema which isn't an object. Array?")
|
||||||
|
% (group_name, path, method)
|
||||||
|
)
|
||||||
|
# loop top-level json keys
|
||||||
|
json_body = Units.prop(param, "schema/properties")
|
||||||
|
for key in json_body:
|
||||||
|
endpoint["req_params"].append({
|
||||||
|
"name": key,
|
||||||
|
"type": "JSON",
|
||||||
|
"val_type": json_body[key]["type"],
|
||||||
|
"desc": json_body[key]["description"]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
endpoints.append(endpoint)
|
||||||
|
return {
|
||||||
|
"base": api.get("basePath"),
|
||||||
|
"group": group_name,
|
||||||
|
"endpoints": endpoints,
|
||||||
|
}
|
||||||
|
|
||||||
def load_swagger_apis(self):
|
def load_swagger_apis(self):
|
||||||
path = "../api/client-server/v1"
|
path = "../api/client-server/v1"
|
||||||
apis = {}
|
apis = {}
|
||||||
|
|
@ -18,7 +89,10 @@ class MatrixUnits(Units):
|
||||||
self.log("Reading swagger API: %s" % filename)
|
self.log("Reading swagger API: %s" % filename)
|
||||||
with open(os.path.join(path, filename), "r") as f:
|
with open(os.path.join(path, filename), "r") as f:
|
||||||
# strip .yaml
|
# strip .yaml
|
||||||
apis[filename[:-5]] = yaml.load(f.read())
|
group_name = filename[:-5]
|
||||||
|
api = yaml.load(f.read())
|
||||||
|
api["__meta"] = self._load_swagger_meta(api, group_name)
|
||||||
|
apis[group_name] = api
|
||||||
return apis
|
return apis
|
||||||
|
|
||||||
def load_common_event_fields(self):
|
def load_common_event_fields(self):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue