Simplify dump_swagger

We don't need most of the templating stuff. All we have to do is merge together
the swagger files, and resolve references.
pull/977/head
Richard van der Hoff 7 years ago
parent 726a8c2f61
commit 0dfff6b190

@ -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

Loading…
Cancel
Save