diff --git a/scripts/dump-swagger.py b/scripts/dump-swagger.py index 58ec2b84..4e5ac942 100755 --- a/scripts/dump-swagger.py +++ b/scripts/dump-swagger.py @@ -25,17 +25,17 @@ import json import logging import os.path import re -import shutil import sys import yaml + scripts_dir = os.path.dirname(os.path.abspath(__file__)) templating_dir = os.path.join(os.path.dirname(scripts_dir), "templating") api_dir = os.path.join(os.path.dirname(scripts_dir), "api") sys.path.insert(0, templating_dir) -from matrix_templates.units import resolve_references, MatrixUnits +from matrix_templates import units if len(sys.argv) > 3: sys.stderr.write("usage: %s [output_file] [client_release_label]\n" % (sys.argv[0],)) @@ -53,12 +53,8 @@ match = re.match("^(r\d+)(\.\d+)*$", major_version) if match: major_version = match.group(1) - logging.basicConfig() -os.chdir(templating_dir) -apis = MatrixUnits().load_swagger_apis() - output = { "basePath": "/", "consumes": ["application/json"], @@ -74,21 +70,30 @@ output = { "swagger": "2.0", } -with open(os.path.join(api_dir, 'client-server', 'definitions', +cs_api_dir = os.path.join(api_dir, 'client-server') +with open(os.path.join(cs_api_dir, 'definitions', 'security.yaml')) as f: output['securityDefinitions'] = yaml.load(f) -for file, contents in apis.items(): - basePath = contents['basePath'] - for path, methods in contents["paths"].items(): - path = (basePath + path).replace('%CLIENT_MAJOR_VERSION%', - major_version) - for method, spec in methods.items(): - if "tags" in spec.keys(): - if path not in output["paths"]: - output["paths"][path] = {} - output["paths"][path][method] = spec - +for filename in os.listdir(cs_api_dir): + if not filename.endswith(".yaml"): + continue + filepath = os.path.join(cs_api_dir, filename) + + print("Reading swagger API: %s" % filepath) + with open(filepath, "r") as f: + api = yaml.load(f.read()) + api = units.resolve_references(filepath, api) + + basePath = api['basePath'] + for path, methods in api["paths"].items(): + path = (basePath + path).replace('%CLIENT_MAJOR_VERSION%', + major_version) + for method, spec in methods.items(): + if "tags" in spec.keys(): + if path not in output["paths"]: + output["paths"][path] = {} + output["paths"][path][method] = spec print "Generating %s" % output_file