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 logging
import os.path import os.path
import re import re
import shutil
import sys import sys
import yaml import yaml
scripts_dir = os.path.dirname(os.path.abspath(__file__)) scripts_dir = os.path.dirname(os.path.abspath(__file__))
templating_dir = os.path.join(os.path.dirname(scripts_dir), "templating") templating_dir = os.path.join(os.path.dirname(scripts_dir), "templating")
api_dir = os.path.join(os.path.dirname(scripts_dir), "api") api_dir = os.path.join(os.path.dirname(scripts_dir), "api")
sys.path.insert(0, templating_dir) sys.path.insert(0, templating_dir)
from matrix_templates.units import resolve_references, MatrixUnits from matrix_templates import units
if len(sys.argv) > 3: if len(sys.argv) > 3:
sys.stderr.write("usage: %s [output_file] [client_release_label]\n" % (sys.argv[0],)) 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: if match:
major_version = match.group(1) major_version = match.group(1)
logging.basicConfig() logging.basicConfig()
os.chdir(templating_dir)
apis = MatrixUnits().load_swagger_apis()
output = { output = {
"basePath": "/", "basePath": "/",
"consumes": ["application/json"], "consumes": ["application/json"],
@ -74,21 +70,30 @@ output = {
"swagger": "2.0", "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: 'security.yaml')) as f:
output['securityDefinitions'] = yaml.load(f) output['securityDefinitions'] = yaml.load(f)
for file, contents in apis.items(): for filename in os.listdir(cs_api_dir):
basePath = contents['basePath'] if not filename.endswith(".yaml"):
for path, methods in contents["paths"].items(): continue
path = (basePath + path).replace('%CLIENT_MAJOR_VERSION%', filepath = os.path.join(cs_api_dir, filename)
major_version)
for method, spec in methods.items(): print("Reading swagger API: %s" % filepath)
if "tags" in spec.keys(): with open(filepath, "r") as f:
if path not in output["paths"]: api = yaml.load(f.read())
output["paths"][path] = {} api = units.resolve_references(filepath, api)
output["paths"][path][method] = spec
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 print "Generating %s" % output_file

Loading…
Cancel
Save