Support rendering schema definitions in the spec

This commit is contained in:
Travis Ralston 2018-07-31 13:55:53 -06:00
parent bc3e45d642
commit ea307b5bdb
3 changed files with 73 additions and 0 deletions

View file

@ -43,6 +43,13 @@ HTTP_APIS = {
os.path.join(matrix_doc_dir, "api/push-gateway"): "push",
os.path.join(matrix_doc_dir, "api/server-server"): "ss",
}
SWAGGER_DEFINITIONS = {
os.path.join(matrix_doc_dir, "api/application-service/definitions"): "as",
os.path.join(matrix_doc_dir, "api/client-server/definitions"): "cs",
#os.path.join(matrix_doc_dir, "api/identity/definitions"): "is",
#os.path.join(matrix_doc_dir, "api/push-gateway/definitions"): "push",
os.path.join(matrix_doc_dir, "api/server-server/definitions"): "ss",
}
EVENT_EXAMPLES = os.path.join(matrix_doc_dir, "event-schemas/examples")
EVENT_SCHEMA = os.path.join(matrix_doc_dir, "event-schemas/schema")
CORE_EVENT_SCHEMA = os.path.join(matrix_doc_dir, "event-schemas/schema/core-event-schema")
@ -654,6 +661,37 @@ class MatrixUnits(Units):
apis[group_name] = api
return apis
def load_swagger_definitions(self):
defs = {}
for path, prefix in SWAGGER_DEFINITIONS.items():
for filename in os.listdir(path):
if not filename.endswith(".yaml"):
continue
filepath = os.path.join(path, filename)
logger.info("Reading swagger definition: %s" % filepath)
with open(filepath, "r") as f:
# strip .yaml
group_name = filename[:-5].replace("-", "_")
group_name = "%s_%s" % (prefix, group_name)
definition = yaml.load(f.read(), OrderedLoader)
definition = resolve_references(filepath, definition)
if 'type' not in definition:
continue
try:
example = get_example_for_schema(definition)
except:
pass # do nothing - we don't care
if 'title' not in definition:
definition['title'] = "NO_TITLE"
definition['tables'] = get_tables_for_schema(definition)
defs[group_name] = {
"definition": definition,
"examples": [example] if example is not None else [],
}
return defs
def load_common_event_fields(self):
"""Parse the core event schema files